Using OSR, Proj.4,
py-Projection, and
Twisted Python, I made a web service that allows
you to project a coordinate in any projection system to any other projection system. See
the code below for examples on how to use it.
import xmlrpclib
p = xmlrpclib.ServerProxy('http://maps.hobu.net:7080/RPC2')
#Define the projection system in Proj.4
in_proj4 = '+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs '
#Define the input projection system in EPSG
in_epsg = '26915'
#Define the input projection in ESRI WKT
in_esri = """PROJCS["NAD_1983_UTM_Zone_15N",
GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",500000],
PARAMETER["False_Northing",0],
PARAMETER["Central_Meridian",-93],
PARAMETER["Scale_Factor",0.9996],
PARAMETER["Latitude_Of_Origin",0],
UNIT["Meter",1]] “”"
#Define the input projection in OGC WKT
in_wkt = “”"PROJCS["NAD_1983_UTM_Zone_15N",
GEOGCS["GCS_North_American_1983",
DATUM["North_American_Datum_1983",
SPHEROID["GRS_1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",500000],
PARAMETER["False_Northing",0],
PARAMETER["Central_Meridian",-93],
PARAMETER["Scale_Factor",0.9996],
PARAMETER["Latitude_Of_Origin",0],
UNIT["Meter",1]]”"”
#Define the output projection in Proj.4
out_proj4 = “+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ”
#Define the output projection in EPSG
out_epsg = ‘4326′
#Define the output projection in ESRI WKT
out_esri = “”"GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.0174532925199433]] “”"
#Define the output projection in OGC WKT
out_wkt = “”"GEOGCS["WGS 84",DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]”"”
esri_albers = “”"PROJCS["USA_Contiguous_Albers_Equal_Area_Conic_USGS_version",
GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]],
PROJECTION["Albers"],
PARAMETER["False_Easting",0.0],
PARAMETER["False_Northing",0.0],
PARAMETER["Central_Meridian",-96.0],
PARAMETER["Standard_Parallel_1",29.5],
PARAMETER["Standard_Parallel_2",45.5],
PARAMETER["Latitude_Of_Origin",23.0],
UNIT["Meter",1.0]]”"”
#Print the valid projection type strings
print ‘Valid projection type strings: ‘,p.getprojectiontypes()
#Project a point in UTM NAD 83 Zone 15 into Geographic using the
#various methods. This point is located in a corn field.
x = 437142.35
y = 4658582.96
points = [[x, y]]
#Project using Proj.4
print ‘Proj.4 UTM 15 to Proj.4 DD –’,
print p.project(points, in_proj4, out_proj4, ‘proj4′, ‘proj4′)
print ‘Proj.4 UTM 15 to EPSG DD –’,
print p.project(points, in_proj4, out_epsg, ‘proj4′, ‘epsg’)
print ‘Proj.4 UTM 15 to ESRI DD –’,
print p.project(points, in_proj4, out_esri, ‘proj4′, ‘esriwkt’)
print ‘Proj.4 UTM 15 to OGC WKT –’,
print p.project(points, in_proj4, out_wkt, ‘proj4′, ‘wkt’)
#Project using EPSG
print ‘EPSG UTM 15 to Proj.4 DD –’,
print p.project(points, in_epsg, out_proj4, ‘epsg’, ‘proj4′)
print ‘EPSG UTM 15 to EPSG DD –’,
print p.project(points, in_epsg, out_epsg, ‘epsg’, ‘epsg’)
print ‘EPSG UTM 15 to ESRI DD –’,
print p.project(points, in_epsg, out_esri, ‘epsg’, ‘esriwkt’)
print ‘EPSG UTM 15 to OGC WKT DD –’,
print p.project(points, in_epsg, out_wkt, ‘epsg’, ‘wkt’)
#Project using ESRI
print ‘ESRI UTM 15 to Proj.4 DD –’,
print p.project(points, in_esri, out_proj4, ‘esriwkt’, ‘proj4′)
print ‘ESRI UTM 15 to EPSG DD –’,
print p.project(points, in_esri, out_epsg, ‘esriwkt’, ‘epsg’)
print ‘ESRI UTM 15 to ESRI DD –’,
print p.project(points, in_esri, out_esri, ‘esriwkt’, ‘esriwkt’)
print ‘ESRI UTM 15 to OGC WKT DD –’,
print p.project(points, in_esri, out_wkt, ‘esriwkt’, ‘wkt’)
#project using WKT
print ‘OGC WKT UTM 15 to Proj.4 DD –’,
print p.project(points, in_wkt, out_proj4, ‘wkt’, ‘proj4′)
print ‘OGC WKT UTM 15 to EPSG DD –’,
print p.project(points, in_wkt, out_epsg, ‘wkt’, ‘epsg’)
print ‘OGC WKT UTM 15 to ESRI DD –’,
print p.project(points, in_wkt, out_esri, ‘wkt’, ‘esriwkt’)
print ‘OGC WKT UTM 15 to OGC WKT DD –’,
print p.project(points, in_wkt, out_wkt, ‘wkt’, ‘wkt’)
#Project to ESRI Albers
print ‘ESRI UTM 15 to ESRI USGS Albers –’,
print p.project(points, in_esri, esri_albers, ‘esriwkt’, ‘esriwkt’)
print ‘Project array of points’
points = points*10
print p.project(points, in_esri, esri_albers, ‘esriwkt’, ‘esriwkt’)
Output:
Valid projection type strings: [['wkt', 'epsg', 'esriwkt', 'proj4']]
Proj.4 UTM 15 to Proj.4 DD — [[-93.759900978958413, 42.076802903741402]]
Proj.4 UTM 15 to EPSG DD — [[-93.759900978958413, 42.076802903741402]]
Proj.4 UTM 15 to ESRI DD — [[-93.759900978958413, 42.076802903741402]]
Proj.4 UTM 15 to OGC WKT — [[-93.759900978958413, 42.076802903741402]]
EPSG UTM 15 to Proj.4 DD — [[-93.759900978958413, 42.076802903741402]]
EPSG UTM 15 to EPSG DD — [[-93.759900978958413, 42.076802903741402]]
EPSG UTM 15 to ESRI DD — [[-93.759900978958413, 42.076802903741402]]
EPSG UTM 15 to OGC WKT DD — [[-93.759900978958413, 42.076802903741402]]
ESRI UTM 15 to Proj.4 DD — [[-93.759900978958413, 42.076802903741402]]
ESRI UTM 15 to EPSG DD — [[-93.759900978958413, 42.076802903741402]]
ESRI UTM 15 to ESRI DD — [[-93.759900978958413, 42.076802903741402]]
ESRI UTM 15 to OGC WKT DD — [[-93.759900978958413, 42.076802903741402]]
OGC WKT UTM 15 to Proj.4 DD — [[-93.759900978958413, 42.076802903741402]]
OGC WKT UTM 15 to EPSG DD — [[-93.759900978958413, 42.076802903741402]]
OGC WKT UTM 15 to ESRI DD — [[-93.759900978958413, 42.076802903741402]]
OGC WKT UTM 15 to OGC WKT DD — [[-93.759900978958413, 42.076802903741402]]
ESRI UTM 15 to ESRI USGS Albers — [[184064.98645664263, 2121672.8254685458]]
Project array of points
[[184064.98645664263, 2121672.8254685458], [184064.98645664263, 2121672.82546854
58], [184064.98645664263, 2121672.8254685458], [184064.98645664263, 2121672.8254
685458], [184064.98645664263, 2121672.8254685458], [184064.98645664263, 2121672.
8254685458], [184064.98645664263, 2121672.8254685458], [184064.98645664263, 2121
672.8254685458], [184064.98645664263, 2121672.8254685458], [184064.98645664263,
2121672.8254685458]]