【问题标题】:geopandas contains method doesn't return polygonsgeopandas contains 方法不返回多边形
【发布时间】:2016-08-22 17:20:56
【问题描述】:

我最近开始使用 geopandas 来处理我所在城市的 shapefile。最近我使用 geopandas 的 contains 方法发现了一个问题。问题如下:

我得到了 2 个具有相同 crs 投影的不同 shapefile:区域和部分。我需要获取一个区域内的所有截面多边形。我阅读了 contains 方法,它看起来正是我所需要的,但在运行它时,其中返回的多边形是空的。这里奇怪的是,当我使用 intersects 方法时,它会返回该区域内的部分以及所有相邻部分。

以下是我的代码:

districts = GeoDataFrame.from_file('districts_WGS84.shp')
sections = GeoDataFrame.from_file('sections_WGS84.shp')

districts.crs == sections.crs #To be sure the files share the same crs

#The following line returns an empty array, but it should return all seccions within a district
print len(sections[sections.contains(districts.geometry[34]) == True])
# districts.geometry[34] is a fixed discrict in order to run a test

#The following line returns the list of all sections within the district plus adjacent ones
print len(sections[sections.intersects(districts.geometry[34]) == True])

我尝试获取它的方式有什么问题,还是方法本身有问题?

这里有重复我的问题的 shapefile:

地区:https://ufile.io/0a6f1

部分:https://ufile.io/e2463

问候。

【问题讨论】:

    标签: python shapefile geopandas


    【解决方案1】:

    Intersect 意味着如果两个多边形重叠,它将返回 true,而 contains 意味着只有当一个多边形完全在另一个多边形内时,它才会返回 true。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-01
      • 2021-03-21
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多