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();