3

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

2 Answers 2

4

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)'
3

I'm not sure why the order matters to you but the shapely manual shows wrapping the MultiPoint in a list:

pprint.pprint(list(points.geoms))

so I would expect something like:

points = MultiPoint(list(points.geoms)[::-1]) 

to work. Though the manual makes no claims that MultiPoints honour the order of the input list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.