Geopandas Spatial Join - AttributeError: 'NoneType' object has no attribute 'bounds'
Geopandas Spatial Join - AttributeError: 'NoneType' object has no attribute 'bounds'
我有以下地理数据框,对应于一个规则网格:
id grid_id geometry
0 48 0 (POLYGON ((2.052457758079306 41.42493869117656...
1 49 1 (POLYGON ((2.052470852112577 41.42403805731954...
2 215 2 (POLYGON ((2.053641274433816 41.42584917461342...
3 216 3 (POLYGON ((2.053654352531821 41.42494854059127...
4 217 4 (POLYGON ((2.053667430035439 41.42404790642426...
和一个点地理数据框:
id_act geometry
0 4001 POINT (2.183026563657264 41.37459702541483)
1 4003 POINT (2.183012216695291 41.37471411724238)
2 4003 POINT (2.183128113845906 41.37472901746361)
3 3002 POINT (2.182820482338962 41.37482095671629)
4 4003 POINT (2.182945418252172 41.37482221760939)
我正在通过空间连接合并两个数据帧:
id_grid = gpd.sjoin(gdf, grid, how="inner", op='intersects')
但是 returns 以下 AttributeError
:
AttributeError: 'NoneType' object has no attribute 'bounds'
重点是当我调用函数时:
grid.bounds
它产生:
minx miny maxx maxy
0 2.052458 41.424038 2.053667 41.424949
1 2.052471 41.423137 2.053681 41.424048
2 2.053641 41.424949 2.054851 41.425859
3 2.053654 41.424048 2.054864 41.424958
4 2.053667 41.423147 2.054877 41.424058
5 2.053681 41.422247 2.054890 41.423157
同时调用 type(gdf.geometry[0])
或 type(grid.geometry[0])
得到:
shapely.geometry.point.Point
shapely.geometry.multipolygon.MultiPolygon
分别。
有谁知道错在哪里吗?
很可能,您的点地理数据框包含空几何。这就是为什么你会得到 'NoneType'。您可以通过
删除它们
points_clean = points[points.geometry.type == 'Point']
它只会在几何列中保留带有 Point
类型的行。然后你的空间连接应该工作。您的 Polygon 层中也可能有一个空几何体。在这种情况下,只需将上面的代码从 Point
修改为 Polygon
或 MultiPolygon
.
我有以下地理数据框,对应于一个规则网格:
id grid_id geometry
0 48 0 (POLYGON ((2.052457758079306 41.42493869117656...
1 49 1 (POLYGON ((2.052470852112577 41.42403805731954...
2 215 2 (POLYGON ((2.053641274433816 41.42584917461342...
3 216 3 (POLYGON ((2.053654352531821 41.42494854059127...
4 217 4 (POLYGON ((2.053667430035439 41.42404790642426...
和一个点地理数据框:
id_act geometry
0 4001 POINT (2.183026563657264 41.37459702541483)
1 4003 POINT (2.183012216695291 41.37471411724238)
2 4003 POINT (2.183128113845906 41.37472901746361)
3 3002 POINT (2.182820482338962 41.37482095671629)
4 4003 POINT (2.182945418252172 41.37482221760939)
我正在通过空间连接合并两个数据帧:
id_grid = gpd.sjoin(gdf, grid, how="inner", op='intersects')
但是 returns 以下 AttributeError
:
AttributeError: 'NoneType' object has no attribute 'bounds'
重点是当我调用函数时:
grid.bounds
它产生:
minx miny maxx maxy
0 2.052458 41.424038 2.053667 41.424949
1 2.052471 41.423137 2.053681 41.424048
2 2.053641 41.424949 2.054851 41.425859
3 2.053654 41.424048 2.054864 41.424958
4 2.053667 41.423147 2.054877 41.424058
5 2.053681 41.422247 2.054890 41.423157
同时调用 type(gdf.geometry[0])
或 type(grid.geometry[0])
得到:
shapely.geometry.point.Point
shapely.geometry.multipolygon.MultiPolygon
分别。
有谁知道错在哪里吗?
很可能,您的点地理数据框包含空几何。这就是为什么你会得到 'NoneType'。您可以通过
删除它们points_clean = points[points.geometry.type == 'Point']
它只会在几何列中保留带有 Point
类型的行。然后你的空间连接应该工作。您的 Polygon 层中也可能有一个空几何体。在这种情况下,只需将上面的代码从 Point
修改为 Polygon
或 MultiPolygon
.