Skip to content

Instantly share code, notes, and snippets.

@oscar9
Created March 29, 2017 13:29
Show Gist options
  • Save oscar9/a92ca47eaaa9ce8904a6722db3cd76b6 to your computer and use it in GitHub Desktop.
Save oscar9/a92ca47eaaa9ce8904a6722db3cd76b6 to your computer and use it in GitHub Desktop.
Find crs from a prj file #gvsig
# encoding: utf-8
import gvsig
def main():
crs = esriprj2epsg("D:/Working/test/Huimilpan_Circles_copia.shp")
print crs
def esriprj2epsg(shapeprj_path):
import os
from org.gdal import osr
from java.util import Vector
if os.path.isdir(shapeprj_path):
raise("Should be a file path")
else:
pre, ext = os.path.splitext(shapeprj_path)
new_extension = ".prj"
shapeprj_path = pre + new_extension
#print shapeprj_path
prj_file = open(shapeprj_path, 'r')
prj_txt = prj_file.read()
srs = osr.SpatialReference()
prj_vector = Vector()
prj_vector.add(prj_txt)
srs.ImportFromESRI(prj_vector)
srs.AutoIdentifyEPSG()
epsg = "EPSG:"+srs.GetAuthorityCode(None)
return epsg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment