================== wkt2proj.py =======================
#!/usr/bin/env python
import os
import sys
import string
import osgeo.osr
if (len(sys.argv) <> 2):
print 'Usage: wkt2proj.py [WKT Projection Text]'
else:
srs = osgeo.osr.SpatialReference()
srs.ImportFromWkt(sys.argv[1])
print srs.ExportToProj4()
======================================================
================== proj2wkt.py =======================
#!/usr/bin/env python
import os
import sys
import string
import osgeo.osr
if (len(sys.argv) <> 2):
print 'Usage: proj2wkt.py [Proj4 Projection Text]'
else:
srs = osgeo.osr.SpatialReference()
srs.ImportFromProj4(sys.argv[1])
print srs.ExportToWkt()
======================================================
On Ubuntu, provided you have the python-gdal package installed, the above files executed by python will accept the first argument as a wkt/proj projection string, and return the proj/wkt equivalent. For proj2wkt.py, you can also take advantage of known EPSG numbers. For example, the WKT for the Spherical Mercator projection used by most free online mapping services (e.g., Google Maps, OpenStreetMap, etc) will be returned by: proj2wkt.py '+init=epsg:3857'
I haven't tested this on Windows - but as long as the Proj library is installed and the GDAL Python modules are installed and accessible to the Python environment, I imagine they will work the same.
No comments:
Post a Comment