make keys member var + cache geojson grammar
This commit is contained in:
parent
22a6652160
commit
d286b75fb5
2 changed files with 44 additions and 5 deletions
|
@ -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<mapnik::json::keys_tag>(std::ref(keys))
|
||||
[ mapnik::json::geojson_grammar() ];
|
||||
auto const grammar = x3::with<mapnik::json::keys_tag>(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<std::string::const_iterator> const& ex)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/interprocess/mapped_region.hpp>
|
||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||
#include <boost/bimap.hpp>
|
||||
#include <boost/bimap/set_of.hpp>
|
||||
#include <boost/bimap/unordered_set_of.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <mapnik/mapped_memory_cache.hpp>
|
||||
#endif
|
||||
|
@ -39,6 +43,35 @@
|
|||
#include <deque>
|
||||
#include <cstdio>
|
||||
|
||||
namespace {
|
||||
|
||||
using keys_map = boost::bimap<boost::bimaps::unordered_set_of<std::string>,
|
||||
boost::bimaps::set_of<int>>;
|
||||
|
||||
enum well_known_names
|
||||
{
|
||||
id = 1,
|
||||
type,
|
||||
features,
|
||||
geometry,
|
||||
coordinates,
|
||||
properties
|
||||
};
|
||||
|
||||
inline keys_map get_keys()
|
||||
{
|
||||
keys_map keys = boost::assign::list_of<keys_map::relation>
|
||||
("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<std::size_t, std::size_t>;
|
||||
|
@ -59,6 +92,7 @@ private:
|
|||
mapnik::context_ptr ctx_;
|
||||
std::vector<value_type> positions_;
|
||||
std::vector<value_type>::iterator itr_;
|
||||
keys_map keys_ = get_keys();
|
||||
};
|
||||
|
||||
#endif // GEOJSON_INDEX_FEATURESE_HPP
|
||||
|
|
Loading…
Add table
Reference in a new issue