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?
3 Answers
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 <shapefile>.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.
-
This works also with a geo-referenced raster file, such as TIFF: gdalsrsinfo filename.tif Commented Jan 13, 2020 at 12:34
The gdal app gdalsrsinfo produces many different representations of an srs:
kyle@kyle-hp-desktop:~$ gdalsrsinfo epsg:4326 -o all
PROJ.4 : '+proj=longlat +datum=WGS84 +no_defs '
OGC WKT :
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
OGC WKT (simple) :
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]]
OGC WKT (no CT) :
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]]
ESRI WKT :
GEOGCS["GCS_WGS_1984",
DATUM["D_WGS_1984",
SPHEROID["WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]]
...
You can input proj.4 strings, wkt strings or epsg codes. Since gdal 1.9 (I think).
I've always used grep
to grab this information:
ogrinfo -so <shapefile>.shp | grep -e "ESPG"
-
-
3
-
-
1I don't think this actually works, on none of the platforms, as
gdalinfo
does not read shape files. And if you meantgdalsrsinfo
, that does not always return an EPSG code in its output.– j08lueCommented Sep 15, 2016 at 11:22 -