18

This question already has an answer here:

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?

marked as duplicate by Devdatta Tengshe, whuber Jun 26 '13 at 3:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

26

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.

4

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).

3

I've always used grep to grab this information:

ogrinfo -so <shapefile>.shp | grep -e "ESPG"
  • only possible in linux :) – Curlew Mar 22 '13 at 15:05
  • 3
    and Mac OS X :) – ShaunLangley Mar 22 '13 at 15:31
  • and Windows, using MobaXterm ;-) – Michi Jul 3 '15 at 16:53
  • 1
    I don't think this actually works, on none of the platforms, as gdalinfo does not read shape files. And if you meant gdalsrsinfo, that does not always return an EPSG code in its output. – j08lue Sep 15 '16 at 11:22
  • @j08lue: they probably meant ogrinfo (edited). – Christian Severin Dec 20 '16 at 10:58

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