Read srid of shapefile

Python -- Posted on Sept. 4, 2018

Read srid of a shapefile

              
                from osgeo import ogr, osr
shapefile = ogr.Open("shapefile.shp")
prj = ogr.Open("shapefile.prj")
layer = shapefile.GetLayer(0)
crs = layer.GetSpatialRef()
prj_file = open("shapefile.prj", 'r')
prj_txt = prj_file.read()
srs = osr.SpatialReference()
srs.ImportFromESRI([prj_txt])
print('Shape prj is: %s' % prj_txt)
print('WKT is: %s' % srs.ExportToWkt())
print('Proj4 is: %s' % srs.ExportToProj4())
srs.AutoIdentifyEPSG()
print('EPSG is: %s' % srs.GetAuthorityCode(None))
                  
   
            

Related Posts