[GIS] Setting Config Options for GDAL using Python

configurationgdalgeotiff-tiffosgeopython

I am attempting to invoke the "SetConfigOption" function using the GDAL API to tweak GDAL's default settings to get additional information about GeoTiff. I am specifying the Config Options below in conjunction with the 'gdalinfo' command to retrieve information about the vertical coordinate reference system (VERTCRS). Running 'gdalinfo' on the GeoTiff as it is does not show the VERTCRS information, but the VERTCRS info. can obtained from the command line by typing/entering these Config Option commands individually before calling 'gdalinfo' on the GeoTiff.

Is there a way to use the "subprocess" function to seamlessly get the VERTCRS information?

Below is the code I am using, which prints the 'gdalinfo' output but does not capture the VERTCRS information as needed.

from osgeo import gdal, osr, ogr
import subprocess

gdal.SetConfigOption('GTIFF_REPORT_COMPD_CS','TRUE')
gdal.SetConfigOption('DTED_APPLY_PIXEL_IS_POINT', 'TRUE')
gdal.SetConfigOption('GTIFF_POINT_GEO_IGNORE', 'TRUE')
gdal.SetConfigOption('REPORT_COMPD_CS','TRUE')

cmd='gdalinfo C:\\users\\mikel\\GeoData\\DSM.tif'
print(subprocess.check_output(cmd))

Best Answer

Use the API rather than starting up a subprocess:

gdal.SetConfigOption('GTIFF_REPORT_COMPD_CS', 'YES')
print(gdal.Info(r'C:\users\mikel\GeoData\DSM.tif'))

Works for me with my data.