Skip to content

Commit

Permalink
Initial support for adding new TopoGeometry objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Dec 2, 2012
1 parent ee0ba0e commit 5cf1c77
Showing 1 changed file with 65 additions and 20 deletions.
85 changes: 65 additions & 20 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1814,31 +1814,69 @@ QString QgsPostgresProvider::paramValue( QString fieldValue, const QString &defa

QString QgsPostgresProvider::geomParam( int offset ) const
{
// TODO: retrive these at construction time
QString toponame;
long layer_id;

if ( mSpatialColType == sctTopoGeometry )
{
QString sql = QString( "SELECT t.name, l.layer_id FROM topology.layer l, topology.topology t "
"WHERE l.topology_id = t.id AND l.schema_name=%1 "
"AND l.table_name=%2 AND l.feature_column=%3" )
.arg( quotedValue( mSchemaName ) )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mGeometryColumn ) );
QgsPostgresResult result = mConnectionRO->PQexec( sql );
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
{
throw PGException( result ); // we should probably not do this
}
if ( result.PQntuples() < 1 )
{
QgsMessageLog::logMessage( tr( "Could not find topology of layer %1.%2.%3" )
.arg( quotedValue( mSchemaName ) )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mGeometryColumn ) ),
tr( "PostGIS" ) );
}
toponame = result.PQgetvalue( 0, 0 );
layer_id = result.PQgetvalue( 0, 1 ).toLong();

}

QString geometry;

bool forceMulti = false;

switch ( geometryType() )
{
case QGis::WKBPoint:
case QGis::WKBLineString:
case QGis::WKBPolygon:
case QGis::WKBPoint25D:
case QGis::WKBLineString25D:
case QGis::WKBPolygon25D:
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
forceMulti = false;
break;
if ( mSpatialColType != sctTopoGeometry )
{
switch ( geometryType() )
{
case QGis::WKBPoint:
case QGis::WKBLineString:
case QGis::WKBPolygon:
case QGis::WKBPoint25D:
case QGis::WKBLineString25D:
case QGis::WKBPolygon25D:
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
forceMulti = false;
break;

case QGis::WKBMultiPoint:
case QGis::WKBMultiLineString:
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiPolygon25D:
forceMulti = true;
break;
case QGis::WKBMultiPoint:
case QGis::WKBMultiLineString:
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiPolygon25D:
forceMulti = true;
break;
}
}

if ( mSpatialColType == sctTopoGeometry )
{
geometry += QString( "toTopoGeom(" );
}

if ( forceMulti )
Expand All @@ -1857,6 +1895,13 @@ QString QgsPostgresProvider::geomParam( int offset ) const
geometry += ")";
}

if ( mSpatialColType == sctTopoGeometry )
{
geometry += QString( ",%1,%2)" )
.arg( quotedValue(toponame) )
.arg( layer_id );
}

return geometry;
}

Expand Down

0 comments on commit 5cf1c77

Please sign in to comment.