Hi, I'm one of the technical admins of Wikivoyage, a free open content
wiki based travel guide. We have plans to make extensive use of Mapnik
together - but not only - with OSM data. The table layout of the PostGIS
backend will be completely different from what OSM's osm2pgsql generates.
Oh, yes - and I don't like mailing lists. I only will keep subscribed
for some days in order to follow the discussion. You always can drop me
a message on my Wikivoyage user talk page
http://www.wikivoyage.org/de/Benutzer:Hansm
As I have seen from the source code, Mapnik makes a *very* simplistic
guess about the PostgreSQL table and schema that hold the actual
geometry column. If queries given as parameter "table" (actually a bad
name) get a little bit more complex, Mapnik fails terribly. However,
it's not worth to improve this guess since queries may be really
complex. Instead, I wanted to propose two additional optional paramters
for postgis_datasource: "table_name" and "schema_name". Both are used
for retrieving the SRID and the geometry field (if not given as
parameter). The SRID itself is needed for estimating the extend of the
table's geometries.
Here is an example for parameter "table", that is too complex for Mapnik
(it guesses osm_relation_mb to be the geometry table):
<Parameter name="table">(SELECT way FROM osm_way WHERE osm_id = ANY
(SELECT rm_way FROM osm_relation_mb WHERE rm_relation=62149)) as
border</Parameter>
I have added two patches, one for plugins/input/postgis/postgis.cpp and
one for the corresponding header file. Both refere to the up to date svn
version.
Cheers,
Hans
--- mapnik-0.6.1/plugins/input/postgis/postgis.cpp 2009-07-14 11:08:55.000000000 +0200
+++ mapnik-0.6.1-patched/plugins/input/postgis/postgis.cpp 2009-07-17 11:39:44.000000000 +0200
@@ -82,6 +82,9 @@
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
+ schema_name_ = *params.get<std::string>("schema_name","");
+ table_name_ = *params.get<std::string>("table_name","");
+
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext)
{
@@ -130,25 +133,32 @@
desc_.set_encoding(conn->client_encoding());
- std::string table_name=table_from_sql(table_);
- std::string schema_name="";
- std::string::size_type idx=table_name.find_last_of('.');
+ if (table_name_.length()==0)
+ {
+ table_name_=table_from_sql(table_);
+ std::string::size_type idx=table_name_.find_last_of('.');
if (idx!=std::string::npos)
{
- schema_name=table_name.substr(0,idx);
- table_name=table_name.substr(idx+1);
+ if (schema_name_.length()==0)
+ {
+ schema_name_=table_name_.substr(0,idx);
+ };
+ table_name_ =table_name_.substr(idx+1);
}
else
{
- table_name=table_name.substr(0);
+ table_name_=table_name_.substr(0);
}
+ };
+
+ geometryColumn_=geometry_field_;
std::ostringstream s;
s << "select f_geometry_column,srid,type from ";
- s << GEOMETRY_COLUMNS <<" where f_table_name='" << table_name<<"'";
+ s << GEOMETRY_COLUMNS <<" where f_table_name='" << table_name_<<"'";
- if (schema_name.length() > 0)
- s <<" and f_table_schema='"<< schema_name <<"'";
+ if (schema_name_.length() > 0)
+ s <<" and f_table_schema='"<< schema_name_ <<"'";
if (geometry_field_.length() > 0)
s << " and f_geometry_column = '" << geometry_field_ << "'";
@@ -361,21 +371,20 @@
{
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::ostringstream s;
- std::string table_name = table_from_sql(table_);
boost::optional<std::string> estimate_extent = params_.get<std::string>("estimate_extent");
if (estimate_extent && *estimate_extent == "true")
{
s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"
<< " from (select estimated_extent('"
- << table_name <<"','"
+ << table_name_ <<"','"
<< geometryColumn_ << "') as ext) as tmp";
}
else
{
s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"
<< " from (select extent(" <<geometryColumn_<< ") as ext from "
- << table_name << ") as tmp";
+ << table_name_ << ") as tmp";
}
shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
--- mapnik-0.6.1/plugins/input/postgis/postgis.hpp 2009-07-14 11:08:55.000000000 +0200
+++ mapnik-0.6.1-patched/plugins/input/postgis/postgis.hpp 2009-07-17 11:40:42.000000000 +0200
@@ -1,3 +1,4 @@
+
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
@@ -60,6 +61,8 @@
const std::string geometry_field_;
const int cursor_fetch_size_;
const int row_limit_;
+ std::string schema_name_;
+ std::string table_name_;
std::string geometryColumn_;
int type_;
int srid_;
_______________________________________________
Mapnik-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-devel