Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix gdaltools getRasterSRS() and use gdalsrsinfo with gdal >= 1.9
  • Loading branch information
etiennesky committed Jan 29, 2014
1 parent 7456eb7 commit d63104a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/plugins/GdalTools/tools/GdalTools_utils.py
Expand Up @@ -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())
Expand All @@ -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))
Expand Down

2 comments on commit d63104a

@rouault
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.