Dimitris Kougioumtzis Blog About technology

Read srid of shapefile

Category Python

Posted on Sept. 4, 2018



Read srid of a shapefile


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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))

About

My name is Dimitris Kougioumtzis and i work as a Web developer at Rapidbounce Company

Elsewhere