diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 422fcf0a5..90270873d 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -116,7 +116,8 @@ geojson_datasource::geojson_datasource(parameters const& params) inline_string_(), extent_(), features_(), - tree_(nullptr) + tree_(nullptr), + num_features_to_query_(*params.get("num_features_to_query",5)) { boost::optional inline_string = params.get("inline"); if (inline_string) @@ -233,6 +234,7 @@ void geojson_datasource::initialise_disk_index(std::string const& filename) mapnik::util::file file(filename_); if (!file) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'"); + mapnik::context_ptr ctx = std::make_shared(); for (auto const& pos : positions) { std::fseek(file.get(), pos.first, SEEK_SET); @@ -241,7 +243,6 @@ void geojson_datasource::initialise_disk_index(std::string const& filename) std::fread(record.data(), pos.second, 1, file.get()); auto const* start = record.data(); auto const* end = start + record.size(); - mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, -1)); using namespace boost::spirit; standard::space_type space; @@ -314,6 +315,7 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end) tree_ = std::make_unique(boxes); // calculate total extent std::size_t feature_count = 0; + mapnik::context_ptr ctx = std::make_shared(); for (auto const& item : boxes) { auto const& box = std::get<0>(item); @@ -326,7 +328,6 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end) // NOTE: this doesn't yield correct answer for geoJSON in general, just an indication Iterator itr2 = start + geometry_index.first; Iterator end2 = itr2 + geometry_index.second; - mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,-1)); // temp feature if (!boost::spirit::qi::phrase_parse(itr2, end2, (geojson_datasource_static_feature_grammar)(boost::phoenix::ref(*feature)), space) @@ -356,7 +357,7 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end) try { bool result = boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_fc_grammar) - (boost::phoenix::ref(ctx),boost::phoenix::ref(start_id), boost::phoenix::ref(callback)), + (boost::phoenix::ref(ctx), boost::phoenix::ref(start_id), boost::phoenix::ref(callback)), space); if (!result || itr != end) { @@ -458,7 +459,7 @@ boost::optional geojson_datasource::get_geometry_ mapnik::util::file file(filename_); if (!file) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'"); - + mapnik::context_ptr ctx = std::make_shared(); for (auto const& pos : positions) { std::fseek(file.get(), pos.first, SEEK_SET); @@ -467,7 +468,6 @@ boost::optional geojson_datasource::get_geometry_ std::fread(record.data(), pos.second, 1, file.get()); auto const* start = record.data(); auto const* end = start + record.size(); - mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, -1)); // temp feature using namespace boost::spirit; standard::space_type space; diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index a50bd9567..5ba36a66b 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -104,7 +104,7 @@ private: std::unique_ptr tree_; bool cache_features_ = true; bool has_disk_index_ = false; - const std::size_t num_features_to_query_ = 5; + const std::size_t num_features_to_query_; };