【问题标题】:Points within polygon pandas多边形熊猫内的点
【发布时间】:2019-11-12 13:30:00
【问题描述】:

给定一个dataframe,我做了一些操作以通过geopandas 获得geometry

turin_point = 

id_easy ordinal latitude    longitude       epoch   day_of_week geometry
0   qw   1138.0  22.6433       2.6602    22:00:22   Friday      POINT (8.66020 44.64330)
1   qw   1139.0  22.6291       2.6595    22:01:22   Friday      POINT (8.65950 44.62910)
2   qw   1140.0  22.6146       2.6564    22:02:22   Friday      POINT (8.65640 44.61460)
3   qw   1141.0  22.6013       2.6657    22:03:22   Friday      POINT (8.66570 44.60130)
4   qw   1142.0  22.5866       2.6648    22:04:22   Friday      POINT (8.66480 44.58660)

另一个数据框是shapefile:

border = 
zone    geometry
  12    POLYGON ((2.80190 22.96504, 2.80205 22.96483,2.80190 22.96504, 2.80205 22.96483))

想在border shapefile 中检查turin_point 的点。

我的尝试:

将 numpy 导入为 np 将熊猫导入为 pd

import geopandas as gpd
from shapely.geometry import Point, Polygon


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

AttributeError: 'Polygon' 对象没有属性 'x'

【问题讨论】:

    标签: python pandas geopandas


    【解决方案1】:

    试试这个,用你的边界 df,在 turin_point 创建一个 geodf 和一个新列

    import geopandas as gpd
    
    border_gdf = gpd.GeoDataFrame(border, geometry='geometry')
    
    
    turin_point['inside'] = turin_point['geometry'].apply(border_gdf.contains)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 2014-06-16
      • 2014-09-17
      • 2015-02-19
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多