我有以下几点MultiPolygon:
MULTIPOLYGON (
(
(10.8849956 49.8901705, 10.8849507 49.8902499, 10.884969 49.8902588, 10.8851033 49.8903298, 10.8851183 49.8903132, 10.88512882654868 49.8903054, 10.8851246 49.8903054, 10.8851246 49.8902754, 10.8851546 49.8902754, 10.8851546 49.89028643275958, 10.8853289 49.8901612, 10.885421 49.8901035, 10.8854414638889 49.8900896, 10.8854205 49.8900896, 10.8854205 49.8900596, 10.8854505 49.8900596, 10.8854505 49.89008346226415, 10.885527 49.8900315, 10.885519 49.8899952, 10.8854851 49.8899903, 10.8853164 49.8899957, 10.8852419 49.8899981, 10.8851711 49.8899919, 10.8851165 49.8899814, 10.8850728 49.8899652, 10.8850692 49.8899713, 10.8849925 49.8900275, 10.8850251 49.890083, 10.8850275 49.8901159, 10.8850185 49.8901733, 10.8849956 49.8901705),
(10.8852028 49.8901715, 10.8852328 49.8901715, 10.8852328 49.8902015, 10.8852028 49.8902015, 10.8852028 49.8901715),
(10.8852889 49.8900884, …Run Code Online (Sandbox Code Playgroud) 我正在使用开放街道地图数据,我通过立交桥将其下载为 GEOJSON 数据框。虽然我可以根据标签和子标签过滤数据,如下所示:
gdf_b = gdf_b.loc[(gdf_b['高速公路'] != '服务')]
我无法弄清楚删除具有特定几何类型(如点)的地理数据帧的特定行的确切命令
所以我正在寻找类似的东西: gdf_b = gdf_b.loc[(gdf_b['geometry'].type != 'Point')]
我正在开发一个需要坐标映射的项目 - 确定坐标点是否存在于一系列多边形中。映射的数量相当大 - 跨越 100 多个多边形的约 1000 万个坐标。
在继续之前,我已经查看了此处和此处的问题。这个问题并不多余,因为它涉及动态点和静态多边形。
我通过在 200 万个多边形的子集中映射单个坐标来缩小该问题的项目范围。这是我使用的代码:
from shapely.geometry import shape, Point
f = open('path/to/file.geojson', 'r')
data = json.loads(f.read())
point = Point(42.3847, -71.127411)
for feature in data['features']:
polygon = shape(feature['geometry'])
if polygon.contains(point):
print(polygon)
Run Code Online (Sandbox Code Playgroud)
迭代 200 万个多边形(在本例中为建筑足迹)大约需要 30 秒(时间太长)。
我也尝试过使用mplPath如下:
import matplotlib.path as mplPath
building_arrays = [np.array(data['features'][i]['geometry']['coordinates'][0])
for i, v in enumerate(tqdm(data['features']))]
bbPath_list = [mplPath.Path(building)
for building in tqdm(building_arrays)]
for b in tqdm(bbPath_list):
if b.contains_point((-71.1273842, 42.3847423)):
print(b)
Run Code Online (Sandbox Code Playgroud)
这大约需要 6 秒。一个改进,但考虑到我需要的映射量,仍然有点慢。 …