返回多边形geopandas内的点列表 [英] return list of points within polygon geopandas
问题描述
我有一个伦敦的shapefile,其中有4000多个代表lsoa区域的独特多边形.我还创建了代表城市中传感器的点的地理数据框.我需要确定每个传感器属于/位于哪个lsoa区域(即哪个多边形).因此,理想情况下,我将拥有每个sesnsor_id_location及其各自的lsoa编号(LSOA11DC)的列表.
I have a shapefile of London with over 4000 unique polygons representing lsoa areas. I have also created a geodataframe of points representing sensors in the city. I need to work out which lsoa area (ie which polygon) each sensor belongs to/is within. So ideally I would have a list of each sesnsor_id_location and their respective lsoa number (LSOA11DC).
我的观点如下:
pod_id_location Borough Latitude Longitude geometry
0 1245 Barnet 51.604486 -0.206551 POINT (-0.20655 51.60449)
1 2245 Camden 51.521880 -0.120434 POINT (-0.12043 51.52188)
2 3245 Camden 51.555485 -0.152338 POINT (-0.15234 51.55548)
3 5245 Wandsworth 51.440399 -0.186775 POINT (-0.18677 51.44040)
4 6245 Hounslow 51.468625 -0.359770 POINT (-0.35977 51.46863)
我的伦敦形状文件如下所示:
and my london shape file looks like this:
LSOA11CD LSOA11NM geometry
0 E01000001 City of London 001A POLYGON ((-0.09729 51.52158, -0.09652 51.52027...
1 E01000002 City of London 001B POLYGON ((-0.08813 51.51941, -0.08929 51.51752...
2 E01000003 City of London 001C POLYGON ((-0.09679 51.52325, -0.09647 51.52282...
3 E01000005 City of London 001E POLYGON ((-0.07323 51.51000, -0.07553 51.50974...
4 E01000006 Barking and Dagenham 016A POLYGON ((0.09115 51.53909, 0.09326 51.53787, ...
从视觉上看,我的数据如下:
Visually my data looks like this:
感谢您的帮助.
推荐答案
我发现使用空间连接的一种非常简单的解决方案,如下所示:
I have found a very simple solution using a spatial join as follows:
merge = gpd.sjoin(map_df, sensors, how="right", op='contains')
index_left LSOA11CD LSOA11NM pod_id_location Borough Latitude Longitude geometry
index_right
0 199 E01000204 Barnet 025C 1245 Barnet 51.604486 -0.206551 POINT (-0.20655 51.60449)
1 897 E01000915 Camden 027A 2245 Camden 51.521880 -0.120434 POINT (-0.12043 51.52188)
这篇关于返回多边形geopandas内的点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!