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

This commit is contained in:
Dane Springmeyer 2011-09-11 19:46:09 +00:00
parent b09e3dc945
commit 7c72c31951
2 changed files with 17 additions and 2 deletions

View file

@ -84,7 +84,9 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
extent_from_subquery_(*params_.get<mapnik::boolean>("extent_from_subquery",false)), extent_from_subquery_(*params_.get<mapnik::boolean>("extent_from_subquery",false)),
// params below are for testing purposes only (will likely be removed at any time) // params below are for testing purposes only (will likely be removed at any time)
force2d_(*params_.get<mapnik::boolean>("force_2d",false)), force2d_(*params_.get<mapnik::boolean>("force_2d",false)),
st_(*params_.get<mapnik::boolean>("st_prefix",false)) st_(*params_.get<mapnik::boolean>("st_prefix",false)),
intersect_min_scale_(*params_.get<int>("intersect_min_scale",0)),
intersect_max_scale_(*params_.get<int>("intersect_max_scale",0))
//show_queries_(*params_.get<mapnik::boolean>("show_queries",false)) //show_queries_(*params_.get<mapnik::boolean>("show_queries",false))
{ {
if (table_.empty()) throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter"); if (table_.empty()) throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
@ -403,7 +405,18 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double c
else else
{ {
std::ostringstream s; 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(); return populated_sql + s.str();
} }
} }

View file

@ -77,6 +77,8 @@ class postgis_datasource : public datasource
// params below are for testing purposes only (will likely be removed at any time) // params below are for testing purposes only (will likely be removed at any time)
bool force2d_; bool force2d_;
bool st_; bool st_;
int intersect_min_scale_;
int intersect_max_scale_;
//bool show_queries_; //bool show_queries_;
public: public:
static std::string name(); static std::string name();