Skip to content

Commit ea38c73

Browse files
committedMay 7, 2018
[afs] Fix handling of custom projections
Don't treat all unknown projections as WGS84 Fixes #18881
1 parent 3fef9cd commit ea38c73

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed
 

‎src/providers/arcgisrest/qgsafsprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri )
4747
mSharedData->mDataSource = QgsDataSourceUri( uri );
4848

4949
// Set CRS
50-
mSharedData->mSourceCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mSharedData->mDataSource.param( QStringLiteral( "crs" ) ) );
50+
mSharedData->mSourceCRS.createFromString( mSharedData->mDataSource.param( QStringLiteral( "crs" ) ) );
5151

5252
// Get layer info
5353
QString errorTitle, errorMessage;

‎src/providers/arcgisrest/qgsafssourceselect.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
9090
cachedItem->setCheckState( Qt::Checked );
9191

9292
QgsCoordinateReferenceSystem crs = QgsArcGisRestUtils::parseSpatialReference( serviceInfoMap[QStringLiteral( "spatialReference" )].toMap() );
93-
if ( !crs.isValid() )
94-
{
95-
// If not spatial reference, just use WGS84
96-
crs.createFromString( QStringLiteral( "EPSG:4326" ) );
97-
}
9893
mAvailableCRS[layerData[QStringLiteral( "name" )].toString()] = QList<QString>() << crs.authid();
9994

10095
mModel->appendRow( QList<QStandardItem *>() << idItem << nameItem << abstractItem << cachedItem << filterItem );

‎src/providers/arcgisrest/qgsarcgisrestutils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,11 @@ QgsCoordinateReferenceSystem QgsArcGisRestUtils::parseSpatialReference( const QV
342342
spatialReference = QStringLiteral( "EPSG:%1" ).arg( spatialReference );
343343
QgsCoordinateReferenceSystem crs;
344344
crs.createFromString( spatialReference );
345-
if ( crs.authid().startsWith( QLatin1String( "USER:" ) ) )
346-
crs.createFromString( QStringLiteral( "EPSG:4326" ) ); // If we can't recognize the SRS, fall back to WGS84
345+
if ( !crs.isValid() )
346+
{
347+
// If not spatial reference, just use WGS84
348+
crs.createFromString( QStringLiteral( "EPSG:4326" ) );
349+
}
347350
return crs;
348351
}
349352

‎tests/src/providers/testqgsarcgisrestutils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TestQgsArcGisRestUtils : public QObject
3737
void init() {}// will be called before each testfunction is executed.
3838
void cleanup() {}// will be called after every testfunction.
3939
void testMapEsriFieldType();
40+
void testParseSpatialReference();
4041
void testMapEsriGeometryType();
4142
void testParseEsriFillStyle();
4243
void testParseEsriLineStyle();
@@ -89,6 +90,18 @@ void TestQgsArcGisRestUtils::testMapEsriFieldType()
8990
QCOMPARE( QgsArcGisRestUtils::mapEsriFieldType( QStringLiteral( "xxx" ) ), QVariant::Invalid );
9091
}
9192

93+
void TestQgsArcGisRestUtils::testParseSpatialReference()
94+
{
95+
QVariantMap map;
96+
map.insert(
97+
QStringLiteral( "wkt" ),
98+
QStringLiteral( "PROJCS[\"NewJTM\",GEOGCS[\"GCS_ETRF_1989\",DATUM[\"D_ETRF_1989\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",40000.0],PARAMETER[\"False_Northing\",70000.0],PARAMETER[\"Central_Meridian\",-2.135],PARAMETER[\"Scale_Factor\",0.9999999],PARAMETER[\"Latitude_Of_Origin\",49.225],UNIT[\"Meter\",1.0]]" ) );
99+
100+
QgsCoordinateReferenceSystem crs = QgsArcGisRestUtils::parseSpatialReference( map );
101+
QVERIFY( crs.isValid() );
102+
QCOMPARE( crs.toWkt(), QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"WGS 84\",DATUM[\"unknown\",SPHEROID[\"WGS84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49.225],PARAMETER[\"central_meridian\",-2.135],PARAMETER[\"scale_factor\",0.9999999],PARAMETER[\"false_easting\",40000],PARAMETER[\"false_northing\",70000],UNIT[\"Meter\",1]]" ) );
103+
}
104+
92105
void TestQgsArcGisRestUtils::testMapEsriGeometryType()
93106
{
94107
QCOMPARE( QgsArcGisRestUtils::mapEsriGeometryType( QStringLiteral( "esriGeometryNull" ) ), QgsWkbTypes::Unknown );

0 commit comments

Comments
 (0)
Please sign in to comment.