从地理数据框中检查多边形内的点 [英] Check for points within polygon from geodataframe

查看:97
本文介绍了从地理数据框中检查多边形内的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个印度地区的shapefile:

I have a shapefile of Indian districts:

full_state_df = gpd.read_file("kerala/shapefiles/district.shp")
print (full_state_df.head())

结果:

    DISTRICT  ...                                           geometry
0  Alappuzha  ...  POLYGON ((76.37334 9.83565, 76.37955 9.82888, ...
1  Ernakulam  ...  POLYGON ((76.68924 10.26721, 76.68724 10.26170...
2     Idukki  ...  POLYGON ((77.28895 10.22973, 77.29462 10.21643...
3     Kannur  ...  POLYGON ((75.46997 12.30049, 75.48558 12.29131...
4  Kasaragod  ...  POLYGON ((75.41667 12.50166, 75.42240 12.48463...

我有一个csv文件,其中列出了手机信号塔.

I have a csv file which lists cellphone towers.

radio,mcc,net,area,cell,unit,lon,lat,range,samples,changeable,created,updated,averageSignal
GSM,405,67,5021,21106,0,87.192306518555,22.334518432617,1000,1,1,1459748781,1459748781,0
GSM,405,752,7302,57151,0,86.663589477539,22.370223999023,1000,1,1,1459748770,1459748770,0
GSM,405,852,51,3066,0,77.056045532227,11.272659301758,1000,1,1,1459682666,1459682666,0
...

我想过滤出位于指定区域内的点的线.例如,我选择Alappuzha:

I want to filter out lines for points that lie within a specified district. Say, for example, I select Alappuzha:

patch_df = full_state_df.loc[full_state_df['DISTRICT'] == 'Alappuzha']

...并获得:

    DISTRICT  ...                                           geometry
0  Alappuzha  ...  POLYGON ((76.37334 9.83565, 76.37955 9.82888, ...

我如何1)提取多边形并测试其中是否有纬线?

How do I 1) extract the POLYGON and test if a lat-long lies in that?

推荐答案

IIUC,如果对点和多边形使用地理数据框,则可以执行此操作. points_in_polygon_gdf将包含每个区域内的点.

IIUC, you can do this if you use geodataframes for your points and polygons. The points_in_polygon_gdf will contain the points that are within each district.

points_in_polygons_gdf = gpd.sjoin(points_gdf, polygons_gdf, op='within', how='inner')

这篇关于从地理数据框中检查多边形内的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆