Skip to content

Commit

Permalink
postgis: support PostGIS 2.x - always use ST prefix (removing old tes…
Browse files Browse the repository at this point in the history
…ting code) and fixup other debug output - closes mapnik#893 and closes mapnik#956
  • Loading branch information
Dane Springmeyer committed Nov 20, 2011
1 parent 0999523 commit 5b94e63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
29 changes: 7 additions & 22 deletions plugins/input/postgis/postgis_datasource.cpp
Expand Up @@ -81,8 +81,6 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
persist_connection_(*params_.get<mapnik::boolean>("persist_connection",true)),
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)
force2d_(*params_.get<mapnik::boolean>("force_2d",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))
Expand Down Expand Up @@ -219,7 +217,7 @@ void postgis_datasource::bind() const
if (srid_ == 0)
{
srid_ = -1;
std::clog << "Postgis Plugin: SRID warning, using srid=-1" << std::endl;
std::clog << "Postgis Plugin: SRID warning, using srid=-1 for '" << table_ << "'" << std::endl;
}

// At this point the geometry_field may still not be known
Expand Down Expand Up @@ -476,7 +474,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
if (!geometryColumn_.length() > 0)
{
std::ostringstream s_error;
s_error << "geometry name lookup failed for table '";
s_error << "PostGIS: geometry name lookup failed for table '";
if (schema_.length() > 0)
{
s_error << schema_ << ".";
Expand All @@ -489,17 +487,11 @@ featureset_ptr postgis_datasource::features(const query& q) const
s_error << schema_ << ".";
}
s_error << geometry_table_ << "'.";
throw mapnik::datasource_exception("Postgis Plugin: " + s_error.str());
throw mapnik::datasource_exception(s_error.str());
}

std::ostringstream s;
s << "SELECT ";
if (st_)
s << "ST_";
if (force2d_)
s << "AsBinary(ST_Force_2D(\"" << geometryColumn_ << "\")) AS geom";
else
s << "AsBinary(\"" << geometryColumn_ << "\") AS geom";
s << "SELECT ST_AsBinary(\"" << geometryColumn_ << "\") AS geom";

if (!key_field_.empty())
mapnik::sql_utils::quote_attr(s,key_field_);
Expand Down Expand Up @@ -547,7 +539,6 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
if (conn && conn->isOK())
{
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::ostringstream s;

if (!geometryColumn_.length() > 0)
{
Expand All @@ -557,7 +548,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
{
s_error << schema_ << ".";
}
s_error << "." << geometry_table_
s_error << geometry_table_
<< "'. Please manually provide the 'geometry_field' parameter or add an entry "
<< "in the geometry_columns for '";
if (schema_.length() > 0)
Expand All @@ -568,14 +559,8 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
throw mapnik::datasource_exception(s_error.str());
}


s << "SELECT ";
if (st_)
s << "ST_";
if (force2d_)
s << "AsBinary(ST_Force_2D(\"" << geometryColumn_ << "\")) AS geom";
else
s << "AsBinary(\"" << geometryColumn_ << "\") AS geom";
std::ostringstream s;
s << "SELECT ST_AsBinary(\"" << geometryColumn_ << "\") AS geom";

if (!key_field_.empty())
mapnik::sql_utils::quote_attr(s,key_field_);
Expand Down
2 changes: 0 additions & 2 deletions plugins/input/postgis/postgis_datasource.hpp
Expand Up @@ -75,8 +75,6 @@ class postgis_datasource : public datasource
bool persist_connection_;
bool extent_from_subquery_;
// 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_;
Expand Down

0 comments on commit 5b94e63

Please sign in to comment.