From 7c72c3195169000b571d1a1fd3e3340f635e0f41 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 11 Sep 2011 19:46:09 +0000 Subject: [PATCH] postgis: expose min/max scale controls on datasource to direct when mapnik should pull features by bbox intersection, or the more accurate (and likely to fetch more correct features) approach of Intersection with geometries - addresses part of original problem in #876 --- plugins/input/postgis/postgis_datasource.cpp | 17 +++++++++++++++-- plugins/input/postgis/postgis_datasource.hpp | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 192dfa13b..b02dc9c17 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -84,7 +84,9 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind) extent_from_subquery_(*params_.get("extent_from_subquery",false)), // params below are for testing purposes only (will likely be removed at any time) force2d_(*params_.get("force_2d",false)), - st_(*params_.get("st_prefix",false)) + st_(*params_.get("st_prefix",false)), + intersect_min_scale_(*params_.get("intersect_min_scale",0)), + intersect_max_scale_(*params_.get("intersect_max_scale",0)) //show_queries_(*params_.get("show_queries",false)) { if (table_.empty()) throw mapnik::datasource_exception("Postgis Plugin: missing parameter"); @@ -403,7 +405,18 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double c else { std::ostringstream s; - s << " WHERE \"" << geometryColumn_ << "\" && " << box; + if (intersect_min_scale_ > 0 && (scale_denom <= intersect_min_scale_ )) + { + s << " WHERE ST_Intersects(\"" << geometryColumn_ << "\"," << box << ")"; + } + else if (intersect_max_scale_ > 0 && (scale_denom >= intersect_max_scale_ )) + { + // do no bbox restriction + } + else + { + s << " WHERE \"" << geometryColumn_ << "\" && " << box; + } return populated_sql + s.str(); } } diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index 0203afe56..eade5781f 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -77,6 +77,8 @@ class postgis_datasource : public datasource // params below are for testing purposes only (will likely be removed at any time) bool force2d_; bool st_; + int intersect_min_scale_; + int intersect_max_scale_; //bool show_queries_; public: static std::string name();