1

I have a tif image containing its CRS. I would like to extract the parameter "central_meridian". I have the following piece of code:

from osgeo import gdal,osr
ds=gdal.Open(r'hrs0000bf5c_07_if177l_trr3_CAT_scale_trial_p.img.tif')
prj=ds.GetProjection()
print prj

srs=osr.SpatialReference(wkt=prj)
print srs.GetAttrValue('PARAMETER',0)
print srs.GetAttrValue('PARAMETER',1)

The output I get is the following:

    PROJCS["Mars_Npolar_Stereo",GEOGCS["GCS_Unknown",DATUM["Unknown",SPHEROID["S_Unknown",3396190,169.8944472236118]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Polar_Stereographic"],PARAMETER["latitude_of_origin",90],PARAMETER["central_meridian",160.0712280273438],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]

latitude_of_origin
90

I would like to fetch the second parameter "central_meridian" but i don't know how to do it? Any ideas?

##EDIT

If trying to open a list of files given by a list like:

from osgeo import gdal,osr from gdalconst import GA_ReadOnly

f = open('list.txt')
for line in iter(f):
    print line
    ds=gdal.Open(line,GA_ReadOnly)
    prj=ds.GetProjection()
    srs=osr.SpatialReference(wkt=prj)
    print line + " " + srs.GetProjParm( osr.SRS_PP_CENTRAL_MERIDIAN)
f.close()

I get the following error: ERROR 4: `frt0000703c_07_if187l_trr3_CAT_scale_trial_p.img.tif ' does not exist in the file system, and is not recognised as a supported dataset name.

I tried different ways to do it and went through documentation but no luck. Any ideas why it does not recognizes it as a filename?

2

You could use the OGRSpatialReference::GetProjParm to obtain the central meridian value as described in the GDAL tutorial for Querying Coordinate System:

srs.GetProjParm( osr.SRS_PP_CENTRAL_MERIDIAN)

So you could use:

from osgeo import gdal,osr
ds = gdal.Open(r'hrs0000bf5c_07_if177l_trr3_CAT_scale_trial_p.img.tif')
prj = ds.GetProjection()

srs = osr.SpatialReference(wkt=prj)
srs.GetProjParm( osr.SRS_PP_CENTRAL_MERIDIAN)
  • @ramayer - Most welcome, glad it worked =) – Joseph Oct 18 '16 at 12:25
  • I know it might sound super silly the question but I am trying to do this iterative given a list of files like this: – ramayer Oct 18 '16 at 12:30
  • @ramayer - I would probably suggest asking this as a new question. Perhaps you need to specify the full paths in your .txt file? – Joseph Oct 18 '16 at 12:50
  • indeed. filePath="/storage/esp-data/data/data/MARS/MRO/CRISM/TRDR/mrocr_2102/processed_mrocr_2102/tif/" + line ds=gdal.Open(filePath.strip()) – ramayer Oct 18 '16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.