Skip to content

Commit

Permalink
Accept "proj:..." prefix in QgsCoordinateReferenceSystem::createFromS…
Browse files Browse the repository at this point in the history
…tring

instead of just "proj4:..."

(cherry picked from commit f547049)
  • Loading branch information
nyalldawson committed Feb 27, 2020
1 parent c053e7e commit 83eaba9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Expand Up @@ -191,7 +191,7 @@ It supports the following formats:
- "EPSG:<code>" - handled with createFromOgcWms()
- "POSTGIS:<srid>" - handled with createFromSrid()
- "INTERNAL:<srsid>" - handled with createFromSrsId()
- "PROJ4:<proj4>" - handled with createFromProj()
- "PROJ:<proj>" - handled with createFromProj()
- "WKT:<wkt>" - handled with createFromWkt()

If no prefix is specified, WKT definition is assumed.
Expand Down Expand Up @@ -485,7 +485,7 @@ It supports the following formats:
- "EPSG:<code>" - handled with createFromOgcWms()
- "POSTGIS:<srid>" - handled with createFromSrid()
- "INTERNAL:<srsid>" - handled with createFromSrsId()
- "PROJ4:<proj4>" - handled with createFromProj()
- "PROJ:<proj>" - handled with createFromProj()
- "WKT:<wkt>" - handled with createFromWkt()

If no prefix is specified, WKT definition is assumed.
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -313,11 +313,11 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
}
else
{
QRegularExpression reCrsStr( "^(?:(wkt|proj4)\\:)?(.+)$", QRegularExpression::CaseInsensitiveOption );
QRegularExpression reCrsStr( "^(?:(wkt|proj4|proj)\\:)?(.+)$", QRegularExpression::CaseInsensitiveOption );
match = reCrsStr.match( definition );
if ( match.capturedStart() == 0 )
{
if ( match.captured( 1 ).compare( QLatin1String( "proj4" ), Qt::CaseInsensitive ) == 0 )
if ( match.captured( 1 ).startsWith( QLatin1String( "proj" ), Qt::CaseInsensitive ) )
{
result = createFromProj( match.captured( 2 ) );
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -228,7 +228,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

~QgsCoordinateReferenceSystem();

// TODO QGIS 4: remove "POSTGIS" and "INTERNAL", allow PROJ4 without the prefix
// TODO QGIS 4: remove "POSTGIS" and "INTERNAL"

/**
* Constructs a CRS object from a string definition using createFromString()
Expand All @@ -237,7 +237,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* - "EPSG:<code>" - handled with createFromOgcWms()
* - "POSTGIS:<srid>" - handled with createFromSrid()
* - "INTERNAL:<srsid>" - handled with createFromSrsId()
* - "PROJ4:<proj4>" - handled with createFromProj()
* - "PROJ:<proj>" - handled with createFromProj()
* - "WKT:<wkt>" - handled with createFromWkt()
*
* If no prefix is specified, WKT definition is assumed.
Expand Down Expand Up @@ -460,7 +460,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* - "EPSG:<code>" - handled with createFromOgcWms()
* - "POSTGIS:<srid>" - handled with createFromSrid()
* - "INTERNAL:<srsid>" - handled with createFromSrsId()
* - "PROJ4:<proj4>" - handled with createFromProj()
* - "PROJ:<proj>" - handled with createFromProj()
* - "WKT:<wkt>" - handled with createFromWkt()
*
* If no prefix is specified, WKT definition is assumed.
Expand Down
13 changes: 13 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -778,6 +778,19 @@ void TestQgsCoordinateReferenceSystem::fromString()
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3111" ) );

crs.createFromString( QStringLiteral( "proj4:+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3111" ) );

crs.createFromString( QStringLiteral( "PROJ4:+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3111" ) );
crs.createFromString( QStringLiteral( "proj:+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3111" ) );
crs.createFromString( QStringLiteral( "PROJ:+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3111" ) );

#if PROJ_VERSION_MAJOR>=6
crs.createFromString( QStringLiteral( "esri:102499" ) );
QVERIFY( crs.isValid() );
Expand Down

0 comments on commit 83eaba9

Please sign in to comment.