【发布时间】:2019-10-15 14:04:09
【问题描述】:
我需要通过 QGIS 中的 geopandas 找到 GeoDataFrame 与其自身的交集。该代码在 Anaconda 环境中运行良好,但在 QGIS python 中失败。
Shapefile 可在以下链接获得: https://drive.google.com/file/d/1DQqg7Cf6AokyadkmOE8Y6k41tqDMXdmS/view?usp=drivesdk
下面是代码:
df1 = gpd.GeoDataFrame.from_file("C:\\QGIS_ShapeFile1\\qgis\\laneGroup.shp")
intersection_gdf = overlay(df1, df1, how='intersection')
在QGIS中,出现如下错误:
An error has occurred while executing Python code:
AttributeError: 'NoneType' object has no attribute 'intersection'
Traceback (most recent call last):
File"C:/Users/sn43673/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ad_qgis\shapefile_validator.py", line 318, in errorInShapeFile
intersection_gdf = overlay(df1, df2, how='intersection')File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\geopandas\tools\overlay.py", line 391, in overlay
File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\geopandas\tools\overlay.py", line 216, in _overlay_intersection
for k in j:
File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\pandas\core\series.py", line 4042, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas\_libs\lib.pyx", line 2228, in pandas._libs.lib.map_infer
File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\geopandas\tools\overlay.py", line 216, in
for k in j:
AttributeError: 'NoneType' object has no attribute 'intersection'
【问题讨论】:
-
你能提供一个小的可重现的代码示例吗?
-
@joris 我在上面的描述中添加了形状文件。您可以将它与上面的代码一起使用。
-
谢谢。您在两种环境中都使用什么版本的 GeoPandas? (您可以与
geopandas.__version__联系)对我来说,这适用于 geopandas 0.5.1 和 0.6.0 -
我使用的是 0.6.0。你在哪里检查的,在 Anaconda 上?
-
它可以在 anaconda 上正常工作,但不能在 QGIS 上工作
标签: python python-3.x qgis geopandas