Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Detect topology support
  • Loading branch information
Sandro Santilli authored and jef-n committed Nov 25, 2011
1 parent 5543a89 commit cbf6302
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -674,6 +674,11 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
"GEOS support (http://geos.refractions.net)" ) );
}

if ( conn->hasTopology() )
{
QgsDebugMsg( "Topology support available!" );
}



return conn;
Expand Down Expand Up @@ -3008,9 +3013,22 @@ bool QgsPostgresProvider::Conn::hasGEOS()
return geosAvailable;
}

/**
* Check to see if topology is available
*/
bool QgsPostgresProvider::Conn::hasTopology()
{
// make sure info is up to date for the current connection
postgisVersion();
// get topology capability
return topologyAvailable;
}

/* Functions for determining available features in postGIS */
QString QgsPostgresProvider::Conn::postgisVersion()
{
if ( gotPostgisVersion ) return postgisVersionInfo;

postgresqlVersion = PQserverVersion( conn );

Result result = PQexec( "select postgis_version()" );
Expand Down Expand Up @@ -3075,6 +3093,18 @@ QString QgsPostgresProvider::Conn::postgisVersion()
}
}

// checking for topology support
QgsDebugMsg( "Checking for topology support" );
topologyAvailable = false;
if ( postgisVersionMajor > 1 )
{
Result result = PQexec( "select count(c.oid) from pg_class as c join pg_namespace as n on c.relnamespace = n.oid where n.nspname = 'topology' and c.relname = 'topology'" );
if ( PQntuples( result ) >= 1 )
{
topologyAvailable = true;
}
}

gotPostgisVersion = true;

return postgisVersionInfo;
Expand Down
8 changes: 7 additions & 1 deletion src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -644,6 +644,9 @@ class QgsPostgresProvider : public QgsVectorDataProvider
//! get status of GEOS capability
bool hasGEOS();

//! get status of topology capability
bool hasTopology();

//! get status of GIST capability
bool hasGIST();

Expand Down Expand Up @@ -693,10 +696,13 @@ class QgsPostgresProvider : public QgsVectorDataProvider
//! GEOS capability
bool geosAvailable;

//! Topology capability
bool topologyAvailable;

//! PostGIS version string
QString postgisVersionInfo;

//! Are postgisVersionMajor, postgisVersionMinor, geosAvailable, gistAvailable, projAvailable valid?
//! Are postgisVersionMajor, postgisVersionMinor, geosAvailable, gistAvailable, projAvailable, topologyAvailable valid?
bool gotPostgisVersion;

//! PostgreSQL version
Expand Down

0 comments on commit cbf6302

Please sign in to comment.