Navigation Menu

Skip to content

Commit

Permalink
[afs] Fix handling of custom projections
Browse files Browse the repository at this point in the history
Don't treat all unknown projections as WGS84

Fixes #18881
  • Loading branch information
nyalldawson committed May 7, 2018
1 parent 3fef9cd commit ea38c73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsprovider.cpp
Expand Up @@ -47,7 +47,7 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri )
mSharedData->mDataSource = QgsDataSourceUri( uri );

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

// Get layer info
QString errorTitle, errorMessage;
Expand Down
5 changes: 0 additions & 5 deletions src/providers/arcgisrest/qgsafssourceselect.cpp
Expand Up @@ -90,11 +90,6 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
cachedItem->setCheckState( Qt::Checked );

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

mModel->appendRow( QList<QStandardItem *>() << idItem << nameItem << abstractItem << cachedItem << filterItem );
Expand Down
7 changes: 5 additions & 2 deletions src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -342,8 +342,11 @@ QgsCoordinateReferenceSystem QgsArcGisRestUtils::parseSpatialReference( const QV
spatialReference = QStringLiteral( "EPSG:%1" ).arg( spatialReference );
QgsCoordinateReferenceSystem crs;
crs.createFromString( spatialReference );
if ( crs.authid().startsWith( QLatin1String( "USER:" ) ) )
crs.createFromString( QStringLiteral( "EPSG:4326" ) ); // If we can't recognize the SRS, fall back to WGS84
if ( !crs.isValid() )
{
// If not spatial reference, just use WGS84
crs.createFromString( QStringLiteral( "EPSG:4326" ) );
}
return crs;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/src/providers/testqgsarcgisrestutils.cpp
Expand Up @@ -37,6 +37,7 @@ class TestQgsArcGisRestUtils : public QObject
void init() {}// will be called before each testfunction is executed.
void cleanup() {}// will be called after every testfunction.
void testMapEsriFieldType();
void testParseSpatialReference();
void testMapEsriGeometryType();
void testParseEsriFillStyle();
void testParseEsriLineStyle();
Expand Down Expand Up @@ -89,6 +90,18 @@ void TestQgsArcGisRestUtils::testMapEsriFieldType()
QCOMPARE( QgsArcGisRestUtils::mapEsriFieldType( QStringLiteral( "xxx" ) ), QVariant::Invalid );
}

void TestQgsArcGisRestUtils::testParseSpatialReference()
{
QVariantMap map;
map.insert(
QStringLiteral( "wkt" ),
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]]" ) );

QgsCoordinateReferenceSystem crs = QgsArcGisRestUtils::parseSpatialReference( map );
QVERIFY( crs.isValid() );
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]]" ) );
}

void TestQgsArcGisRestUtils::testMapEsriGeometryType()
{
QCOMPARE( QgsArcGisRestUtils::mapEsriGeometryType( QStringLiteral( "esriGeometryNull" ) ), QgsWkbTypes::Unknown );
Expand Down

0 comments on commit ea38c73

Please sign in to comment.