Thursday, 28 July 2016

gdal - How can I get the proj4 string or EPSG code from a shapefile .prj file?



I have to work with a shapefile defined in an unusual projection, which my GIS software does not know about. How can I get the proj4 definition or the EPSG code for the projection?




Answer



The shapefile should have a .prj file which defines the projection. You can use it together with one of the following 3 options to get either the proj4 string, WKT definition or EPSG code.


To get proj4 definition:


If you have gdal installed on your system, you can use the gdalsrsinfo command line application to get the proj4 definition as the OGC WKT definition:


$ gdalsrsinfo .prj

Exampe:


$ gdalsrsinfo 7490.prj 

PROJ.4 : '+proj=aea +lat_1=-18 +lat_2=-32 +lat_0=0 +lon_0=24 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs '


OGC WKT :
PROJCS["Albers_Equal_Area_Conic_South_Africa",
GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]],
PROJECTION["Albers_Conic_Equal_Area"],
PARAMETER["False_Easting",0],

PARAMETER["False_Northing",0],
PARAMETER["longitude_of_center",24],
PARAMETER["Standard_Parallel_1",-18],
PARAMETER["Standard_Parallel_2",-32],
PARAMETER["latitude_of_center",0],
UNIT["Meter",1]]

To get EPSG number:


You can use the prj2epsg.org service to upload the .prj file and get a list of matching EPSG codes. Warning: prj2epsg.org returns the list of codes which match best. It may be that none of them are correct.


Using python:



If you are comfortable with Python, you can use the very useful script at Shapefile PRJ to PostGIS SRID lookup table? to get the WKT, proj4 string and EPSG code.


See also:


You can find definitions for most standard projections at spatialreference.org.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...