1

(Note: This seems to be the same thing that Mohayemin ran into at "GDAL does not recognize EPSG code of a shapefilefile reprojected by ogr2ogr", but the comment there that "GDAL is writing out EPSG:3857 incorrectly" doesn't apply to my case here.)


Is it me, or does gdalsrsinfo know and display the different EPSG codes for an SRS, but a shapefile reprojection using ogr2ogr -t_srs <targetSRS> <dst> <srs> does not write these EPSG codes to the shapefile's .prj file?


I have a shapefile shapes.shp that I presume to be in an EPSG:4647 projection.
gdalsrsinfo shapes.shp gives me

PROJ.4 : '+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500000 +y_0=0
          +ellps=GRS80 +units=m +no_defs '

OGC WKT :
PROJCS["ETRS89_UTM32",
    GEOGCS["GCS_ETRF_1989",
        DATUM["ETRF_1989",
            SPHEROID["GRS80",6378137.0,298.257222101]],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["False_Easting",32500000.0],
    PARAMETER["False_Northing",0.0],
    PARAMETER["Central_Meridian",9.0],
    PARAMETER["Scale_Factor",0.9996],
    PARAMETER["Latitude_Of_Origin",0.0],
    UNIT["Meter",1.0]]

For comparison, gdalsrsinfo EPSG:4647 shows this definition:

PROJ.4 : '+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500000 +y_0=0
          +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs '

OGC WKT :
PROJCS["ETRS89 / UTM zone 32N (zE-N)",
    GEOGCS["ETRS89",
        DATUM["European_Terrestrial_Reference_System_1989",
            SPHEROID["GRS 1980",6378137,298.257222101,
                AUTHORITY["EPSG","7019"]],
            TOWGS84[0,0,0,0,0,0,0],
            AUTHORITY["EPSG","6258"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4258"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",9],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",32500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","4647"]]

So it's basically identical, apart from the AUTHORITY nodes and the TOWGS84[0,0,0,0,0,0,0], right?

But since I'd like to have these AUTHORITY nodes in there to make it easier to identify the projection later, I call ogr2ogr -t_srs EPSG:4647 shapes_4647.shp shapes.shp. This results in (a gazillion warnings about feature fields not being convertible due to type width, which I ignore as spurious, and ...) a new shapefile called shapes_4647.shp, with this projection:

PROJ.4 : '+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500000 +y_0=0
          +ellps=GRS80 +units=m +no_defs '

OGC WKT :
PROJCS["ETRS89_UTM_zone_32N_zE_N",
    GEOGCS["GCS_ETRS_1989",
        DATUM["European_Terrestrial_Reference_System_1989",
            SPHEROID["GRS_1980",6378137,298.257222101]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",9],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",32500000],
    PARAMETER["false_northing",0],
    UNIT["Meter",1]]

Note: no AUTHORITY nodes anywhere.

I thought that including the EPSG codes in the target SRS would be trivial, given that they are obviously on file somewhere...

Should I just manually overwrite shapes_4647.prj with the "official" SRS WKT returned by gdalsrsinfo EPSG:4647?

1

If you want, can you try this command for console

ogr2ogr -t_srs EPSG:32617 sample.shp newsample.shp i'm work this. or if you need a specific area from your shp can you use this ogr2ogr -clipdst xmin ymin xmax ymax bounding.shp mylayer.shp

have you a .tif?

if you have a .tif and you need a .shp can you use gdal_polygonize gdal_polygonize.py sample.tif -f "ESRI Shapefile" mylayer.shp

http://www.gdal.org/ogr2ogr.html http://www.gdal.org/gdal_polygonize.html http://www.gdal.org/pages.html

4
  • Yes, I did RTFM for ogr2ogr, thank you. My question would be: when you perform ogr2ogr -t_srs EPSG:<whatever> on a shapefile that a) can be converted to EPSG:<whatever>, and b) does not itself contain a valid EPSG AUTHORITY node, does your resulting .prj file contain an AUTHORITY node? Dec 29 '16 at 10:18
  • Yes, you can reproject in other EPSG using ogr2ogre -t_srs EPSG:32616 input.shp output.shp and if not have a EPSG, also you can use ogrinfo -ro -so input.shp Dec 29 '16 at 16:00
  • All files in format .shp having a EPSG just reproject or overwrite Dec 29 '16 at 16:03
  • 1
    I'm sorry, but I don't see where your answer answers my question. Did you read it? I know how to reproject, and I know how to read the SRS info of my shape files. The question is: a) why doesn't a reprojected shape file's .prj file automatically contain the relevant EPSG codes? -- and b) what can I do (short of manually editing the .prj file myself) to add these EPSG codes to the .prj file? Are there, say, any secret ogr2ogr parameters to auto-add the EPSG codes during reprojection? Jan 3 '17 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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