仅在形状几何熊猫回复中获取值

问题描述 投票:0回答:1

我有一个包含地理数据的大型数据集。我只想提取与城市部分有关的数据。因此,我需要创建一个形状并检查我的点是否存在。

我尝试使用this answer

要点

1)

turin.head() = 

       latitude     longitude   
    0   44.9125     7.7432  
    21  45.0764     7.5249  
    22  45.0764     7.5249  
    23  45.0755     7.5248 
    24  45.0718     7.5236 

2)

geometry = [Point(xy) for xy in zip(turin.longitude,turin.latitude)]
turin_point = gpd.GeoDataFrame(turin,crs=crs,geometry=geometry)
turin_point.head()


    latitude    longitude   geometry
0   44.9125     7.7432  POINT (7.74320 44.91250)
21  45.0764     7.5249  POINT (7.52490 45.07640)
22  45.0764     7.5249  POINT (7.52490 45.07640)
23  45.0755     7.5248  POINT (7.52480 45.07550)
24  45.0718     7.5236  POINT (7.52360 45.07180)

BORDERS

1)

border.head()

    longitude   latitude    
0   7.577835    45.041828   
1   7.579849    45.039877   
2   7.580106    45.039628   
3   7.580852    45.038576   
4   7.580866    45.038556   

2)

geometry2 = [Point(xy) for xy in zip(border.longitude,border.latitude)]
border_point = gpd.GeoDataFrame(border,crs=crs,geometry=geometry2)
border_point.head() = 

        longitude   latitude    geometry
    0   7.577835    45.041828   POINT (7.57783 45.04183)
    1   7.579849    45.039877   POINT (7.57985 45.03988)
    2   7.580106    45.039628   POINT (7.58011 45.03963)
    3   7.580852    45.038576   POINT (7.58085 45.03858)
    4   7.580866    45.038556   POINT (7.58087 45.03856)

然后根据reply

turin_final= border_point.geometry.unary_union
within_turin = turin_point[turin_point.geometry.within(turin_final)]

IndexError:数组的索引过多

python pandas geopandas shapely
1个回答
0
投票

如果要在边界内查找点,则边界本身必须是多边形,而不是另一组点。如果边界点的坐标顺序正确,则可以尝试将以下两行替换为这些行:

from shapely.geometry import Polygon

turin_final = Polygon([[p.x, p.y] for p in border_point.geometry])
within_turin = turin_point[turin_point.geometry.within(turin_final)]

通常不是这种情况,但是据您的评论所知,它已经解决了您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.