[gdal-dev] Get specific parameter in CRS information with Python gdal

Even Rouault even.rouault at spatialys.com
Tue Oct 18 06:19:06 PDT 2016


Le mardi 18 octobre 2016 11:38:08, Ramiro Marco Figuera a écrit :
> Hi,
> 
> 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["s
> cale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],
> UNIT["metre",1,AUTHORITY["EPSG","9001"]]]
> 
> latitude_of_origin 90
> 
> The code is fetching the first parameter: latitude_of_origin 90 but i
> would like to get the second one "central_meridian" but i don't know how
> to do it? Any ideas?

Relevant extract from 
https://svn.osgeo.org/gdal/trunk/autotest/osr/osr_basic.py


    parm_list = \
              [ (osr.SRS_PP_CENTRAL_MERIDIAN, -117.0),
                (osr.SRS_PP_LATITUDE_OF_ORIGIN, 0.0),
                (osr.SRS_PP_SCALE_FACTOR, 0.9996),
                (osr.SRS_PP_FALSE_EASTING, 500000.0),
                (osr.SRS_PP_FALSE_NORTHING, 0.0) ]

    for parm in parm_list:
        value = utm_srs.GetProjParm( parm[0], -1111 )
        if abs(value-parm[1]) > .00000000000010:
            gdaltest.post_reason( 'got %g for %s instead of %g.' \
                                  % (value, parm[0], parm[1] ) )
            return 'fail'




> 
> Thanks a lot.

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list