diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index c187980a3..f6411102b 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -38,6 +38,7 @@ // boost #include +#include using mapnik::datasource; using mapnik::parameters; @@ -439,13 +440,16 @@ featureset_ptr ogr_datasource::features(query const& q) const std::vector::const_iterator it = desc_ar.begin(); std::vector::const_iterator end = desc_ar.end(); std::vector known_fields; + mapnik::context_ptr ctx = boost::make_shared(); for (; it != end; ++it) { known_fields.push_back(it->get_name()); + ctx->push(it->get_name()); } - + const std::set& attribute_names = q.property_names(); std::set::const_iterator pos = attribute_names.begin(); + while (pos != attribute_names.end()) { bool found_name = false; @@ -454,6 +458,7 @@ featureset_ptr ogr_datasource::features(query const& q) const if (known_fields[i] == *pos) { found_name = true; + break; } } @@ -477,7 +482,8 @@ featureset_ptr ogr_datasource::features(query const& q) const { filter_in_box filter(q.get_bbox()); - return featureset_ptr(new ogr_index_featureset(*dataset_, + return featureset_ptr(new ogr_index_featureset(ctx, + *dataset_, *layer, filter, index_name_, @@ -486,7 +492,8 @@ featureset_ptr ogr_datasource::features(query const& q) const } else { - return featureset_ptr(new ogr_featureset (*dataset_, + return featureset_ptr(new ogr_featureset (ctx, + *dataset_, *layer, q.get_bbox(), desc_.get_encoding() @@ -503,13 +510,17 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const if (dataset_ && layer_.is_valid()) { + mapnik::context_ptr ctx = boost::make_shared(); + // TODO : push all attribute names here + OGRLayer* layer = layer_.layer(); - + if (indexed_) { filter_at_point filter(pt); - - return featureset_ptr(new ogr_index_featureset (*dataset_, + + return featureset_ptr(new ogr_index_featureset (ctx, + *dataset_, *layer, filter, index_name_, @@ -522,7 +533,8 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const point.setX (pt.x); point.setY (pt.y); - return featureset_ptr(new ogr_featureset (*dataset_, + return featureset_ptr(new ogr_featureset (ctx, + *dataset_, *layer, point, desc_.get_encoding() diff --git a/plugins/input/ogr/ogr_featureset.cpp b/plugins/input/ogr/ogr_featureset.cpp index 5b30fe054..30248e0fc 100644 --- a/plugins/input/ogr/ogr_featureset.cpp +++ b/plugins/input/ogr/ogr_featureset.cpp @@ -46,26 +46,30 @@ using mapnik::transcoder; using mapnik::feature_factory; -ogr_featureset::ogr_featureset(OGRDataSource & dataset, +ogr_featureset::ogr_featureset(mapnik::context_ptr const & ctx, + OGRDataSource & dataset, OGRLayer & layer, OGRGeometry & extent, - const std::string& encoding) - : dataset_(dataset), + std::string const& encoding) + : ctx_(ctx), + dataset_(dataset), layer_(layer), layerdef_(layer.GetLayerDefn()), tr_(new transcoder(encoding)), fidcolumn_(layer_.GetFIDColumn ()), - count_(0), - ctx_(boost::make_shared()) + count_(0) + { layer_.SetSpatialFilter (&extent); } -ogr_featureset::ogr_featureset(OGRDataSource & dataset, +ogr_featureset::ogr_featureset(mapnik::context_ptr const& ctx, + OGRDataSource & dataset, OGRLayer & layer, - const mapnik::box2d & extent, - const std::string& encoding) - : dataset_(dataset), + mapnik::box2d const& extent, + std::string const& encoding) + : ctx_(ctx), + dataset_(dataset), layer_(layer), layerdef_(layer.GetLayerDefn()), tr_(new transcoder(encoding)), diff --git a/plugins/input/ogr/ogr_featureset.hpp b/plugins/input/ogr/ogr_featureset.hpp index 4a5c247fc..f13c699b1 100644 --- a/plugins/input/ogr/ogr_featureset.hpp +++ b/plugins/input/ogr/ogr_featureset.hpp @@ -37,29 +37,30 @@ class ogr_featureset : public mapnik::Featureset { public: - ogr_featureset(OGRDataSource & dataset, + ogr_featureset(mapnik::context_ptr const& ctx, + OGRDataSource & dataset, OGRLayer & layer, OGRGeometry & extent, - const std::string& encoding); + std::string const& encoding); - ogr_featureset(OGRDataSource & dataset, + ogr_featureset(mapnik::context_ptr const& ctx, + OGRDataSource & dataset, OGRLayer & layer, - const mapnik::box2d & extent, - const std::string& encoding); + mapnik::box2d const& extent, + std::string const& encoding); + virtual ~ogr_featureset(); mapnik::feature_ptr next(); private: - ogr_featureset(const ogr_featureset&); - const ogr_featureset& operator=(const ogr_featureset&); - + mapnik::context_ptr ctx_; OGRDataSource& dataset_; OGRLayer& layer_; OGRFeatureDefn* layerdef_; boost::scoped_ptr tr_; const char* fidcolumn_; mutable int count_; - mapnik::context_ptr ctx_; + }; #endif // OGR_FEATURESET_HPP diff --git a/plugins/input/ogr/ogr_index_featureset.cpp b/plugins/input/ogr/ogr_index_featureset.cpp index 1faf2b740..8a007fe08 100644 --- a/plugins/input/ogr/ogr_index_featureset.cpp +++ b/plugins/input/ogr/ogr_index_featureset.cpp @@ -52,18 +52,19 @@ using mapnik::transcoder; using mapnik::feature_factory; template -ogr_index_featureset::ogr_index_featureset(OGRDataSource & dataset, +ogr_index_featureset::ogr_index_featureset(mapnik::context_ptr const & ctx, + OGRDataSource & dataset, OGRLayer & layer, - const filterT& filter, - const std::string& index_file, - const std::string& encoding) - : dataset_(dataset), + filterT const& filter, + std::string const& index_file, + std::string const& encoding) + : ctx_(ctx), + dataset_(dataset), layer_(layer), layerdef_(layer.GetLayerDefn()), filter_(filter), tr_(new transcoder(encoding)), - fidcolumn_(layer_.GetFIDColumn()), - ctx_(boost::make_shared()) + fidcolumn_(layer_.GetFIDColumn()) { boost::optional memory = mapnik::mapped_memory_cache::find(index_file.c_str(),true); diff --git a/plugins/input/ogr/ogr_index_featureset.hpp b/plugins/input/ogr/ogr_index_featureset.hpp index ee011302f..7bb163ca7 100644 --- a/plugins/input/ogr/ogr_index_featureset.hpp +++ b/plugins/input/ogr/ogr_index_featureset.hpp @@ -32,18 +32,18 @@ template class ogr_index_featureset : public mapnik::Featureset { public: - ogr_index_featureset(OGRDataSource& dataset, + ogr_index_featureset(mapnik::context_ptr const& ctx, + OGRDataSource& dataset, OGRLayer& layer, - const filterT& filter, - const std::string& index_file, - const std::string& encoding); + filterT const& filter, + std::string const& index_file, + std::string const& encoding); + virtual ~ogr_index_featureset(); mapnik::feature_ptr next(); private: - ogr_index_featureset(const ogr_index_featureset&); - ogr_index_featureset& operator=(const ogr_index_featureset&); - + mapnik::context_ptr ctx_; OGRDataSource& dataset_; OGRLayer& layer_; OGRFeatureDefn* layerdef_; @@ -52,7 +52,7 @@ private: std::vector::iterator itr_; boost::scoped_ptr tr_; const char* fidcolumn_; - mapnik::context_ptr ctx_; + }; #endif // OGR_INDEX_FEATURESET_HPP