diff --git a/plugins/input/geojson/geojson_index_featureset.cpp b/plugins/input/geojson/geojson_index_featureset.cpp index 03adfb861..a9a6bc732 100644 --- a/plugins/input/geojson/geojson_index_featureset.cpp +++ b/plugins/input/geojson/geojson_index_featureset.cpp @@ -77,6 +77,13 @@ geojson_index_featureset::geojson_index_featureset(std::string const& filename, geojson_index_featureset::~geojson_index_featureset() {} +namespace { +using namespace boost::spirit; +//static const mapnik::json::keys_map keys = mapnik::json::get_keys(); +static const mapnik::json::grammar::geojson_grammar_type geojson_g = mapnik::json::geojson_grammar(); + +} + mapnik::feature_ptr geojson_index_featureset::next() { while( itr_ != positions_.end()) @@ -98,16 +105,14 @@ mapnik::feature_ptr geojson_index_featureset::next() using namespace boost::spirit; using space_type = mapnik::json::grammar::space_type; using mapnik::json::grammar::iterator_type; - mapnik::json::geojson_value value; - auto keys = mapnik::json::get_keys(); - auto grammar = x3::with(std::ref(keys)) - [ mapnik::json::geojson_grammar() ]; + auto const grammar = x3::with(std::ref(keys_)) + [ geojson_g ]; try { bool result = x3::phrase_parse(start, end, grammar, space_type(), value); if (!result) return mapnik::feature_ptr(); - mapnik::json::create_feature(*feature, value, keys, tr); + mapnik::json::create_feature(*feature, value, keys_, tr); } catch (x3::expectation_failure const& ex) { diff --git a/plugins/input/geojson/geojson_index_featureset.hpp b/plugins/input/geojson/geojson_index_featureset.hpp index 41e8e84ba..4371636b0 100644 --- a/plugins/input/geojson/geojson_index_featureset.hpp +++ b/plugins/input/geojson/geojson_index_featureset.hpp @@ -32,6 +32,10 @@ #include #include #include +#include +#include +#include +#include #pragma GCC diagnostic pop #include #endif @@ -39,6 +43,35 @@ #include #include +namespace { + +using keys_map = boost::bimap, + boost::bimaps::set_of>; + +enum well_known_names +{ + id = 1, + type, + features, + geometry, + coordinates, + properties +}; + +inline keys_map get_keys() +{ + keys_map keys = boost::assign::list_of + ("type", well_known_names::type) + ("features", well_known_names::features) + ("geometry", well_known_names::geometry) + ("coordinates", well_known_names::coordinates) + ("properties", well_known_names::properties) + ("id", well_known_names::id) + ; + return keys; +} +} + class geojson_index_featureset : public mapnik::Featureset { using value_type = std::pair; @@ -59,6 +92,7 @@ private: mapnik::context_ptr ctx_; std::vector positions_; std::vector::iterator itr_; + keys_map keys_ = get_keys(); }; #endif // GEOJSON_INDEX_FEATURESE_HPP