|
|
@ -51,11 +51,12 @@
|
|
|
|
#include <mapnik/make_unique.hpp>
|
|
|
|
#include <mapnik/make_unique.hpp>
|
|
|
|
#include <mapnik/geometry/boost_adapters.hpp>
|
|
|
|
#include <mapnik/geometry/boost_adapters.hpp>
|
|
|
|
#include <mapnik/json/feature_collection_grammar.hpp>
|
|
|
|
#include <mapnik/json/feature_collection_grammar.hpp>
|
|
|
|
#include <mapnik/json/extract_bounding_box_grammar_impl.hpp>
|
|
|
|
//#include <mapnik/json/extract_bounding_box_grammar_impl.hpp>
|
|
|
|
#include <mapnik/util/fs.hpp>
|
|
|
|
#include <mapnik/util/fs.hpp>
|
|
|
|
#include <mapnik/util/spatial_index.hpp>
|
|
|
|
#include <mapnik/util/spatial_index.hpp>
|
|
|
|
#include <mapnik/geom_util.hpp>
|
|
|
|
#include <mapnik/geom_util.hpp>
|
|
|
|
#include <mapnik/json/parse_feature.hpp>
|
|
|
|
#include <mapnik/json/parse_feature.hpp>
|
|
|
|
|
|
|
|
#include <mapnik/json/extract_bounding_boxes_x3.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
|
|
|
|
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic push
|
|
|
@ -183,14 +184,14 @@ geojson_datasource::geojson_datasource(parameters const& params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
namespace {
|
|
|
|
using box_type = box2d<double>;
|
|
|
|
using box_type = box2d<float>;
|
|
|
|
using boxes_type = std::vector<std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
|
|
|
|
using boxes_type = std::vector<std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
|
|
|
|
using base_iterator_type = char const*;
|
|
|
|
using base_iterator_type = char const*;
|
|
|
|
const mapnik::transcoder geojson_datasource_static_tr("utf8");
|
|
|
|
const mapnik::transcoder geojson_datasource_static_tr("utf8");
|
|
|
|
const mapnik::json::feature_collection_grammar<base_iterator_type,mapnik::feature_impl> geojson_datasource_static_fc_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::feature_collection_grammar<base_iterator_type,mapnik::feature_impl> geojson_datasource_static_fc_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::feature_grammar_callback<base_iterator_type,mapnik::feature_impl> geojson_datasource_static_feature_callback_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::feature_grammar_callback<base_iterator_type,mapnik::feature_impl> geojson_datasource_static_feature_callback_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::feature_grammar<base_iterator_type, mapnik::feature_impl> geojson_datasource_static_feature_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::feature_grammar<base_iterator_type, mapnik::feature_impl> geojson_datasource_static_feature_grammar(geojson_datasource_static_tr);
|
|
|
|
const mapnik::json::extract_bounding_box_grammar<base_iterator_type, boxes_type> geojson_datasource_static_bbox_grammar;
|
|
|
|
//const mapnik::json::extract_bounding_box_grammar<base_iterator_type, boxes_type> geojson_datasource_static_bbox_grammar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void geojson_datasource::initialise_descriptor(mapnik::feature_ptr const& feature)
|
|
|
|
void geojson_datasource::initialise_descriptor(mapnik::feature_ptr const& feature)
|
|
|
@ -254,7 +255,39 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end)
|
|
|
|
boxes_type boxes;
|
|
|
|
boxes_type boxes;
|
|
|
|
boost::spirit::standard::space_type space;
|
|
|
|
boost::spirit::standard::space_type space;
|
|
|
|
Iterator itr = start;
|
|
|
|
Iterator itr = start;
|
|
|
|
if (!boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_bbox_grammar)(boost::phoenix::ref(boxes)) , space))
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mapnik::json::extract_bounding_boxes(itr, end, boxes);
|
|
|
|
|
|
|
|
// bulk insert initialise r-tree
|
|
|
|
|
|
|
|
tree_ = std::make_unique<spatial_index_type>(boxes);
|
|
|
|
|
|
|
|
// calculate total extent
|
|
|
|
|
|
|
|
std::size_t feature_count = 0;
|
|
|
|
|
|
|
|
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
|
|
|
|
|
|
|
for (auto const& item : boxes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto const& box = std::get<0>(item);
|
|
|
|
|
|
|
|
auto const& geometry_index = std::get<1>(item);
|
|
|
|
|
|
|
|
if (!extent_.valid()) extent_.init(box.minx(), box.miny(), box.maxx(), box.maxy());
|
|
|
|
|
|
|
|
else extent_.expand_to_include(mapnik::box2d<double>(box.minx(), box.miny(), box.maxx(), box.maxy()));
|
|
|
|
|
|
|
|
if (feature_count++ < num_features_to_query_)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// parse first N features to extract attributes schema.
|
|
|
|
|
|
|
|
// 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::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)
|
|
|
|
|
|
|
|
|| itr2 != end2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw std::runtime_error("Failed to parse geojson feature");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialise_descriptor(feature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cache_features_ = true; // force caching single feature
|
|
|
|
cache_features_ = true; // force caching single feature
|
|
|
|
itr = start; // reset iteraror
|
|
|
|
itr = start; // reset iteraror
|
|
|
@ -289,7 +322,8 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
extent_.expand_to_include(box);
|
|
|
|
extent_.expand_to_include(box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values.emplace_back(box, std::make_pair(geometry_index,0));
|
|
|
|
values.emplace_back(mapnik::box2d<float>(box.minx(), box.miny(), box.maxx(), box.maxy()),
|
|
|
|
|
|
|
|
std::make_pair(geometry_index,0));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (geometry_index++ < num_features_to_query_)
|
|
|
|
if (geometry_index++ < num_features_to_query_)
|
|
|
@ -300,37 +334,6 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end)
|
|
|
|
// packing algorithm
|
|
|
|
// packing algorithm
|
|
|
|
tree_ = std::make_unique<spatial_index_type>(values);
|
|
|
|
tree_ = std::make_unique<spatial_index_type>(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// bulk insert initialise r-tree
|
|
|
|
|
|
|
|
tree_ = std::make_unique<spatial_index_type>(boxes);
|
|
|
|
|
|
|
|
// calculate total extent
|
|
|
|
|
|
|
|
std::size_t feature_count = 0;
|
|
|
|
|
|
|
|
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
|
|
|
|
|
|
|
for (auto const& item : boxes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto const& box = std::get<0>(item);
|
|
|
|
|
|
|
|
auto const& geometry_index = std::get<1>(item);
|
|
|
|
|
|
|
|
if (!extent_.valid()) extent_ = box;
|
|
|
|
|
|
|
|
else extent_.expand_to_include(box);
|
|
|
|
|
|
|
|
if (feature_count++ < num_features_to_query_)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// parse first N features to extract attributes schema.
|
|
|
|
|
|
|
|
// 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::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)
|
|
|
|
|
|
|
|
|| itr2 != end2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw std::runtime_error("Failed to parse geojson feature");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialise_descriptor(feature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
desc_.order_by_name();
|
|
|
|
desc_.order_by_name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -397,7 +400,8 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
extent_.expand_to_include(box);
|
|
|
|
extent_.expand_to_include(box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values.emplace_back(box, std::make_pair(geometry_index,0));
|
|
|
|
values.emplace_back(mapnik::box2d<float>(box.minx(), box.miny(), box.maxx(), box.maxy()),
|
|
|
|
|
|
|
|
std::make_pair(geometry_index,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (geometry_index < num_features_to_query_)
|
|
|
|
if (geometry_index < num_features_to_query_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|