mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
larger_geojson - store {offset, size} in spatial index and remove multi_pass requirement
TODO: try std::fread instead of ifstream, use std::vector<uint8_t> instead of std::string
This commit is contained in:
parent
15a83ff54d
commit
1f693b8fa2
@ -124,7 +124,7 @@ large_geojson_datasource::large_geojson_datasource(parameters const& params)
|
||||
}
|
||||
if (!inline_string_.empty())
|
||||
{
|
||||
parse_geojson(inline_string_);
|
||||
//parse_geojson(inline_string_);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,6 +175,7 @@ const mapnik::transcoder tr("utf8");
|
||||
const mapnik::json::feature_collection_grammar<base_iterator_type,mapnik::feature_impl> fc_grammar(tr);
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T>
|
||||
void large_geojson_datasource::parse_geojson(T const& buffer)
|
||||
{
|
||||
@ -233,6 +234,7 @@ void large_geojson_datasource::parse_geojson(T const& buffer)
|
||||
#endif
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
template <typename Iterator>
|
||||
void large_geojson_datasource::initialise_index(Iterator start, Iterator end)
|
||||
@ -263,7 +265,7 @@ void large_geojson_datasource::initialise_index(Iterator start, Iterator end)
|
||||
}
|
||||
}
|
||||
|
||||
large_geojson_datasource::~large_geojson_datasource() { }
|
||||
large_geojson_datasource::~large_geojson_datasource() {}
|
||||
|
||||
const char * large_geojson_datasource::name()
|
||||
{
|
||||
@ -321,7 +323,7 @@ mapnik::featureset_ptr large_geojson_datasource::features(mapnik::query const& q
|
||||
tree_->query(boost::geometry::index::intersects(box),std::back_inserter(index_array));
|
||||
std::cerr << "Query size=" << index_array.size() << std::endl;
|
||||
std::cerr << "Sort index_array by offsets" << std::endl;
|
||||
std::sort(index_array.begin(),index_array.end(), [](item_type const& item0, item_type const& item1) {return item0.second < item1.second;});
|
||||
std::sort(index_array.begin(),index_array.end(), [](item_type const& item0, item_type const& item1) {return item0.second.first < item1.second.first;});
|
||||
std::cerr << "Done" << std::endl;
|
||||
return std::make_shared<large_geojson_featureset>(filename_, std::move(index_array));
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public:
|
||||
//using point_type = boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>;
|
||||
using box_type = mapnik::box2d<double>;//boost::geometry::model::box<point_type>;
|
||||
|
||||
using item_type = std::pair<box_type,std::size_t>;
|
||||
using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;
|
||||
using spatial_index_type = boost::geometry::index::rtree<item_type,geojson_linear<16,4> >;
|
||||
|
||||
// constructor
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
|
||||
large_geojson_featureset::large_geojson_featureset(std::string const& filename,
|
||||
array_type && index_array)
|
||||
: file_(filename, std::ios::binary),
|
||||
: file_(filename.c_str(), std::ios::binary),
|
||||
index_array_(std::move(index_array)),
|
||||
index_itr_(index_array_.begin()),
|
||||
index_end_(index_array_.end()),
|
||||
@ -60,29 +60,19 @@ mapnik::feature_ptr large_geojson_featureset::next()
|
||||
{
|
||||
#if BOOST_VERSION >= 105600
|
||||
large_geojson_datasource::item_type const& item = *index_itr_++;
|
||||
std::size_t file_offset = item.second;
|
||||
//std::cerr << file_offset << " -- " << item.first << std::endl;
|
||||
std::size_t file_offset = item.second.first;
|
||||
std::size_t size = item.second.second;
|
||||
//std::cerr << file_offset << " (" << size << ") " << item.first << std::endl;
|
||||
#else
|
||||
std::size_t index = *index_itr_++;
|
||||
#endif
|
||||
|
||||
using base_iterator_type = std::istreambuf_iterator<char>;
|
||||
|
||||
using chr_iterator_type =
|
||||
boost::spirit::multi_pass
|
||||
< base_iterator_type
|
||||
, boost::spirit::iterator_policies::default_policy
|
||||
< boost::spirit::iterator_policies::first_owner//ref_counted
|
||||
, boost::spirit::iterator_policies::no_check
|
||||
//, boost::spirit::iterator_policies::functor_input
|
||||
//, boost::spirit::iterator_policies::split_std_deque
|
||||
>
|
||||
> ;
|
||||
|
||||
file_.seekg(file_offset);
|
||||
base_iterator_type in(file_);
|
||||
chr_iterator_type start(in);
|
||||
chr_iterator_type end;
|
||||
std::string json;
|
||||
json.resize(size,' ');
|
||||
file_.read(&*json.begin(), size);
|
||||
using chr_iterator_type = std::string::const_iterator;
|
||||
chr_iterator_type start = json.begin();
|
||||
chr_iterator_type end = json.end();
|
||||
|
||||
static const mapnik::transcoder tr("utf8");
|
||||
static const mapnik::json::feature_grammar<chr_iterator_type,mapnik::feature_impl> grammar(tr);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user