Skip to content
Permalink
Browse files

Fix memory layers lose CRS definition if it does not have an authority

associated with it

Fixes #36241
  • Loading branch information
nyalldawson committed May 20, 2020
1 parent f20801a commit e23a49a6b858cad9373c3bfb9ad66525622ce9ee
Showing with 19 additions and 2 deletions.
  1. +4 −1 src/core/providers/memory/qgsmemoryproviderutils.cpp
  2. +15 −1 tests/src/python/test_provider_memory.py
@@ -65,7 +65,10 @@ QgsVectorLayer *QgsMemoryProviderUtils::createMemoryLayer( const QString &name,
QStringList parts;
if ( crs.isValid() )
{
parts << QStringLiteral( "crs=" ) + crs.authid();
if ( !crs.authid().isEmpty() )
parts << QStringLiteral( "crs=%1" ).arg( crs.authid() );
else
parts << QStringLiteral( "crs=wkt:%1" ).arg( crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) );
}
for ( const auto &field : fields )
{
@@ -28,7 +28,8 @@
QgsCoordinateReferenceSystem,
QgsRectangle,
QgsTestUtils,
QgsFeatureSource
QgsFeatureSource,
QgsProjUtils
)

from qgis.testing import (
@@ -443,6 +444,19 @@ def testCreateMemoryLayer(self):
self.assertTrue(layer.crs().isValid())
self.assertEqual(layer.crs().authid(), 'EPSG:3111')

# custom CRS
if QgsProjUtils.projVersionMajor() >= 6:
crs = QgsCoordinateReferenceSystem.fromProj('+proj=qsc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs')
layer = QgsMemoryProviderUtils.createMemoryLayer('my name', QgsFields(), QgsWkbTypes.PolygonZM, crs)
self.assertTrue(layer.isValid())
self.assertTrue(layer.crs().isValid())
self.assertEqual(layer.crs().toProj(), '+proj=qsc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs +type=crs')

# clone it, just to check
layer2 = layer.clone()
self.assertEqual(layer2.crs().toProj(),
'+proj=qsc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs +type=crs')

# fields
fields = QgsFields()
fields.append(QgsField("string", QVariant.String))

0 comments on commit e23a49a

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