How to extract individual points from the shapely Multipoint data type?
Question:
I am using shapely2.0; somehow, I can’t iterate through individual points in the MULTIPOINT data type in this version.
I wanted to extract and plot individual points from the MULTIPOINT.
The MULTIPOINT is obtained from line.intersection(circle_boundary)
, where I tried to get the intersection points between line and circle geometry.
Is there any way to access the Individual points in the MULTIPOINT or get the intersecting points as individual shapely Points rather than as MULTIPOINT?
Answers:
MultiPoint geometry object can be exploded
to become basic Point objects.
import os
os.environ['USE_PYGEOS'] = '0'
import geopandas as gpd
from shapely.geometry import MultiPoint
s = gpd.GeoSeries(
[MultiPoint([(0, 0), (1, 1)]),
MultiPoint([(2, 2), (3, 3), (4, 4)])]
)
# Create a new geodataframe of individual points
exploded_s = s.explode(index_parts=True)
exploded_s
0 0 POINT (0.00000 0.00000)
1 POINT (1.00000 1.00000)
1 0 POINT (2.00000 2.00000)
1 POINT (3.00000 3.00000)
2 POINT (4.00000 4.00000)
dtype: geometry
I am using shapely2.0; somehow, I can’t iterate through individual points in the MULTIPOINT data type in this version.
I wanted to extract and plot individual points from the MULTIPOINT.
The MULTIPOINT is obtained from line.intersection(circle_boundary)
, where I tried to get the intersection points between line and circle geometry.
Is there any way to access the Individual points in the MULTIPOINT or get the intersecting points as individual shapely Points rather than as MULTIPOINT?
MultiPoint geometry object can be exploded
to become basic Point objects.
import os
os.environ['USE_PYGEOS'] = '0'
import geopandas as gpd
from shapely.geometry import MultiPoint
s = gpd.GeoSeries(
[MultiPoint([(0, 0), (1, 1)]),
MultiPoint([(2, 2), (3, 3), (4, 4)])]
)
# Create a new geodataframe of individual points
exploded_s = s.explode(index_parts=True)
exploded_s
0 0 POINT (0.00000 0.00000) 1 POINT (1.00000 1.00000) 1 0 POINT (2.00000 2.00000) 1 POINT (3.00000 3.00000) 2 POINT (4.00000 4.00000) dtype: geometry