Add tolerance parameter to features_at_point
Make map.query_point() always pass tolerance to datasources
This commit is contained in:
parent
f4934e62ea
commit
8f7083d14d
34 changed files with 50 additions and 50 deletions
|
@ -115,7 +115,7 @@ public:
|
|||
virtual void bind() const {}
|
||||
|
||||
virtual featureset_ptr features(query const& q) const = 0;
|
||||
virtual featureset_ptr features_at_point(coord2d const& pt) const = 0;
|
||||
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
|
||||
virtual box2d<double> envelope() const = 0;
|
||||
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
|
||||
virtual layer_descriptor get_descriptor() const = 0;
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
void push(feature_ptr feature);
|
||||
datasource::datasource_t type() const;
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||
box2d<double> envelope() const;
|
||||
boost::optional<geometry_t> get_geometry_type() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -959,7 +959,7 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
|
|||
return boost::make_shared<mapnik::memory_featureset>(q.get_bbox(),features_);
|
||||
}
|
||||
|
||||
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt) const
|
||||
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -246,7 +246,7 @@ featureset_ptr gdal_datasource::features(query const& q) const
|
|||
nodata_value_));
|
||||
}
|
||||
|
||||
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -217,7 +217,7 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
|
|||
}
|
||||
|
||||
// FIXME
|
||||
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt) const
|
||||
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
throw mapnik::datasource_exception("GeoJSON Plugin: features_at_point is not supported yet");
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
|
|
|
@ -315,7 +315,7 @@ featureset_ptr geos_datasource::features(query const& q) const
|
|||
desc_.get_encoding());
|
||||
}
|
||||
|
||||
featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr geos_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -166,7 +166,7 @@ featureset_ptr kismet_datasource::features(query const& q) const
|
|||
// return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr kismet_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -590,7 +590,7 @@ featureset_ptr occi_datasource::features(query const& q) const
|
|||
row_prefetch_);
|
||||
}
|
||||
|
||||
featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr occi_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -519,7 +519,7 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -158,7 +158,7 @@ featureset_ptr osm_datasource::features(const query& q) const
|
|||
desc_.get_encoding());
|
||||
}
|
||||
|
||||
featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||
box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -709,7 +709,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_)
|
||||
{
|
||||
|
@ -778,7 +778,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
|||
}
|
||||
}
|
||||
|
||||
box2d<double> box(pt.x, pt.y, pt.x, pt.y);
|
||||
box2d<double> box(pt.x - tol, pt.y - tol, pt.x + tol, pt.y + tol);
|
||||
std::string table_with_bbox = populate_tokens(table_, FMAX, box, 0, 0);
|
||||
|
||||
s << " FROM " << table_with_bbox;
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -189,7 +189,7 @@ mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const
|
|||
return mapnik::featureset_ptr();
|
||||
}
|
||||
|
||||
mapnik::featureset_ptr python_datasource::features_at_point(mapnik::coord2d const& pt) const
|
||||
mapnik::featureset_ptr python_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
// mandatory: function to query features by point (coord2d)
|
||||
// not used by rendering, but available to calling applications
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
|
||||
// mandatory: return the box2d of the datasource
|
||||
// called during rendering to determine if the layer should be processed
|
||||
|
|
|
@ -220,7 +220,7 @@ featureset_ptr raster_datasource::features(query const& q) const
|
|||
}
|
||||
}
|
||||
|
||||
featureset_ptr raster_datasource::features_at_point(coord2d const&) const
|
||||
featureset_ptr raster_datasource::features_at_point(coord2d const&, double tol) const
|
||||
{
|
||||
MAPNIK_LOG_WARN(raster) << "raster_datasource: feature_at_point not supported";
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(const mapnik::query& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -201,7 +201,7 @@ featureset_ptr rasterlite_datasource::features(query const& q) const
|
|||
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
|
||||
}
|
||||
|
||||
featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
mapnik::datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -286,7 +286,7 @@ featureset_ptr shape_datasource::features(const query& q) const
|
|||
}
|
||||
}
|
||||
|
||||
featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const;
|
||||
box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -632,7 +632,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
|||
return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
datasource::datasource_t type() const;
|
||||
static const char * name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
|
|
@ -82,7 +82,7 @@ mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
|
|||
return mapnik::featureset_ptr();
|
||||
}
|
||||
|
||||
mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt) const
|
||||
mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
// mandatory: function to query features by point (coord2d)
|
||||
// not used by rendering, but available to calling applications
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt, double tol = 0) const;
|
||||
|
||||
// mandatory: return the box2d of the datasource
|
||||
// called during rendering to determine if the layer should be processed
|
||||
|
|
32
src/map.cpp
32
src/map.cpp
|
@ -548,24 +548,24 @@ featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
|||
{
|
||||
throw std::runtime_error("query_point: could not project x,y into layer srs");
|
||||
}
|
||||
// TODO - pass tolerance to features_at_point as well
|
||||
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
|
||||
// calculate default tolerance
|
||||
mapnik::box2d<double> map_ex = current_extent_;
|
||||
if (maximum_extent_)
|
||||
{
|
||||
map_ex.clip(*maximum_extent_);
|
||||
}
|
||||
if (!prj_trans.backward(map_ex,PROJ_ENVELOPE_POINTS))
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "query_point: could not project map extent '" << map_ex
|
||||
<< "' into layer srs for tolerance calculation";
|
||||
throw std::runtime_error(s.str());
|
||||
}
|
||||
double tol = (map_ex.maxx() - map_ex.minx()) / width_ * 3;
|
||||
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y), tol);
|
||||
MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
|
||||
if (fs)
|
||||
{
|
||||
mapnik::box2d<double> map_ex = current_extent_;
|
||||
if (maximum_extent_)
|
||||
{
|
||||
map_ex.clip(*maximum_extent_);
|
||||
}
|
||||
if (!prj_trans.backward(map_ex,PROJ_ENVELOPE_POINTS))
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "query_point: could not project map extent '" << map_ex
|
||||
<< "' into layer srs for tolerance calculation";
|
||||
throw std::runtime_error(s.str());
|
||||
}
|
||||
double tol = (map_ex.maxx() - map_ex.minx()) / width_ * 3;
|
||||
MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
|
||||
return boost::make_shared<filter_featureset<hit_test_filter> >(fs,
|
||||
hit_test_filter(x,y,tol));
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ featureset_ptr memory_datasource::features(const query& q) const
|
|||
}
|
||||
|
||||
|
||||
featureset_ptr memory_datasource::features_at_point(coord2d const& pt) const
|
||||
featureset_ptr memory_datasource::features_at_point(coord2d const& pt, double tol) const
|
||||
{
|
||||
box2d<double> box = box2d<double>(pt.x, pt.y, pt.x, pt.y);
|
||||
|
||||
|
|
Loading…
Reference in a new issue