Skip to content
Permalink
Browse files

fix gdaltools getRasterSRS() and use gdalsrsinfo with gdal >= 1.9

  • Loading branch information
etiennesky committed Jan 29, 2014
1 parent 7456eb7 commit d63104ae50dcd45ddf50dfe31ea6803530a64b26
Showing with 5 additions and 2 deletions.
  1. +5 −2 python/plugins/GdalTools/tools/GdalTools_utils.py
@@ -288,7 +288,10 @@ def getVectorFields(vectorFile):
# get raster SRS if possible
def getRasterSRS( parent, fileName ):
processSRS = QProcess( parent )
processSRS.start( "gdalinfo", [fileName], QIODevice.ReadOnly )
if ( GdalConfig.versionNum() >= 1900 ):
processSRS.start( "gdalsrsinfo", ["-o", "wkt", "-p", fileName], QIODevice.ReadOnly )
else:
processSRS.start( "gdalinfo", [fileName], QIODevice.ReadOnly )
arr = ''
if processSRS.waitForFinished():
arr = str(processSRS.readAllStandardOutput())
@@ -301,7 +304,7 @@ def getRasterSRS( parent, fileName ):
if len(info) == 0:
return ''

for elem in info:
for elem in reversed(info):
m = re.match("^\s*AUTHORITY\[\"([a-z]*[A-Z]*)\",\"(\d*)\"\]", elem)
if m and len(m.groups()) == 2:
return '%s:%s' % (m.group(1), m.group(2))

2 comments on commit d63104a

@rouault

This comment has been minimized.

Copy link
Contributor

@rouault rouault replied Jan 29, 2014

Just an outsider point of view : why using GDAL utilties and risky output parsing to get the SRS and not just plain Python GDAL API...

ds = gdal.Open(the_raster)
ds.GetProjectionRef()

@etiennesky

This comment has been minimized.

Copy link
Contributor Author

@etiennesky etiennesky replied Jan 30, 2014

I agree - GdalTools uses the commandline tools instead of the python API in many places.
I made a quick fix, probably should have gone your way.

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