简体   繁体   中英

Geopandas: how to make spatial join between geoandas dataframes?

I have two geopandas dataframes. One composed by polygon and another by points.

grid.head()

                                            geometry  zone
0   POLYGON ((-71.11007 42.36766, -71.10957 42.367...   0
1   POLYGON ((-71.11007 42.36716, -71.10957 42.367...   1
2   POLYGON ((-71.11007 42.36666, -71.10957 42.366...   2
3   POLYGON ((-71.11007 42.36616, -71.10957 42.366...   3
4   POLYGON ((-71.11007 42.36566, -71.10957 42.365...   4

gdf.head()
                     geometry
0   POINT (-71.09000 42.36000)
1   POINT (-71.09000 42.36000)
2   POINT (-71.09477 42.36407)
3   POINT (-71.09000 42.36000)
4   POINT (-71.09477 42.36407)

If I try to make a spatial join I get an error

from geopandas import sjoin
gdf = sjoin(grid, gdf)

AttributeError: 'NoneType' object has no attribute 'intersection'

I tried to install rtree

sudo python3.7 -m pip install "rtree>=0.8,<0.9"

Looks like at least one of the entries in the geometry column of either grid or gdf is None . sjoin needs to do spatial intersections on all the geometries, which it cannot do if they are None .

You can check if any of the following returns any rows:

grid[grid.geometry.isnull()]
gdf[gdf.geometry.isnull()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM