diff --git a/AUTHORS b/AUTHORS index 66c821dd6..df5bbba25 100644 --- a/AUTHORS +++ b/AUTHORS @@ -31,6 +31,7 @@ Patches - Beau Gunderson - John Hague - Aubrey Holland + - Mak Kolybabi - Dennis Luxen - Tom MacWright - Michal Migurski diff --git a/CHANGELOG b/CHANGELOG index 8f432bbbf..227156c2f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,8 @@ For a complete change history, see the SVN log. Mapnik 0.7.1 Release -------------------- +- PostGIS: Added better support for alterative schemas (#500) + - AGG Renderer - Enforced default gamma function on all symbolizers to ensure proper antialiasing even when gamma is modified on the PolygonSymbolizer. (#512) diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index f929fc9d4..017ef2768 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -74,6 +74,7 @@ using mapnik::attribute_descriptor; postgis_datasource::postgis_datasource(parameters const& params) : datasource(params), table_(*params_.get("table","")), + schema_(""), geometry_table_(*params_.get("geometry_table","")), geometry_field_(*params_.get("geometry_field","")), cursor_fetch_size_(*params_.get("cursor_size",0)), @@ -154,11 +155,10 @@ postgis_datasource::postgis_datasource(parameters const& params) { geometry_table_ = table_from_sql(table_); } - std::string schema_name=""; std::string::size_type idx = geometry_table_.find_last_of('.'); if (idx!=std::string::npos) { - schema_name = geometry_table_.substr(0,idx); + schema_ = geometry_table_.substr(0,idx); geometry_table_ = geometry_table_.substr(idx+1); } else @@ -179,8 +179,8 @@ postgis_datasource::postgis_datasource(parameters const& params) s << "SELECT f_geometry_column, srid FROM "; s << GEOMETRY_COLUMNS <<" WHERE f_table_name='" << unquote(geometry_table_) <<"'"; - if (schema_name.length() > 0) - s << " AND f_table_schema='" << unquote(schema_name) << "'"; + if (schema_.length() > 0) + s << " AND f_table_schema='" << unquote(schema_) << "'"; if (geometry_field_.length() > 0) s << " AND f_geometry_column='" << unquote(geometry_field_) << "'"; @@ -473,9 +473,9 @@ featureset_ptr postgis_datasource::features(const query& q) const if (!geometryColumn_.length() > 0) { std::ostringstream s_error; - s_error << "PostGIS: geometry name lookup failed for table '" << geometry_table_ + s_error << "PostGIS: geometry name lookup failed for table '" << schema_ << "." << geometry_table_ << "'. Please manually provide the 'geometry_field' parameter or add an entry " - << "in the geometry_columns for '" << geometry_table_ << "'."; + << "in the geometry_columns for '" << schema_ << "." << geometry_table_ << "'."; throw mapnik::datasource_exception(s_error.str()); } @@ -520,9 +520,9 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const if (!geometryColumn_.length() > 0) { std::ostringstream s_error; - s_error << "PostGIS: geometry name lookup failed for table '" << geometry_table_ + s_error << "PostGIS: geometry name lookup failed for table '" << schema_ << "." << geometry_table_ << "'. Please manually provide the 'geometry_field' parameter or add an entry " - << "in the geometry_columns for '" << geometry_table_ << "'."; + << "in the geometry_columns for '" << schema_ << "." << geometry_table_ << "'."; throw mapnik::datasource_exception(s_error.str()); } @@ -573,32 +573,47 @@ Envelope postgis_datasource::envelope() const { std::ostringstream s_error; s_error << "PostGIS: unable to query the layer extent of table '" - << geometry_table_ << "' because we cannot determine the geometry field name." + << schema_ << "." << geometry_table_ << "' because we cannot determine the geometry field name." << "\nPlease provide either 1) an 'extent' parameter to skip this query, " << "2) a 'geometry_field' and/or 'geometry_table' parameter, or 3) add a " << "record to the 'geometry_columns' for your table."; throw mapnik::datasource_exception(s_error.str()); } - // TODO - do we need to respect schema here? + if (estimate_extent && *estimate_extent == "true") { - s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)" - << " from (select estimated_extent('" - << geometry_table_ << "','" - << geometryColumn_ << "') as ext) as tmp"; + s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)" + << " from (select estimated_extent("; + + if (schema_.length() > 0) + { + s << schema_ << "."; + } + + s << geometry_table_ << "," + << geometryColumn_ << ") as ext) as tmp"; } - else + else { s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)" << " from (select extent(" < 0) + { + s << schema_ << "."; + } + // but if the subquery does not limit records then querying the // actual table will be faster as indexes can be used s << geometry_table_ << ") as tmp"; + } } /*if (show_queries_) diff --git a/plugins/input/postgis/postgis.hpp b/plugins/input/postgis/postgis.hpp index c7300745a..1d3f793ea 100644 --- a/plugins/input/postgis/postgis.hpp +++ b/plugins/input/postgis/postgis.hpp @@ -57,6 +57,7 @@ class postgis_datasource : public datasource const std::string username_; const std::string password_; const std::string table_; + mutable std::string schema_; mutable std::string geometry_table_; const std::string geometry_field_; const int cursor_fetch_size_;