Skip to content
Permalink
Browse files

Determine geometry type and srid directly from column type

  • Loading branch information
SebDieBln committed Nov 14, 2015
1 parent 4edf1ee commit 6b3651faef3e02f48188ae8005c80b3a4e097a6b
Showing with 36 additions and 1 deletion.
  1. +36 −1 src/providers/postgres/qgspostgresprovider.cpp
@@ -2910,7 +2910,42 @@ bool QgsPostgresProvider::getGeometryDetails()
}
else
{
detectedType = mRequestedGeomType == QGis::WKBUnknown ? "" : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
sql = QString( "SELECT %1 FROM %2 LIMIT 0" ).arg( quotedIdentifier( mGeometryColumn ), mQuery );
result = connectionRO()->PQexec( sql );
if ( PGRES_TUPLES_OK == result.PQresultStatus() )
{
sql = QString( "SELECT (SELECT t.typname FROM pg_type t WHERE oid = %1), upper(postgis_typmod_type(%2)), postgis_typmod_srid(%2)" )
.arg(QString::number( result.PQftype( 0 ) ), QString::number( result.PQfmod( 0 ) ) );
result = connectionRO()->PQexec( sql );
if ( result.PQntuples() == 1 )
{
geomColType = result.PQgetvalue( 0, 0 );
detectedType = result.PQgetvalue( 0, 1 );
detectedSrid = result.PQgetvalue( 0, 2 );
if ( geomColType == "geometry" )
mSpatialColType = sctGeometry;
else if ( geomColType == "geography" )
mSpatialColType = sctGeography;
else if ( geomColType == "topogeometry" )
mSpatialColType = sctTopoGeometry;
else if ( geomColType == "pcpatch" )
mSpatialColType = sctPcPatch;
else {
detectedType = mRequestedGeomType == QGis::WKBUnknown ? "" : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
detectedSrid = mRequestedSrid;
}
}
else
{
connectionRO()->PQexecNR( "COMMIT" );
detectedType = mRequestedGeomType == QGis::WKBUnknown ? "" : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
}
}
else
{
mValid = false;
return false;
}
}

mDetectedGeomType = QgsPostgresConn::wkbTypeFromPostgis( detectedType );

0 comments on commit 6b3651f

Please sign in to comment.
You can’t perform that action at this time.