[Gdal-dev] python - get projection from a file
Matthew Perry
perrygeo at gmail.com
Mon Mar 6 15:11:21 EST 2006
Brent,
Once you open the dataset, you have to get the layer then the spatial
reference for the layer. From there you can export the spatial
reference to a variety of formats as needed (the "exportTo*" methods
at http://gdal.maptools.org/ogr/classOGRSpatialReference.html)
>>> import ogr
>>> ds = ogr.Open('ca_counties.shp')
>>> layer = ds.GetLayer()
>>> sr = layer.GetSpatialRef()
>>> sr
<osr.SpatialReference instance at 0xb7b5510c>
>>> sr.ExportToProj4()
'+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997
+units=m +no_defs '
>>> sr.ExportToWkt()
'PROJCS["US National Atlas Equal Area",GEOGCS["Unspecified datum based
upon the GRS 1980 Authalic
Sphere",DATUM["Not_specified_based_on_GRS_1980_Authalic_Sphere",SPHEROID["GRS_1980_Authalic_Sphere",6370997,0]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["latitude_of_center",45],PARAMETER["longitude_of_center",-100],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]'
- matt
On 3/6/06, Brent Pedersen <bpederse at gmail.com> wrote:
> hi, i'd like to be able to have a user upload a file (.shapefile for now). i
> want to then use python/gdal to get the projection information associated
> with that file. where do i start?
>
> i have ogr.Open(filename) and the simple stuff like that, but how do i get
> the projection? i am having trouble seeing how ogr fits in with stuff like
> osr.SpatialReference.ImportFromESRI ...
>
> thanks for any pointers,
> -brent
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
>
>
--
Matt Perry
perrygeo at gmail.com
http://www.perrygeo.net
More information about the Gdal-dev
mailing list