Changes between Initial Version and Version 1 of ProjectingWktFromStdin


Ignore:
Timestamp:
Feb 16, 2010, 8:59:25 AM (14 years ago)
Author:
hobu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ProjectingWktFromStdin

    v1 v1  
     1{{{
     2#!rst
     3
     4The 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.
     5
     6::
     7
     8  project_wkt.py EPSG:26915 EPSG:4326 < input.wkt > output.wkt
     9
     10
     11.. code-block:: python
     12
     13    #!/usr/bin/env python
     14
     15    import sys
     16
     17    from osgeo import ogr, osr
     18
     19    in_ref_text = sys.argv[1]
     20    out_ref_text = sys.argv[2]
     21
     22    g = ogr.CreateGeometryFromWkt(sys.stdin.read())
     23
     24    in_ref = osr.SpatialReference()
     25    in_ref.SetFromUserInput(in_ref_text)
     26
     27    out_ref = osr.SpatialReference()
     28    out_ref.SetFromUserInput(out_ref_text)
     29
     30    g.AssignSpatialReference(in_ref)
     31    g.TransformTo(out_ref)
     32
     33    sys.stdout.write(g.ExportToWkt())
     34
     35}}}