【问题标题】:Find all intersecting polygons in a shape file查找形状文件中的所有相交多边形
【发布时间】:2019-10-10 04:40:33
【问题描述】:

我试图通过 QGIS 算法按位置提取来找出 shapefile 中的所有多边形,它给了我完美的结果,但需要太多时间,大约 25 小时。现在,如果可能的话,我希望它由其他库(如 geopandas 或其他库)来完成。谁能建议我哪个图书馆可以提供帮助?

这就是在 geopandas 中所做的:

import itertools

import geopandas as gpd

gi = gpd.GeoDataFrame.from_file("D:\Shape_file_uploader\qgis\laneGroup.shp")

geoms = gi['geometry'].tolist()

intersection_iter = gpd.GeoDataFrame(gpd.GeoSeries([poly[0].intersection(poly[1]) for poly in  itertools.combinations(geoms, 2)

【问题讨论】:

  • geopandas 应该是您尝试的第一个电话
  • @BrunoVermeulen 请看上面的代码,我做对了吗?我已经添加了
  • 我将提供一个关于如何解决的暂定答案
  • 您能解释一下按位置提取的作用吗?
  • 按位置提取给出了一个 shapefile,它是输入 shapefile 中多边形相交的结果。结果是准确的,但需要更长的时间。

标签: python gis qgis geopandas


【解决方案1】:

我前段时间做过这个,如果我没记错的话,我使用了 geopandas 覆盖方法。所以处理这个的“伪”代码......

from geopandas import GeoDataFrame, overlay

first_shape_gdf = GeoDataFrame.from_file('D:\Shape_file_uploader\qgis\laneGroup.shp')
second_shape_gdf = GeoDataFrame.from_file('another.shp')

intersection_gdf = overlay(first_shape_gdf, second_shape_gdf, how='intersection')

看看Set-Operations with Overlay

【讨论】:

  • 我之前用过这个。但这是为了在两个 shapefile 之间找到相交的多边形。我需要在同一个 shapefile 中找到相交的多边形。
  • 你有我,我不知道该怎么做...可能需要先拆分形状文件...
  • 你能否将相同的数据帧两次传递给覆盖函数,作为第一个和第二个参数?
  • @MichaelEntin 是的,您可以,但与按位置提取相比,它不会为您提供准确的结果。
  • @BrunoVermeulen 实际上,当我两次传递相同的数据帧时,这解决了我的问题。但它给出了部分相交的几何图形。但是,它仍然解决了我的问题。谢谢。
猜你喜欢
  • 2014-02-06
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
相关资源
最近更新 更多