Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for Pointcloud layers
- Loading branch information
Showing
4 changed files
with
102 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,12 +364,12 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
|
||
mLayersSupported.clear(); | ||
|
||
for ( int i = 0; i < ( hasTopology() ? 3 : 2 ); i++ ) | ||
for ( int i = sctGeometry; i <= sctPcPatch; ++i ) | ||
{ | ||
QString sql, tableName, schemaName, columnName, typeName, sridName, gtableName, dimName; | ||
QgsPostgresGeometryColumnType columnType = sctGeometry; | ||
|
||
if ( i == 0 ) | ||
if ( i == sctGeometry ) | ||
{ | ||
tableName = "l.f_table_name"; | ||
schemaName = "l.f_table_schema"; | ||
|
@@ -380,7 +380,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
gtableName = "geometry_columns"; | ||
columnType = sctGeometry; | ||
} | ||
else if ( i == 1 ) | ||
else if ( i == sctGeography ) | ||
{ | ||
tableName = "l.f_table_name"; | ||
schemaName = "l.f_table_schema"; | ||
|
@@ -391,8 +391,10 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
gtableName = "geography_columns"; | ||
columnType = sctGeography; | ||
} | ||
else if ( i == 2 ) | ||
else if ( i == sctTopoGeometry ) | ||
{ | ||
if ( ! hasTopology() ) continue; | ||
|
||
schemaName = "l.schema_name"; | ||
tableName = "l.table_name"; | ||
columnName = "l.feature_column"; | ||
|
@@ -407,6 +409,25 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
gtableName = "topology.layer"; | ||
columnType = sctTopoGeometry; | ||
} | ||
else if ( i == sctPcPatch ) | ||
{ | ||
if ( ! hasPointcloud() ) continue; | ||
|
||
tableName = "l.\"table\""; | ||
schemaName = "l.\"schema\""; | ||
columnName = "l.\"column\""; | ||
typeName = "'POLYGON'"; | ||
sridName = "l.srid"; | ||
dimName = "2"; | ||
gtableName = "pointcloud_columns"; | ||
columnType = sctPcPatch; | ||
} | ||
else | ||
{ | ||
QgsMessageLog::logMessage( tr( "Unsupported spatial column type %1" ) | ||
.arg( displayStringForGeomType(( QgsPostgresGeometryColumnType )i ) ) ); | ||
continue; | ||
} | ||
|
||
// The following query returns only tables that exist and the user has SELECT privilege on. | ||
// Can't use regclass here because table must exist, else error occurs. | ||
|
@@ -510,7 +531,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
" WHERE c.relkind IN ('v','r','m')" | ||
" AND has_schema_privilege( n.nspname, 'usage' )" | ||
" AND has_table_privilege( '\"' || n.nspname || '\".\"' || c.relname || '\"', 'select' )" | ||
" AND (t.typname IN ('geometry','geography','topogeometry') OR b.typname IN ('geometry','geography','topogeometry'))"; | ||
" AND (t.typname IN ('geometry','geography','topogeometry') OR b.typname IN ('geometry','geography','topogeometry','pcpatch'))"; | ||
|
||
// user has select privilege | ||
if ( searchPublicOnly ) | ||
|
@@ -522,19 +543,19 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
// skip columns of which we already derived information from the metadata tables | ||
if ( nColumns > 0 ) | ||
{ | ||
if ( foundInTables & 1 ) | ||
if ( foundInTables & ( 1 << sctGeometry ) ) | ||
{ | ||
sql += " AND (n.nspname,c.relname,a.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geometry_column FROM geometry_columns)"; | ||
} | ||
|
||
if ( foundInTables & 2 ) | ||
if ( foundInTables & ( 1 << sctGeography ) ) | ||
{ | ||
sql += " AND (n.nspname,c.relname,a.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geography_column FROM geography_columns)"; | ||
} | ||
|
||
if ( foundInTables & 4 ) | ||
if ( foundInTables & ( 1 << sctPcPatch ) ) | ||
{ | ||
sql += " AND (n.nspname,c.relname,a.attname) NOT IN (SELECT schema_name,table_name,feature_column FROM topology.layer)"; | ||
sql += " AND (n.nspname,c.relname,a.attname) NOT IN (SELECT \"schema\",\"table\",\"column\" FROM pointcloud_columns)"; | ||
} | ||
} | ||
|
||
|
@@ -586,6 +607,10 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP | |
{ | ||
layerProperty.geometryColType = sctTopoGeometry; | ||
} | ||
else if ( coltype == "pcpatch" ) | ||
{ | ||
layerProperty.geometryColType = sctPcPatch; | ||
} | ||
else | ||
{ | ||
Q_ASSERT( !"Unknown geometry type" ); | ||
|
@@ -747,6 +772,16 @@ bool QgsPostgresConn::hasTopology() | |
return mTopologyAvailable; | ||
} | ||
|
||
/** | ||
* Check to see if pointcloud is available | ||
*/ | ||
bool QgsPostgresConn::hasPointcloud() | ||
{ | ||
// TODO: use mPointcloudAvailable function instead | ||
QgsPostgresResult result = PQexec( "SELECT 'pointcloud_columns'::regclass" ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
strk
Contributor
|
||
return result.PQntuples() == 1; | ||
} | ||
|
||
/* Functions for determining available features in postGIS */ | ||
QString QgsPostgresConn::postgisVersion() | ||
{ | ||
|
@@ -1279,12 +1314,15 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert | |
|
||
QString query = "SELECT DISTINCT "; | ||
|
||
bool castToGeometry = layerProperty.geometryColType == sctGeography || | ||
layerProperty.geometryColType == sctPcPatch; | ||
|
||
QGis::WkbType type = layerProperty.types.value( 0, QGis::WKBUnknown ); | ||
if ( type == QGis::WKBUnknown ) | ||
{ | ||
query += QString( "upper(geometrytype(%1%2))" ) | ||
.arg( quotedIdentifier( layerProperty.geometryColName ) ) | ||
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" ); | ||
.arg( castToGeometry ? "::geometry" : "" ); | ||
} | ||
else | ||
{ | ||
|
@@ -1299,7 +1337,7 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert | |
query += QString( "%1(%2%3)" ) | ||
.arg( majorVersion() < 2 ? "srid" : "st_srid" ) | ||
.arg( quotedIdentifier( layerProperty.geometryColName ) ) | ||
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" ); | ||
.arg( castToGeometry ? "::geometry" : "" ); | ||
} | ||
else | ||
{ | ||
|
@@ -1311,7 +1349,7 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert | |
query += QString( ",%1(%2%3)" ) | ||
.arg( majorVersion() < 2 ? "ndims" : "st_ndims" ) | ||
.arg( quotedIdentifier( layerProperty.geometryColName ) ) | ||
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" ); | ||
.arg( castToGeometry ? "::geometry" : "" ); | ||
} | ||
|
||
query += " FROM " + table; | ||
|
@@ -1426,10 +1464,10 @@ QString QgsPostgresConn::postgisWkbTypeName( QGis::WkbType wkbType ) | |
return geometryType; | ||
} | ||
|
||
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QGis::WkbType geomType, bool isGeography ) | ||
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QGis::WkbType geomType, bool castToGeometry ) | ||
{ | ||
geomCol = quotedIdentifier( geomCol ); | ||
if ( isGeography ) | ||
if ( castToGeometry ) | ||
geomCol += "::geometry"; | ||
|
||
switch ( geomType ) | ||
|
@@ -1601,6 +1639,8 @@ QString QgsPostgresConn::displayStringForGeomType( QgsPostgresGeometryColumnType | |
return tr( "Geography" ); | ||
case sctTopoGeometry: | ||
return tr( "TopoGeometry" ); | ||
case sctPcPatch: | ||
return tr( "PcPatch" ); | ||
} | ||
|
||
Q_ASSERT( !"unexpected geometry column type" ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@strk I'm seeing a lot of errors in the PostGIS log messages window following this commit:
"Erroneous query: SELECT 'pointcloud_columns'::regclass returned 7 [ERROR: relation "pointcloud_columns" does not exist
LINE 1: SELECT 'pointcloud_columns'::regclass"