I need to convert a MULTIPOINT string to a list of POINT objects. For example, suppose I have a query with ST_AsText() producing an output that is captured in my_points:

result={str}'MULTIPOINT(-1.0 1.2, 3.4 5.6, 7.8 9.0)'

I need result to be converted to a list of POINT objects so that I can use STRtree() to query if the points intersect a polygon.

I have tried the following:

[x.split(' ') for x in result[11:-1].split(',')]

but it only returns a list of strings:

(['-1.0', '1.2'], ['3.4', '4.5']...)

I need each element in each list to be floats so that I can convert them to Points.

What is the most efficient way to convert the MULTIPOINT string to an actual list of Points?

I am a novice to GIS and Python, not to programming in general.


Assuming my_points is a Multipoint object, you can iterate over each individual point of the multipoint as you can iterate over a list and access each point's geometry. The following line will create a list of tuples, one for each point with their respective x and y coordinates.

individual_points = [(pt.x, pt.y) for pt in my_points]
print(individual_points)  # [(-1.0, 1.2), (3.4, 5.6), (7.8, 9.0)]

For more information see the Collections Shapely documentation

  • The dilemma stems from the fact that my_points is not a MultiPoint object, but a string; however, your response did point me in the right direction to resolve the issue: [Point(x.split(' ')[0], x.split(' ')[1]) for x in result[11:-1].split(',')] – CNIDog Jun 4 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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