Python – How to Reverse Coordinates of MultiPoint Using Shapely

coordinatespythonshapely

How to reverse the cooridnates order of this MultiPoint:

MULTIPOINT (92 169, 100 163.552380952381, 105.2167832167832 160, 266.7552447552447 50, 290 34.17142857142857, 302 26)

to this:

 MULTIPOINT (302 26, 290 34.17142857142857, 266.7552447552447 50,  105.2167832167832 160, 100 163.552380952381, 92 169)

I tried this and getting an error:

intPoints.coords[::-1])

NotImplementedError: Multi-part geometries do not provide a coordinate sequence

Best Answer

Your example is a MULTIPOINT.

Members of a multi-point collection are accessed via the geoms property or via the iterator protocol using in or list().

Here's an example:

>> from shapely import wkt
>> from shapely.geometry import MultiPoint

>> p = wkt.loads("MULTIPOINT (92 169, 100 163.552380952381, 105.2167832167832 160, 266.7552447552447 50, 290 34.17142857142857, 302 26)")

>> list(p)
   [<shapely.geometry.point.Point at 0x2...>,
    <shapely.geometry.point.Point at 0x2...>,
    <shapely.geometry.point.Point at 0x2...>,
    <shapely.geometry.point.Point at 0x2...>,
    <shapely.geometry.point.Point at 0x2...>,
    <shapely.geometry.point.Point at 0x2...>]
>> inverted_mp = MultiPoint(list[::-1])
>> inverted_mp.wtk
   'MULTIPOINT (302 26, 290 34.17142857142857, 266.7552447552447 50, 105.2167832167832 160, 100 163.552380952381, 92 169)'