Compare commits
5 commits
master
...
mapnik-ind
Author | SHA1 | Date | |
---|---|---|---|
|
ae6b65d25b | ||
|
43d44da147 | ||
|
6e170a2e75 | ||
|
3b14da1210 | ||
|
af5e196d5f |
19 changed files with 110 additions and 102 deletions
|
@ -20,7 +20,7 @@ public:
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::default_random_engine engine(rd());
|
std::default_random_engine engine(rd());
|
||||||
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
||||||
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
|
quad_tree_type tree(mapnik::box2d<float>(0,0,2048,2048));
|
||||||
//populate
|
//populate
|
||||||
for (size_t i = 0; i < iterations_; ++i)
|
for (size_t i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ public:
|
||||||
int cy = uniform_dist(engine);
|
int cy = uniform_dist(engine);
|
||||||
int sx = 0.2 * uniform_dist(engine);
|
int sx = 0.2 * uniform_dist(engine);
|
||||||
int sy = 0.2 * uniform_dist(engine);
|
int sy = 0.2 * uniform_dist(engine);
|
||||||
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
mapnik::box2d<float> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
||||||
tree.insert(i, box);
|
tree.insert(i, box);
|
||||||
}
|
}
|
||||||
// bounding box query
|
// bounding box query
|
||||||
|
@ -39,7 +39,7 @@ public:
|
||||||
int cy = uniform_dist(engine);
|
int cy = uniform_dist(engine);
|
||||||
int sx = 0.4 * uniform_dist(engine);
|
int sx = 0.4 * uniform_dist(engine);
|
||||||
int sy = 0.4 * uniform_dist(engine);
|
int sy = 0.4 * uniform_dist(engine);
|
||||||
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
mapnik::box2d<float> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
||||||
auto itr = tree.query_in_box(box);
|
auto itr = tree.query_in_box(box);
|
||||||
auto end = tree.query_end();
|
auto end = tree.query_end();
|
||||||
for ( ;itr != end; ++itr)
|
for ( ;itr != end; ++itr)
|
||||||
|
|
|
@ -196,28 +196,32 @@ inline bool point_on_path(double x,double y,Iter start,Iter end, double tol)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
|
template <typename T = double>
|
||||||
struct filter_in_box
|
struct filter_in_box
|
||||||
{
|
{
|
||||||
box2d<double> box_;
|
using value_type = T;
|
||||||
explicit filter_in_box(box2d<double> const& box)
|
box2d<value_type> box_;
|
||||||
|
explicit filter_in_box(box2d<value_type> const& box)
|
||||||
: box_(box) {}
|
: box_(box) {}
|
||||||
|
|
||||||
bool pass(box2d<double> const& extent) const
|
bool pass(box2d<value_type> const& extent) const
|
||||||
{
|
{
|
||||||
return extent.intersects(box_);
|
return extent.intersects(box_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T = double>
|
||||||
struct filter_at_point
|
struct filter_at_point
|
||||||
{
|
{
|
||||||
box2d<double> box_;
|
using value_type = T;
|
||||||
|
box2d<value_type> box_;
|
||||||
explicit filter_at_point(coord2d const& pt, double tol=0)
|
explicit filter_at_point(coord2d const& pt, double tol=0)
|
||||||
: box_(pt,pt)
|
: box_(pt,pt)
|
||||||
{
|
{
|
||||||
box_.pad(tol);
|
box_.pad(tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pass(box2d<double> const& extent) const
|
bool pass(box2d<value_type> const& extent) const
|
||||||
{
|
{
|
||||||
return extent.intersects(box_);
|
return extent.intersects(box_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ private:
|
||||||
// quad_tree based label collision detector
|
// quad_tree based label collision detector
|
||||||
class label_collision_detector2 : util::noncopyable
|
class label_collision_detector2 : util::noncopyable
|
||||||
{
|
{
|
||||||
using tree_t = quad_tree<box2d<double> >;
|
using tree_t = quad_tree<box2d<double>, box2d<double> >;
|
||||||
tree_t tree_;
|
tree_t tree_;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public:
|
||||||
// quad_tree based label collision detector with seperate check/insert
|
// quad_tree based label collision detector with seperate check/insert
|
||||||
class label_collision_detector3 : util::noncopyable
|
class label_collision_detector3 : util::noncopyable
|
||||||
{
|
{
|
||||||
using tree_t = quad_tree< box2d<double> >;
|
using tree_t = quad_tree< box2d<double>, box2d<double>>;
|
||||||
tree_t tree_;
|
tree_t tree_;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using tree_t = quad_tree< label >;
|
using tree_t = quad_tree< label, box2d<double>>;
|
||||||
tree_t tree_;
|
tree_t tree_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
template <typename T0, typename T1 = box2d<double>>
|
template <typename T0, typename T1 = box2d<float>>
|
||||||
class quad_tree : util::noncopyable
|
class quad_tree : util::noncopyable
|
||||||
{
|
{
|
||||||
using value_type = T0;
|
using value_type = T0;
|
||||||
|
|
|
@ -47,7 +47,7 @@ bool check_spatial_index(InputStream& in)
|
||||||
return (std::strncmp(header, "mapnik-index",12) == 0);
|
return (std::strncmp(header, "mapnik-index",12) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Value, typename Filter, typename InputStream, typename BBox = box2d<double> >
|
template <typename Value, typename Filter, typename InputStream, typename BBox = box2d<float> >
|
||||||
class spatial_index
|
class spatial_index
|
||||||
{
|
{
|
||||||
using bbox_type = BBox;
|
using bbox_type = BBox;
|
||||||
|
|
|
@ -156,9 +156,10 @@ csv_datasource::csv_datasource(parameters const& params)
|
||||||
using value_type = std::pair<std::size_t, std::size_t>;
|
using value_type = std::pair<std::size_t, std::size_t>;
|
||||||
std::ifstream index(filename_ + ".index", std::ios::binary);
|
std::ifstream index(filename_ + ".index", std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'");
|
if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'");
|
||||||
extent_ = mapnik::util::spatial_index<value_type,
|
auto extent = mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::bounding_box(index);
|
std::ifstream>::bounding_box(index);
|
||||||
|
extent_ = mapnik::box2d<double>(extent); //conversion
|
||||||
}
|
}
|
||||||
//in.close(); no need to call close, rely on dtor
|
//in.close(); no need to call close, rely on dtor
|
||||||
}
|
}
|
||||||
|
@ -320,10 +321,10 @@ csv_datasource::get_geometry_type_impl(std::istream & stream) const
|
||||||
std::ifstream index(filename_ + ".index", std::ios::binary);
|
std::ifstream index(filename_ + ".index", std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'");
|
if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'");
|
||||||
|
|
||||||
mapnik::filter_in_box filter(extent_);
|
mapnik::filter_in_box<float> filter((mapnik::box2d<float>(extent_)));
|
||||||
std::vector<value_type> positions;
|
std::vector<value_type> positions;
|
||||||
mapnik::util::spatial_index<value_type,
|
mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::query_first_n(filter, index, positions, 5);
|
std::ifstream>::query_first_n(filter, index, positions, 5);
|
||||||
int multi_type = 0;
|
int multi_type = 0;
|
||||||
for (auto const& val : positions)
|
for (auto const& val : positions)
|
||||||
|
@ -427,7 +428,7 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
|
||||||
}
|
}
|
||||||
else if (has_disk_index_)
|
else if (has_disk_index_)
|
||||||
{
|
{
|
||||||
mapnik::filter_in_box filter(q.get_bbox());
|
mapnik::filter_in_box<float> filter(mapnik::box2d<float>(q.get_bbox()));
|
||||||
return std::make_shared<csv_index_featureset>(filename_, filter, locator_, separator_, quote_, headers_, ctx_);
|
return std::make_shared<csv_index_featureset>(filename_, filter, locator_, separator_, quote_, headers_, ctx_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
csv_index_featureset::csv_index_featureset(std::string const& filename,
|
csv_index_featureset::csv_index_featureset(std::string const& filename,
|
||||||
mapnik::filter_in_box const& filter,
|
mapnik::filter_in_box<float> const& filter,
|
||||||
locator_type const& locator,
|
locator_type const& locator,
|
||||||
char separator,
|
char separator,
|
||||||
char quote,
|
char quote,
|
||||||
|
@ -76,8 +76,9 @@ csv_index_featureset::csv_index_featureset(std::string const& filename,
|
||||||
std::ifstream index(indexname.c_str(), std::ios::binary);
|
std::ifstream index(indexname.c_str(), std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("CSV Plugin: can't open index file " + indexname);
|
if (!index) throw mapnik::datasource_exception("CSV Plugin: can't open index file " + indexname);
|
||||||
mapnik::util::spatial_index<value_type,
|
mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::query(filter, index, positions_);
|
std::ifstream,
|
||||||
|
mapnik::box2d<float>>::query(filter, index, positions_);
|
||||||
|
|
||||||
std::sort(positions_.begin(), positions_.end(),
|
std::sort(positions_.begin(), positions_.end(),
|
||||||
[](value_type const& lhs, value_type const& rhs) { return lhs.first < rhs.first;});
|
[](value_type const& lhs, value_type const& rhs) { return lhs.first < rhs.first;});
|
||||||
|
|
|
@ -45,7 +45,7 @@ class csv_index_featureset : public mapnik::Featureset
|
||||||
public:
|
public:
|
||||||
|
|
||||||
csv_index_featureset(std::string const& filename,
|
csv_index_featureset(std::string const& filename,
|
||||||
mapnik::filter_in_box const& filter,
|
mapnik::filter_in_box<float> const& filter,
|
||||||
locator_type const& locator,
|
locator_type const& locator,
|
||||||
char separator,
|
char separator,
|
||||||
char quote,
|
char quote,
|
||||||
|
|
|
@ -222,14 +222,16 @@ void geojson_datasource::initialise_disk_index(std::string const& filename)
|
||||||
using value_type = std::pair<std::size_t, std::size_t>;
|
using value_type = std::pair<std::size_t, std::size_t>;
|
||||||
std::ifstream index(filename_ + ".index", std::ios::binary);
|
std::ifstream index(filename_ + ".index", std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'");
|
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'");
|
||||||
extent_ = mapnik::util::spatial_index<value_type,
|
extent_ = mapnik::box2d<double>(mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::bounding_box(index);
|
std::ifstream,
|
||||||
mapnik::filter_in_box filter(extent_);
|
mapnik::box2d<float>>::bounding_box(index));
|
||||||
|
mapnik::filter_in_box<float> filter((mapnik::box2d<float>(extent_)));
|
||||||
std::vector<value_type> positions;
|
std::vector<value_type> positions;
|
||||||
mapnik::util::spatial_index<value_type,
|
mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::query_first_n(filter, index, positions, num_features_to_query_);
|
std::ifstream,
|
||||||
|
mapnik::box2d<float>>::query_first_n(filter, index, positions, num_features_to_query_);
|
||||||
|
|
||||||
mapnik::util::file file(filename_);
|
mapnik::util::file file(filename_);
|
||||||
if (!file) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'");
|
if (!file) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'");
|
||||||
|
@ -448,11 +450,12 @@ boost::optional<mapnik::datasource_geometry_t> geojson_datasource::get_geometry_
|
||||||
using value_type = std::pair<std::size_t, std::size_t>;
|
using value_type = std::pair<std::size_t, std::size_t>;
|
||||||
std::ifstream index(filename_ + ".index", std::ios::binary);
|
std::ifstream index(filename_ + ".index", std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'");
|
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'");
|
||||||
mapnik::filter_in_box filter(extent_);
|
mapnik::filter_in_box<float> filter((mapnik::box2d<float>(extent_)));
|
||||||
std::vector<value_type> positions;
|
std::vector<value_type> positions;
|
||||||
mapnik::util::spatial_index<value_type,
|
mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::query_first_n(filter, index, positions, num_features_to_query_);
|
std::ifstream,
|
||||||
|
mapnik::box2d<float>>::query_first_n(filter, index, positions, num_features_to_query_);
|
||||||
|
|
||||||
mapnik::util::file file(filename_);
|
mapnik::util::file file(filename_);
|
||||||
|
|
||||||
|
@ -582,7 +585,7 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
|
||||||
}
|
}
|
||||||
else if (has_disk_index_)
|
else if (has_disk_index_)
|
||||||
{
|
{
|
||||||
mapnik::filter_in_box filter(q.get_bbox());
|
mapnik::filter_in_box<float> filter(mapnik::box2d<float>(q.get_bbox()));
|
||||||
return std::make_shared<geojson_index_featureset>(filename_, filter);
|
return std::make_shared<geojson_index_featureset>(filename_, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
geojson_index_featureset::geojson_index_featureset(std::string const& filename, mapnik::filter_in_box const& filter)
|
geojson_index_featureset::geojson_index_featureset(std::string const& filename, mapnik::filter_in_box<float> const& filter)
|
||||||
:
|
:
|
||||||
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
|
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
|
||||||
//
|
//
|
||||||
|
@ -63,8 +63,9 @@ geojson_index_featureset::geojson_index_featureset(std::string const& filename,
|
||||||
std::ifstream index(indexname.c_str(), std::ios::binary);
|
std::ifstream index(indexname.c_str(), std::ios::binary);
|
||||||
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: can't open index file " + indexname);
|
if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: can't open index file " + indexname);
|
||||||
mapnik::util::spatial_index<value_type,
|
mapnik::util::spatial_index<value_type,
|
||||||
mapnik::filter_in_box,
|
mapnik::filter_in_box<float>,
|
||||||
std::ifstream>::query(filter, index, positions_);
|
std::ifstream,
|
||||||
|
mapnik::box2d<float>>::query(filter, index, positions_);
|
||||||
|
|
||||||
std::sort(positions_.begin(), positions_.end(),
|
std::sort(positions_.begin(), positions_.end(),
|
||||||
[](value_type const& lhs, value_type const& rhs) { return lhs.first < rhs.first;});
|
[](value_type const& lhs, value_type const& rhs) { return lhs.first < rhs.first;});
|
||||||
|
|
|
@ -43,7 +43,7 @@ class geojson_index_featureset : public mapnik::Featureset
|
||||||
{
|
{
|
||||||
using value_type = std::pair<std::size_t, std::size_t>;
|
using value_type = std::pair<std::size_t, std::size_t>;
|
||||||
public:
|
public:
|
||||||
geojson_index_featureset(std::string const& filename, mapnik::filter_in_box const& filter);
|
geojson_index_featureset(std::string const& filename, mapnik::filter_in_box<float> const& filter);
|
||||||
virtual ~geojson_index_featureset();
|
virtual ~geojson_index_featureset();
|
||||||
mapnik::feature_ptr next();
|
mapnik::feature_ptr next();
|
||||||
|
|
||||||
|
|
|
@ -537,20 +537,20 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
||||||
|
|
||||||
if (indexed_)
|
if (indexed_)
|
||||||
{
|
{
|
||||||
filter_in_box filter(q.get_bbox());
|
filter_in_box<double> filter(q.get_bbox());
|
||||||
|
|
||||||
return featureset_ptr(new ogr_index_featureset<filter_in_box>(ctx,
|
return featureset_ptr(new ogr_index_featureset<filter_in_box<double> >(ctx,
|
||||||
*layer,
|
*layer,
|
||||||
filter,
|
filter,
|
||||||
index_name_,
|
index_name_,
|
||||||
desc_.get_encoding()));
|
desc_.get_encoding()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return featureset_ptr(new ogr_featureset(ctx,
|
return featureset_ptr(new ogr_featureset(ctx,
|
||||||
*layer,
|
*layer,
|
||||||
q.get_bbox(),
|
q.get_bbox(),
|
||||||
desc_.get_encoding()));
|
desc_.get_encoding()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,13 +578,13 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol)
|
||||||
|
|
||||||
if (indexed_)
|
if (indexed_)
|
||||||
{
|
{
|
||||||
filter_at_point filter(pt, tol);
|
filter_at_point<double> filter(pt, tol);
|
||||||
|
|
||||||
return featureset_ptr(new ogr_index_featureset<filter_at_point> (ctx,
|
return featureset_ptr(new ogr_index_featureset<filter_at_point<double>> (ctx,
|
||||||
*layer,
|
*layer,
|
||||||
filter,
|
filter,
|
||||||
index_name_,
|
index_name_,
|
||||||
desc_.get_encoding()));
|
desc_.get_encoding()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -207,5 +207,5 @@ feature_ptr ogr_index_featureset<filterT>::next()
|
||||||
return feature_ptr();
|
return feature_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
template class ogr_index_featureset<mapnik::filter_in_box>;
|
template class ogr_index_featureset<mapnik::filter_in_box<double>>;
|
||||||
template class ogr_index_featureset<mapnik::filter_at_point>;
|
template class ogr_index_featureset<mapnik::filter_at_point<double>>;
|
||||||
|
|
|
@ -236,25 +236,25 @@ featureset_ptr shape_datasource::features(query const& q) const
|
||||||
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features");
|
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
filter_in_box filter(q.get_bbox());
|
filter_in_box<float> filter(mapnik::box2d<float>(q.get_bbox()));
|
||||||
if (indexed_)
|
if (indexed_)
|
||||||
{
|
{
|
||||||
std::unique_ptr<shape_io> shape_ptr = std::make_unique<shape_io>(shape_name_);
|
std::unique_ptr<shape_io> shape_ptr = std::make_unique<shape_io>(shape_name_);
|
||||||
return featureset_ptr
|
return featureset_ptr
|
||||||
(new shape_index_featureset<filter_in_box>(filter,
|
(new shape_index_featureset<filter_in_box<float> >(filter,
|
||||||
std::move(shape_ptr),
|
std::move(shape_ptr),
|
||||||
q.property_names(),
|
q.property_names(),
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
shape_name_,
|
shape_name_,
|
||||||
row_limit_));
|
row_limit_));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return std::make_shared<shape_featureset<filter_in_box> >(filter,
|
return std::make_shared<shape_featureset<filter_in_box<float> > >(filter,
|
||||||
shape_name_,
|
shape_name_,
|
||||||
q.property_names(),
|
q.property_names(),
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
row_limit_);
|
row_limit_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol
|
||||||
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point");
|
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
filter_at_point filter(pt,tol);
|
filter_at_point<float> filter(pt, tol);
|
||||||
// collect all attribute names
|
// collect all attribute names
|
||||||
auto const& desc = desc_.get_descriptors();
|
auto const& desc = desc_.get_descriptors();
|
||||||
std::set<std::string> names;
|
std::set<std::string> names;
|
||||||
|
@ -278,20 +278,20 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol
|
||||||
{
|
{
|
||||||
std::unique_ptr<shape_io> shape_ptr = std::make_unique<shape_io>(shape_name_);
|
std::unique_ptr<shape_io> shape_ptr = std::make_unique<shape_io>(shape_name_);
|
||||||
return featureset_ptr
|
return featureset_ptr
|
||||||
(new shape_index_featureset<filter_at_point>(filter,
|
(new shape_index_featureset<filter_at_point<float> >(filter,
|
||||||
std::move(shape_ptr),
|
std::move(shape_ptr),
|
||||||
names,
|
names,
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
shape_name_,
|
shape_name_,
|
||||||
row_limit_));
|
row_limit_));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return std::make_shared<shape_featureset<filter_at_point> >(filter,
|
return std::make_shared<shape_featureset<filter_at_point<float> > >(filter,
|
||||||
shape_name_,
|
shape_name_,
|
||||||
names,
|
names,
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
row_limit_);
|
row_limit_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
{
|
{
|
||||||
double x = record.read_double();
|
double x = record.read_double();
|
||||||
double y = record.read_double();
|
double y = record.read_double();
|
||||||
if (!filter_.pass(mapnik::box2d<double>(x,y,x,y)))
|
if (!filter_.pass(mapnik::box2d<float>(x,y,x,y)))
|
||||||
continue;
|
continue;
|
||||||
feature->set_geometry(mapnik::geometry::point<double>(x,y));
|
feature->set_geometry(mapnik::geometry::point<double>(x,y));
|
||||||
break;
|
break;
|
||||||
|
@ -105,7 +105,7 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
case shape_io::shape_multipointz:
|
case shape_io::shape_multipointz:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
int num_points = record.read_ndr_integer();
|
int num_points = record.read_ndr_integer();
|
||||||
mapnik::geometry::multi_point<double> multi_point;
|
mapnik::geometry::multi_point<double> multi_point;
|
||||||
for (int i = 0; i < num_points; ++i)
|
for (int i = 0; i < num_points; ++i)
|
||||||
|
@ -123,7 +123,7 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
case shape_io::shape_polylinez:
|
case shape_io::shape_polylinez:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
feature->set_geometry(shape_io::read_polyline(record));
|
feature->set_geometry(shape_io::read_polyline(record));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
case shape_io::shape_polygonz:
|
case shape_io::shape_polygonz:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
feature->set_geometry(shape_io::read_polygon(record));
|
feature->set_geometry(shape_io::read_polygon(record));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -167,5 +167,5 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
template <typename filterT>
|
template <typename filterT>
|
||||||
shape_featureset<filterT>::~shape_featureset() {}
|
shape_featureset<filterT>::~shape_featureset() {}
|
||||||
|
|
||||||
template class shape_featureset<mapnik::filter_in_box>;
|
template class shape_featureset<mapnik::filter_in_box<float>>;
|
||||||
template class shape_featureset<mapnik::filter_at_point>;
|
template class shape_featureset<mapnik::filter_at_point<float>>;
|
||||||
|
|
|
@ -117,7 +117,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
||||||
case shape_io::shape_multipointz:
|
case shape_io::shape_multipointz:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
int num_points = record.read_ndr_integer();
|
int num_points = record.read_ndr_integer();
|
||||||
mapnik::geometry::multi_point<double> multi_point;
|
mapnik::geometry::multi_point<double> multi_point;
|
||||||
for (int i = 0; i < num_points; ++i)
|
for (int i = 0; i < num_points; ++i)
|
||||||
|
@ -134,7 +134,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
||||||
case shape_io::shape_polylinez:
|
case shape_io::shape_polylinez:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
if (parts.size() < 2) feature->set_geometry(shape_io::read_polyline(record));
|
if (parts.size() < 2) feature->set_geometry(shape_io::read_polyline(record));
|
||||||
else feature->set_geometry(shape_io::read_polyline_parts(record, parts));
|
else feature->set_geometry(shape_io::read_polyline_parts(record, parts));
|
||||||
break;
|
break;
|
||||||
|
@ -144,7 +144,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
||||||
case shape_io::shape_polygonz:
|
case shape_io::shape_polygonz:
|
||||||
{
|
{
|
||||||
shape_io::read_bbox(record, feature_bbox_);
|
shape_io::read_bbox(record, feature_bbox_);
|
||||||
if (!filter_.pass(feature_bbox_)) continue;
|
if (!filter_.pass(mapnik::box2d<float>(feature_bbox_))) continue;
|
||||||
if (parts.size() < 2) feature->set_geometry(shape_io::read_polygon(record));
|
if (parts.size() < 2) feature->set_geometry(shape_io::read_polygon(record));
|
||||||
else feature->set_geometry(shape_io::read_polygon_parts(record, parts));
|
else feature->set_geometry(shape_io::read_polygon_parts(record, parts));
|
||||||
break;
|
break;
|
||||||
|
@ -181,5 +181,5 @@ feature_ptr shape_index_featureset<filterT>::next()
|
||||||
template <typename filterT>
|
template <typename filterT>
|
||||||
shape_index_featureset<filterT>::~shape_index_featureset() {}
|
shape_index_featureset<filterT>::~shape_index_featureset() {}
|
||||||
|
|
||||||
template class shape_index_featureset<mapnik::filter_in_box>;
|
template class shape_index_featureset<mapnik::filter_in_box<float>>;
|
||||||
template class shape_index_featureset<mapnik::filter_at_point>;
|
template class shape_index_featureset<mapnik::filter_at_point<float>>;
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_CASE("spatial_index")
|
||||||
using value_type = std::int32_t;
|
using value_type = std::int32_t;
|
||||||
using mapnik::filter_in_box;
|
using mapnik::filter_in_box;
|
||||||
mapnik::box2d<double> extent(0,0,100,100);
|
mapnik::box2d<double> extent(0,0,100,100);
|
||||||
mapnik::quad_tree<value_type> tree(extent);
|
mapnik::quad_tree<value_type,mapnik::box2d<double>> tree(extent);
|
||||||
REQUIRE(tree.extent() == extent);
|
REQUIRE(tree.extent() == extent);
|
||||||
// insert some items
|
// insert some items
|
||||||
tree.insert(1, mapnik::box2d<double>(10,10,20,20));
|
tree.insert(1, mapnik::box2d<double>(10,10,20,20));
|
||||||
|
@ -55,12 +55,12 @@ TEST_CASE("spatial_index")
|
||||||
|
|
||||||
// read bounding box
|
// read bounding box
|
||||||
std::istringstream in(out.str(), std::ios::binary);
|
std::istringstream in(out.str(), std::ios::binary);
|
||||||
auto box = mapnik::util::spatial_index<value_type, filter_in_box, std::istringstream>::bounding_box(in);
|
auto box = mapnik::util::spatial_index<value_type, filter_in_box<double>, std::istringstream, mapnik::box2d<double>>::bounding_box(in);
|
||||||
REQUIRE(box == tree.extent());
|
REQUIRE(box == tree.extent());
|
||||||
// bounding box query
|
// bounding box query
|
||||||
std::vector<value_type> results;
|
std::vector<value_type> results;
|
||||||
filter_in_box filter(box);
|
filter_in_box<double> filter(box);
|
||||||
mapnik::util::spatial_index<value_type, filter_in_box, std::istringstream>::query(filter, in, results);
|
mapnik::util::spatial_index<value_type, filter_in_box<double>, std::istringstream, mapnik::box2d<double>>::query(filter, in, results);
|
||||||
|
|
||||||
REQUIRE(results[0] == 1);
|
REQUIRE(results[0] == 1);
|
||||||
REQUIRE(results[1] == 4);
|
REQUIRE(results[1] == 4);
|
||||||
|
@ -71,13 +71,13 @@ TEST_CASE("spatial_index")
|
||||||
// query first N elements interface
|
// query first N elements interface
|
||||||
results.clear();
|
results.clear();
|
||||||
in.seekg(0, std::ios::beg);
|
in.seekg(0, std::ios::beg);
|
||||||
mapnik::util::spatial_index<value_type, filter_in_box, std::istringstream>::query_first_n(filter, in, results, 2);
|
mapnik::util::spatial_index<value_type, filter_in_box<double>, std::istringstream, mapnik::box2d<double>>::query_first_n(filter, in, results, 2);
|
||||||
REQUIRE(results.size() == 2);
|
REQUIRE(results.size() == 2);
|
||||||
REQUIRE(results[0] == 1);
|
REQUIRE(results[0] == 1);
|
||||||
REQUIRE(results[1] == 4);
|
REQUIRE(results[1] == 4);
|
||||||
results.clear();
|
results.clear();
|
||||||
in.seekg(0, std::ios::beg);
|
in.seekg(0, std::ios::beg);
|
||||||
mapnik::util::spatial_index<value_type, filter_in_box, std::istringstream>::query_first_n(filter, in, results, 5);
|
mapnik::util::spatial_index<value_type, filter_in_box<double>, std::istringstream, mapnik::box2d<double>>::query_first_n(filter, in, results, 5);
|
||||||
REQUIRE(results[0] == 1);
|
REQUIRE(results[0] == 1);
|
||||||
REQUIRE(results[1] == 4);
|
REQUIRE(results[1] == 4);
|
||||||
REQUIRE(results[2] == 3);
|
REQUIRE(results[2] == 3);
|
||||||
|
|
|
@ -198,12 +198,10 @@ int main (int argc, char** argv)
|
||||||
if (extent.valid())
|
if (extent.valid())
|
||||||
{
|
{
|
||||||
std::clog << extent << std::endl;
|
std::clog << extent << std::endl;
|
||||||
mapnik::box2d<double> extent_d(extent.minx(), extent.miny(), extent.maxx(), extent.maxy());
|
mapnik::quad_tree<std::pair<std::size_t, std::size_t>> tree(extent, depth, ratio);
|
||||||
mapnik::quad_tree<std::pair<std::size_t, std::size_t>> tree(extent_d, depth, ratio);
|
|
||||||
for (auto const& item : boxes)
|
for (auto const& item : boxes)
|
||||||
{
|
{
|
||||||
auto ext_f = std::get<0>(item);
|
tree.insert(std::get<1>(item), std::get<0>(item));
|
||||||
tree.insert(std::get<1>(item), mapnik::box2d<double>(ext_f.minx(), ext_f.miny(), ext_f.maxx(), ext_f.maxy()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fstream file((filename + ".index").c_str(),
|
std::fstream file((filename + ".index").c_str(),
|
||||||
|
|
|
@ -171,7 +171,7 @@ int main (int argc,char** argv)
|
||||||
}
|
}
|
||||||
int pos = 50;
|
int pos = 50;
|
||||||
shx.seek(pos * 2);
|
shx.seek(pos * 2);
|
||||||
mapnik::quad_tree<mapnik::detail::node> tree(extent, depth, ratio);
|
mapnik::quad_tree<mapnik::detail::node> tree(mapnik::box2d<float>(extent), depth, ratio);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (shape_type != shape_io::shape_null)
|
if (shape_type != shape_io::shape_null)
|
||||||
|
@ -234,7 +234,7 @@ int main (int argc,char** argv)
|
||||||
{
|
{
|
||||||
std::clog << "record number " << record_number << " box=" << item_ext << std::endl;
|
std::clog << "record number " << record_number << " box=" << item_ext << std::endl;
|
||||||
}
|
}
|
||||||
tree.insert(mapnik::detail::node(offset * 2, start, end),item_ext);
|
tree.insert(mapnik::detail::node(offset * 2, start, end), mapnik::box2d<float>(item_ext));
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ int main (int argc,char** argv)
|
||||||
{
|
{
|
||||||
std::clog << "record number " << record_number << " box=" << item_ext << std::endl;
|
std::clog << "record number " << record_number << " box=" << item_ext << std::endl;
|
||||||
}
|
}
|
||||||
tree.insert(mapnik::detail::node(offset * 2,-1,0),item_ext);
|
tree.insert(mapnik::detail::node(offset * 2,-1,0), mapnik::box2d<float>(item_ext));
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue