Skip to content

Commit

Permalink
Non spatial layers do not have a CRS - API changes only, needs UI change
Browse files Browse the repository at this point in the history
Refs #19689
  • Loading branch information
nyalldawson committed Aug 27, 2018
1 parent c87b625 commit 1b56055
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -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();
Expand Down
14 changes: 2 additions & 12 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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 );
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_qgsvectorlayer.py
Expand Up @@ -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):
Expand Down

0 comments on commit 1b56055

Please sign in to comment.