I'm looking for the correct method using GDAL (most recent trunk on Ubuntu) or its Python API to get the correct EPSG code for a given prj file WITHOUT relying on the prj2epsg webservice or any external webservice. To clarify, the solution needs to work on PRJ files that do NOT include the EPSG code within the definiton (which is, in my experience, nearly every shapefile out there) such as this one:


I'm connecting to these files using ogr_fdw in Postgres10/Postgis2.4. If there were some way to use ogr_fdw WITHOUT knowing the specific EPSG code for a given shapefile, I would accept that as an answer as well. I don't necessary need to know the source coordinate system -I'm just looking to transform to WGS84 when working with the data in postgis.

  • You could try the osr.SpatialReference AutoIdentifyEPSG() method, i.e gis.stackexchange.com/a/7615/2856
    – user2856
    Aug 18, 2017 at 1:59
  • 1
    Tested that, doesn't work unless the code is embedded in the prjfile
    – THX1138
    Aug 18, 2017 at 2:02
  • And this is why we ask that you tell us what you have tried already in your question...
    – user2856
    Aug 18, 2017 at 2:04
  • Did you find an answer to your problem? I'm in the same situation. thanks Apr 30, 2020 at 11:34

2 Answers 2


If you use GDAL there is no need to know the EPSG code of the coordinate system. Translation from the WKT contents of .prj file goes directly into Proj4 parameters without using EPSG codes in between. With your example you could (in theory, read further to see why it does not work) just have your .prj file available and run ogr2ogr as

ogr2ogr -f [your_outputformat] -s_srs your_prj_file.prj -t_srs epsg:4326 output_dataset input_dataset

You can test the conversion with gdaltransform utility http://www.gdal.org/gdaltransform.html. However, with your example the tool throws an error:

gdaltransform -t_srs epsg:4326 -s_srs unknown.prj
ERROR 6: No translation for Lambert_Conformal_Conic to PROJ.4 format is known.

I do not know projections well enough to say anything about Lambert_Conformal_Conic and why it is unknown to Proj4, but if I edit .prj to use Lambert_Conformal_Conic_SP2 instead I can use gdaltransform

gdaltransform -t_srs epsg:4326 -s_srs unknown.prj
2668812 10416336
-99.1422367719884 31.2389668371 0

If you are using ogr_fdw, you can change the foreign table geometry definition.

I have this documented in http://postgis.us/presentations/FOSS4G2017_PostGISSpatialTricks.html#/1/12

Repeated here:

ALTER FOREIGN TABLE shps.towns_polym 
ALTER COLUMN geom type geometry(geometry,26986);

Where in this case, ogr_fdw brought the table srid wrong as 4269 instead of what it should be 26986 (MA State plane feet).

Also if you have a mix of polygons/multipolygons you should change the type to something like geometry to handle both cases as shown above.

  • But what tool do you use to programatically determine the correct projection without resorting to using prj2epsg? That's the issue I'm having. I know I can change the geometry definition -but need a way to determime the correct srid without resorting to manual lookups.
    – THX1138
    Aug 18, 2017 at 5:45
  • Okay misunderstood your question. Do you know a possible set of proj? Normally ogr_fdw will get the DATUM at least right though it screws up on the units if it's not wgs 84.
    – Regina Obe
    Aug 18, 2017 at 6:13
  • I don't really have a specific set, I deal with data that is spread out across local jurisdictions in the US. I only need to transform the data TO WGS84 though -I don't need to keep the source projections in the fdw tables if that simplifies anything.
    – THX1138
    Aug 18, 2017 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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