#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Urllib.request
Import OS
def get_epsg_code (EPSG):
"""
Get the ESRI formatted. PRJ definition
Usage Get_epsg_code (4326)
We Use the http://spatialreference.org/ref/epsg/4326/esriwkt/
"""
F=urllib.request.urlopen ("http://spatialreference.org/ref/epsg/{0}/esriwkt/". Format (EPSG))
Return (F.read ())
# Shapefile filename must equal the new PRJ filename
Shp_filename = "Utm_zone_boundaries"
# path to where Shapefiles with No. prj is located
Os.chdir (".. /geodata/")
# Here we write out a new. prj file with the same name
# as our shapefiles named "Schools" in this example
With open ("%s.prj"% Shp_filename, "WB") as PRJ:
Epsg_code = Get_epsg_code (4326)
Print (Epsg_code)
Prj.write (Epsg_code)
Print ("Done writing projection definition" + prj.name + "to EPSG:" + str (epsg_code))
# now change abck to our code directory
Os.chdir (".. /code/")
Defining projections for SHP files