Skip to content
Permalink
Browse files

Non spatial layers do not have a CRS - API changes only, needs UI change

Refs #19689
  • Loading branch information
nyalldawson committed Aug 25, 2018
1 parent c87b625 commit 1b560559e505d571d4519bdb5303f2240aa35209
Showing with 21 additions and 13 deletions.
  1. +1 −1 src/core/qgsmaplayer.cpp
  2. +2 −12 src/core/qgsvectorlayer.cpp
  3. +18 −0 tests/src/python/test_qgsvectorlayer.py
@@ -738,7 +738,7 @@ void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSign
{
mCRS = srs;

if ( !mCRS.isValid() )
if ( isSpatial() && !mCRS.isValid() )
{
mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS.validate();
@@ -3010,20 +3010,10 @@ bool QgsVectorLayer::addFeatures( QgsFeatureList &features, Flags )

void QgsVectorLayer::setCoordinateSystem()
{
QgsDebugMsgLevel( QStringLiteral( "Computing Coordinate System" ), 4 );

if ( isSpatial() )
{
// get CRS directly from provider
setCrs( mDataProvider->crs() );
}
else
{
setCrs( QgsCoordinateReferenceSystem( GEO_EPSG_CRS_AUTHID ) );
}
// if layer is not spatial, it has not CRS!
setCrs( isSpatial() ? mDataProvider->crs() : QgsCoordinateReferenceSystem() );
}


QString QgsVectorLayer::displayField() const
{
QgsExpression exp( mDisplayExpression );
@@ -336,6 +336,24 @@ def testSetDataSource(self):
self.assertNotEqual(layer.renderer(), r)
self.assertEqual(layer.renderer().symbol().type(), QgsSymbol.Line)

def test_layer_crs(self):
"""
Test that spatial layers have CRS, and non-spatial don't
"""
vl = QgsVectorLayer('Point?crs=epsg:3111&field=pk:integer', 'test', 'memory')
self.assertTrue(vl.isSpatial())
self.assertTrue(vl.crs().isValid())
self.assertEqual(vl.crs().authid(), 'EPSG:3111')

vl = QgsVectorLayer('None?field=pk:integer', 'test', 'memory')
self.assertFalse(vl.isSpatial())
self.assertFalse(vl.crs().isValid())

# even if provider has a crs - we don't respect it for non-spatial layers!
vl = QgsVectorLayer('None?crs=epsg:3111field=pk:integer', 'test', 'memory')
self.assertFalse(vl.isSpatial())
self.assertFalse(vl.crs().isValid())

# ADD FEATURE

def test_AddFeature(self):

0 comments on commit 1b56055

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