Skip to content

Commit cbf6302

Browse files
Sandro Santillijef-n
authored andcommittedNov 25, 2011
[FEATURE] Detect topology support
1 parent 5543a89 commit cbf6302

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
674674
"GEOS support (http://geos.refractions.net)" ) );
675675
}
676676

677+
if ( conn->hasTopology() )
678+
{
679+
QgsDebugMsg( "Topology support available!" );
680+
}
681+
677682

678683

679684
return conn;
@@ -3008,9 +3013,22 @@ bool QgsPostgresProvider::Conn::hasGEOS()
30083013
return geosAvailable;
30093014
}
30103015

3016+
/**
3017+
* Check to see if topology is available
3018+
*/
3019+
bool QgsPostgresProvider::Conn::hasTopology()
3020+
{
3021+
// make sure info is up to date for the current connection
3022+
postgisVersion();
3023+
// get topology capability
3024+
return topologyAvailable;
3025+
}
3026+
30113027
/* Functions for determining available features in postGIS */
30123028
QString QgsPostgresProvider::Conn::postgisVersion()
30133029
{
3030+
if ( gotPostgisVersion ) return postgisVersionInfo;
3031+
30143032
postgresqlVersion = PQserverVersion( conn );
30153033

30163034
Result result = PQexec( "select postgis_version()" );
@@ -3075,6 +3093,18 @@ QString QgsPostgresProvider::Conn::postgisVersion()
30753093
}
30763094
}
30773095

3096+
// checking for topology support
3097+
QgsDebugMsg( "Checking for topology support" );
3098+
topologyAvailable = false;
3099+
if ( postgisVersionMajor > 1 )
3100+
{
3101+
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'" );
3102+
if ( PQntuples( result ) >= 1 )
3103+
{
3104+
topologyAvailable = true;
3105+
}
3106+
}
3107+
30783108
gotPostgisVersion = true;
30793109

30803110
return postgisVersionInfo;

‎src/providers/postgres/qgspostgresprovider.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ class QgsPostgresProvider : public QgsVectorDataProvider
644644
//! get status of GEOS capability
645645
bool hasGEOS();
646646

647+
//! get status of topology capability
648+
bool hasTopology();
649+
647650
//! get status of GIST capability
648651
bool hasGIST();
649652

@@ -693,10 +696,13 @@ class QgsPostgresProvider : public QgsVectorDataProvider
693696
//! GEOS capability
694697
bool geosAvailable;
695698

699+
//! Topology capability
700+
bool topologyAvailable;
701+
696702
//! PostGIS version string
697703
QString postgisVersionInfo;
698704

699-
//! Are postgisVersionMajor, postgisVersionMinor, geosAvailable, gistAvailable, projAvailable valid?
705+
//! Are postgisVersionMajor, postgisVersionMinor, geosAvailable, gistAvailable, projAvailable, topologyAvailable valid?
700706
bool gotPostgisVersion;
701707

702708
//! PostgreSQL version

0 commit comments

Comments
 (0)
Please sign in to comment.