Skip to content

Best way to modify coordinates and add points to MultiPoint object #1793

Answered by mwtoews
fuhrmanj asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a quick ipython demo:

In [1]: from shapely.geometry import MultiPoint

In [2]: mp = MultiPoint([(1, 2), (3, 4)])

In [3]: mp
Out[3]: <MULTIPOINT (1 2, 3 4)>

In [4]: mp_list = list(mp.geoms)  # convert to mutable list of Point objects

In [5]: mp_list
Out[5]: [<POINT (1 2)>, <POINT (3 4)>]

In [6]: mp_list.append((5, 6))  # add additional point

In [7]: mp_list[1] = (7, 8)  # modify existing point in second index position

In [8]: mp_list  # this is now a mixed Point and tuple list, which should be fine
Out[8]: [<POINT (1 2)>, (7, 8), (5, 6)]

In [9]: MultiPoint(mp_list) # voila
Out[9]: <MULTIPOINT (1 2, 7 8, 5 6)>

This demo should work the same for Shapely 2 or earlier, although t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fuhrmanj
Comment options

Answer selected by fuhrmanj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants