考虑到dataframe
,我做了一些操作来使geometry
通过geopandas
:
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))
要检查turin_point
shapefile中border
的点。
将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:“多边形”对象没有属性“ x”
答案 0 :(得分: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)