Use geometry_table_ rather than table_ for SRID lookup
- this will result in a faster query in the case that the user provides an explicit geometry_table option
This commit is contained in:
parent
d6175adb1a
commit
4a1f4a9b5e
1 changed files with 24 additions and 21 deletions
|
@ -195,6 +195,8 @@ postgis_datasource::postgis_datasource(parameters const& params)
|
||||||
if (rs->next())
|
if (rs->next())
|
||||||
{
|
{
|
||||||
geometryColumn_ = rs->getValue("f_geometry_column");
|
geometryColumn_ = rs->getValue("f_geometry_column");
|
||||||
|
// only accept srid from geometry_tables if
|
||||||
|
// user has not provided as option
|
||||||
if (srid_ == 0)
|
if (srid_ == 0)
|
||||||
{
|
{
|
||||||
const char* srid_c = rs->getValue("srid");
|
const char* srid_c = rs->getValue("srid");
|
||||||
|
@ -211,20 +213,22 @@ postgis_datasource::postgis_datasource(parameters const& params)
|
||||||
}
|
}
|
||||||
rs->close();
|
rs->close();
|
||||||
}
|
}
|
||||||
catch (mapnik::datasource_exception const& ex) {
|
catch (mapnik::datasource_exception const& ex)
|
||||||
|
{
|
||||||
// let this pass on query error and use the fallback below
|
// let this pass on query error and use the fallback below
|
||||||
MAPNIK_LOG_WARN(postgis) << "postgis_datasource: metadata query failed: " << ex.what();
|
MAPNIK_LOG_WARN(postgis) << "postgis_datasource: metadata query failed: " << ex.what();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we still do not know the srid then we can try to fetch
|
// If we still do not know the srid then we can try to fetch
|
||||||
// it from the 'table_' parameter, which should work even if it is
|
// it from the 'geometry_table_' parameter, which should work even if it is
|
||||||
// a subselect as long as we know the geometry_field to query
|
// a subselect as long as we know the geometry_field to query
|
||||||
if (! geometryColumn_.empty() && srid_ <= 0)
|
if (! geometryColumn_.empty() && srid_ <= 0)
|
||||||
{
|
{
|
||||||
s.str("");
|
std::ostringstream s;
|
||||||
|
|
||||||
s << "SELECT ST_SRID(\"" << geometryColumn_ << "\") AS srid FROM "
|
s << "SELECT ST_SRID(\"" << geometryColumn_ << "\") AS srid FROM "
|
||||||
<< populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;";
|
<< populate_tokens(geometry_table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;";
|
||||||
|
|
||||||
shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
|
shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
|
||||||
if (rs->next())
|
if (rs->next())
|
||||||
|
@ -242,7 +246,6 @@ postgis_datasource::postgis_datasource(parameters const& params)
|
||||||
}
|
}
|
||||||
rs->close();
|
rs->close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// detect primary key
|
// detect primary key
|
||||||
if (*autodetect_key_field && key_field_.empty())
|
if (*autodetect_key_field && key_field_.empty())
|
||||||
|
|
Loading…
Reference in a new issue