2006-12-06 20:26:59 +00:00
|
|
|
/*****************************************************************************
|
2012-02-02 01:53:35 +00:00
|
|
|
*
|
2006-12-06 20:26:59 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2014-11-20 14:25:50 +00:00
|
|
|
* Copyright (C) 2014 Artem Pavlenko
|
2006-12-06 20:26:59 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-10-23 14:09:47 +00:00
|
|
|
#ifndef MAPNIK_MEMORY_FEATURESET_HPP
|
|
|
|
#define MAPNIK_MEMORY_FEATURESET_HPP
|
2006-12-06 20:26:59 +00:00
|
|
|
|
2011-10-23 14:09:47 +00:00
|
|
|
// mapnik
|
2013-03-14 22:13:02 +00:00
|
|
|
#include <mapnik/box2d.hpp>
|
2015-03-13 10:05:56 +00:00
|
|
|
#include <mapnik/geometry_impl.hpp>
|
|
|
|
#include <mapnik/geometry_envelope.hpp>
|
2014-08-04 20:59:13 +00:00
|
|
|
#include <mapnik/featureset.hpp>
|
2013-01-04 04:06:34 +00:00
|
|
|
#include <mapnik/datasource.hpp>
|
2006-12-06 20:26:59 +00:00
|
|
|
#include <mapnik/memory_datasource.hpp>
|
2013-01-04 04:06:34 +00:00
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/raster.hpp>
|
2011-10-23 14:09:47 +00:00
|
|
|
|
2013-03-14 22:13:02 +00:00
|
|
|
#include <deque>
|
2006-12-06 20:26:59 +00:00
|
|
|
|
|
|
|
namespace mapnik {
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2012-02-14 18:33:39 +00:00
|
|
|
class memory_featureset : public Featureset
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-11-29 04:56:08 +00:00
|
|
|
memory_featureset(box2d<double> const& bbox, memory_datasource const& ds, bool bbox_check = true)
|
2010-06-02 11:03:30 +00:00
|
|
|
: bbox_(bbox),
|
|
|
|
pos_(ds.features_.begin()),
|
2012-10-27 01:18:35 +00:00
|
|
|
end_(ds.features_.end()),
|
2012-11-29 04:56:08 +00:00
|
|
|
type_(ds.type()),
|
|
|
|
bbox_check_(bbox_check)
|
2010-06-02 11:03:30 +00:00
|
|
|
{}
|
2011-10-12 00:29:42 +00:00
|
|
|
|
2013-01-18 12:27:29 +00:00
|
|
|
memory_featureset(box2d<double> const& bbox, std::deque<feature_ptr> const& features, bool bbox_check = true)
|
2011-10-12 00:29:42 +00:00
|
|
|
: bbox_(bbox),
|
|
|
|
pos_(features.begin()),
|
2012-10-27 01:18:35 +00:00
|
|
|
end_(features.end()),
|
2012-11-29 04:56:08 +00:00
|
|
|
type_(datasource::Vector),
|
|
|
|
bbox_check_(bbox_check)
|
2011-10-12 00:29:42 +00:00
|
|
|
{}
|
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
virtual ~memory_featureset() {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
feature_ptr next()
|
|
|
|
{
|
|
|
|
while (pos_ != end_)
|
2006-12-06 20:26:59 +00:00
|
|
|
{
|
2012-11-29 05:18:17 +00:00
|
|
|
if (!bbox_check_)
|
2012-04-08 00:20:56 +00:00
|
|
|
{
|
2012-10-27 01:18:35 +00:00
|
|
|
return *pos_++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-29 04:56:08 +00:00
|
|
|
if (type_ == datasource::Raster)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2012-11-29 04:56:08 +00:00
|
|
|
raster_ptr const& source = (*pos_)->get_raster();
|
|
|
|
if (source && bbox_.intersects(source->ext_))
|
2012-10-27 01:18:35 +00:00
|
|
|
{
|
|
|
|
return *pos_++;
|
|
|
|
}
|
2006-12-06 20:26:59 +00:00
|
|
|
}
|
2012-11-29 04:56:08 +00:00
|
|
|
else
|
|
|
|
{
|
2015-03-13 10:05:56 +00:00
|
|
|
new_geometry::geometry const& geom = (*pos_)->get_geometry();
|
|
|
|
if (bbox_.intersects(new_geometry::envelope(geom)))
|
2012-11-29 04:56:08 +00:00
|
|
|
{
|
2015-03-13 10:05:56 +00:00
|
|
|
return *pos_++;
|
2012-11-29 04:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++pos_;
|
2006-12-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
return feature_ptr();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
private:
|
|
|
|
box2d<double> bbox_;
|
2013-01-18 12:27:29 +00:00
|
|
|
std::deque<feature_ptr>::const_iterator pos_;
|
|
|
|
std::deque<feature_ptr>::const_iterator end_;
|
2012-10-27 01:18:35 +00:00
|
|
|
datasource::datasource_t type_;
|
2012-11-29 04:56:08 +00:00
|
|
|
bool bbox_check_;
|
2010-06-02 11:03:30 +00:00
|
|
|
};
|
2006-12-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
|
2011-10-23 14:09:47 +00:00
|
|
|
#endif // MAPNIK_MEMORY_FEATURESET_HPP
|