mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
PG unrestricted geometry: trust SRID from geometry_columns
Fixes #38567 where the SRID was not detected if the table was empty. Also: do not override the SRID passed explicitly in the data source URI. Note: the logic in the provider is becoming a bit convoluted, there are too many corner cases, at least the test coverage is pretty good.
This commit is contained in:
parent
39b78b4006
commit
1560d9aea8
@ -3874,6 +3874,12 @@ bool QgsPostgresProvider::getGeometryDetails()
|
||||
{
|
||||
detectedType = result.PQgetvalue( 0, 0 );
|
||||
|
||||
// Do not override the SRID if set in the data source URI
|
||||
if ( detectedSrid.isEmpty() )
|
||||
{
|
||||
detectedSrid = result.PQgetvalue( 0, 1 );
|
||||
}
|
||||
|
||||
QString dim = result.PQgetvalue( 0, 2 );
|
||||
if ( dim == QLatin1String( "3" ) && !detectedType.endsWith( 'M' ) )
|
||||
detectedType += QLatin1String( "Z" );
|
||||
@ -4047,7 +4053,6 @@ bool QgsPostgresProvider::getGeometryDetails()
|
||||
|
||||
if ( mDetectedGeomType == QgsWkbTypes::Unknown )
|
||||
{
|
||||
mDetectedSrid.clear();
|
||||
|
||||
QgsPostgresLayerProperty layerProperty;
|
||||
if ( !mIsQuery )
|
||||
@ -4077,8 +4082,8 @@ bool QgsPostgresProvider::getGeometryDetails()
|
||||
|
||||
if ( layerProperty.size() == 0 )
|
||||
{
|
||||
// no data - so take what's requested
|
||||
if ( mRequestedGeomType == QgsWkbTypes::Unknown || mRequestedSrid.isEmpty() )
|
||||
// no data - so take what's requested/detected
|
||||
if ( mRequestedGeomType == QgsWkbTypes::Unknown || mDetectedSrid.isEmpty() )
|
||||
{
|
||||
QgsMessageLog::logMessage( tr( "Geometry type and srid for empty column %1 of %2 undefined." ).arg( mGeometryColumn, mQuery ) );
|
||||
}
|
||||
|
@ -2972,6 +2972,18 @@ class TestPyQgsPostgresProviderBigintSinglePk(unittest.TestCase, ProviderTestCas
|
||||
with self.assertRaises(StopIteration):
|
||||
next(polygons.getFeatures())
|
||||
|
||||
# Test regression GH #38567 (no SRID requested in the data source URI)
|
||||
# Cleanup if needed
|
||||
conn.executeSql('DELETE FROM "qgis_test"."test_unrestricted_geometry" WHERE \'t\'')
|
||||
|
||||
points = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'gid\' type=POINT table="qgis_test"."test_unrestricted_geometry" (geom) sql=', 'test_points', 'postgres')
|
||||
lines = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'gid\' type=LINESTRING table="qgis_test"."test_unrestricted_geometry" (geom) sql=', 'test_lines', 'postgres')
|
||||
polygons = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'gid\' type=POLYGON table="qgis_test"."test_unrestricted_geometry" (geom) sql=', 'test_polygons', 'postgres')
|
||||
|
||||
self.assertTrue(points.isValid())
|
||||
self.assertTrue(lines.isValid())
|
||||
self.assertTrue(polygons.isValid())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user