Find srid of a shapefile in python 3

Python -- Posted on Dec. 23, 2018

Find srid of shapefile in python 3

              
                import urllib.parse
import urllib.request
import json
from osgeo import ogr, osr

prj_file = open('file.prj', 'r')
prj_txt = prj_file.read()
prj_file.close()

query = {
    'exact': True,
    'error': True,
    'mode': 'wkt',
    'terms': prj_txt}
webres = 'http://prj2epsg.org/search.json'
data = urllib.parse.urlencode(query).encode("utf-8")
req = urllib.request.Request(webres)
with urllib.request.urlopen(req, data=data) as f:
    jres = json.loads(f.read())
    if jres['codes']:
        srid = int(jres['codes'][0]['code'])
        print(srid)
                  
   
            

Related Posts