我有一个伦敦的shapefile,其中有4000多个代表lsoa区域的独特多边形。我还创建了代表城市中传感器的点的地理数据框。我需要确定每个传感器属于/位于哪个lsoa区域(即哪个多边形)。因此,理想情况下,我将列出每个sesnsor_id_location及其各自的lsoa号(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)
我的伦敦形状文件如下所示:
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, ...
从视觉上看,我的数据如下所示:
谢谢您的帮助。
最佳答案
我发现使用空间连接的一种非常简单的解决方案,如下所示:
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)