[GIS] Convert list of coordinates to OGRGeometry or WKT

gdalogrpython

I am using a Visvalingam-Whyatt simplification script and the output is a list of coordinates such:

[[[[-10885205.10690245   3525662.26531131]
   [-10885369.01690829   3525374.0741439 ]
   [-10885424.08206484   3525269.35422813]
   [-10885439.88685361   3525278.66051977]
   [-10885600.07792469   3525092.02164548]
   [-10885623.88512575   3525100.58301066]
   [-10885627.28152936   3525101.52167386]
   [-10885630.67801411   3525102.45679679]]]]

I would like to create OGRGeometry object from that list. Is there any function that can do that?

Edit: A simple WKT would be correct.

Best Answer

do you mean a line geometry?

something like:

    import numpy as np
    from osgeo import ogr

    v=np.array([[[[-10885205.10690245,3525662.26531131],
       [-10885369.01690829,3525374.0741439],
       [-10885424.08206484,3525269.35422813],
       [-10885439.88685361,3525278.66051977],
       [-10885600.07792469,3525092.02164548],
       [-10885623.88512575,3525100.58301066],
       [-10885627.28152936,3525101.52167386],
       [-10885630.67801411,3525102.45679679]]]])
    line=ogr.Geometry(ogr.wkbLineString)
    for i in v[0,0,:]:
        line.AddPoint(i[0],i[1])
    print line.ExportToWkt()

or other examples of working with geometry

depending on the use of the geometry, you might need to use ogr.wkbLineString25D.