如何从Shapely的Multipoint数据类型中提取单个点?

huangapple go评论64阅读模式
英文:

How to extract individual points from the shapely Multipoint data type?

问题

I am using shapely2.0; somehow, I can't iterate through individual points in the MULTIPOINT data type in this version.

我正在使用shapely 2.0;不知何故,在这个版本中,我无法遍历MULTIPOINT数据类型中的各个点。

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.

我想从MULTIPOINT中提取并绘制各个点。MULTIPOINT是从line.intersection(circle_boundary)获得的,我尝试获取线段和圆形几何体之间的交点。

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中的各个点,或者将交点作为单独的shapely Points而不是MULTIPOINT来获取?

英文:

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?

答案1

得分: 1

多点几何对象可以被“分解”为基本的点对象。

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)])]
)

# 创建一个新的地理数据框包含单个点
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
英文:

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

<pre>
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
</pre>

huangapple
  • 本文由 发表于 2023年4月1日 00:17:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定