wiki:ProjectingWktFromStdin

The following script takes in some WKT on stdin, projects it to the coordinate system of your choice, and emits it on stdout. The first argument passed assigns the coordinate system to the WKT, and the second is your output coordinate system.

project_wkt.py EPSG:26915 EPSG:4326 < input.wkt > output.wkt
#!/usr/bin/env python

import sys

from osgeo import ogr, osr

in_ref_text = sys.argv[1]
out_ref_text = sys.argv[2]

g = ogr.CreateGeometryFromWkt(sys.stdin.read())

in_ref = osr.SpatialReference()
in_ref.SetFromUserInput(in_ref_text)

out_ref = osr.SpatialReference()
out_ref.SetFromUserInput(out_ref_text)

g.AssignSpatialReference(in_ref)
g.TransformTo(out_ref)

sys.stdout.write(g.ExportToWkt())
Last modified 14 years ago Last modified on Feb 16, 2010, 8:59:25 AM
Note: See TracWiki for help on using the wiki.