Skip to content
Permalink
Browse files

[afs] Fix handling of custom projections

Don't treat all unknown projections as WGS84

Fixes #18881
  • Loading branch information
nyalldawson committed May 7, 2018
1 parent 3fef9cd commit ea38c7322bedbd9b37342de8f48c6700931df50e
@@ -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;
@@ -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 );
@@ -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;
}

@@ -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();
@@ -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 );

0 comments on commit ea38c73

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