Skip to content
Permalink
Browse files

[processing] Fix conversion of ESRI CRS when running GDAL algorithms …

…under proj 6

Fixes #35123
  • Loading branch information
nyalldawson committed Mar 17, 2020
1 parent ccbe6b9 commit 8b54d2f06c2ded9c93b4c6e18afaca30f7051590
@@ -41,7 +41,9 @@
QgsMessageLog,
QgsSettings,
QgsCredentials,
QgsDataSourceUri)
QgsDataSourceUri,
QgsProjUtils,
QgsCoordinateReferenceSystem)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.system import isWindows, isMac

@@ -432,8 +434,12 @@ def gdal_crs_string(crs):
:param crs: crs to convert
:return: gdal friendly string
"""
if crs.authid().upper().startswith('EPSG:'):
if crs.authid().upper().startswith('EPSG:') or crs.authid().upper().startswith('IGNF:') or crs.authid().upper().startswith('ESRI:'):
return crs.authid()

if QgsProjUtils.projVersionMajor() >= 6:
# use WKT
return crs.toWkt(QgsCoordinateReferenceSystem.WKT2_2018)

# fallback to proj4 string, stripping out newline characters
return crs.toProj().replace('\n', ' ').replace('\r', ' ')
@@ -36,6 +36,7 @@
QgsProject,
QgsVectorLayer,
QgsRectangle,
QgsProjUtils,
QgsProcessingException,
QgsProcessingFeatureSourceDefinition)

@@ -318,15 +319,22 @@ def testCrsConversion(self):
crs.createFromProj(
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')
self.assertTrue(crs.isValid())
self.assertEqual(GdalUtils.gdal_crs_string(crs),
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')
# check that newlines are stripped
crs = QgsCoordinateReferenceSystem()
crs.createFromProj(
'+proj=utm +zone=36 +south\n +a=600000 +b=70000 \r\n +towgs84=-143,-90,-294,0,0,0,0 +units=m\n+no_defs')
self.assertTrue(crs.isValid())
self.assertEqual(GdalUtils.gdal_crs_string(crs),
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')

if QgsProjUtils.projVersionMajor() >= 6:
# proj 6, WKT should be used
self.assertEqual(GdalUtils.gdal_crs_string(crs)[:40], 'BOUNDCRS[SOURCECRS[PROJCRS["unknown",BAS')

self.assertEqual(GdalUtils.gdal_crs_string(QgsCoordinateReferenceSystem('ESRI:102003')), 'ESRI:102003')
else:
self.assertEqual(GdalUtils.gdal_crs_string(crs),
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')
# check that newlines are stripped
crs = QgsCoordinateReferenceSystem()
crs.createFromProj(
'+proj=utm +zone=36 +south\n +a=600000 +b=70000 \r\n +towgs84=-143,-90,-294,0,0,0,0 +units=m\n+no_defs')
self.assertTrue(crs.isValid())
self.assertEqual(GdalUtils.gdal_crs_string(crs),
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')


if __name__ == '__main__':

0 comments on commit 8b54d2f

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