gpt4 book ai didi

python - geopandas: sjoin 'NoneType' 对象没有属性 'intersection'

转载 作者:行者123 更新时间:2023-12-01 06:29:11 30 4
gpt4 key购买 nike

我正在尝试对两个开源数据集进行空间连接。我遇到了AttributeError: 'NoneType' object has no attribute 'intersection'错误。通过确保删除空几何体似乎可以解决类似的错误,但这似乎没有帮助。我还安装了spatialindex-1.9.3 和rtree-0.9.3。我正在使用Python 3.8

import geopandas as gpd
import pandas as pd
from shapely.geometry import Point

# Import LSOA polygon data
LSOA_polygons = gpd.read_file('https://raw.githubusercontent.com/gausie/LSOA- 2011-GeoJSON/master/lsoa.geojson')

# Remove any empty geometry
LSOA_polygons = LSOA_polygons[LSOA_polygons.geometry.type == 'Polygon']

# UK charge point data
url_charge_points = 'http://chargepoints.dft.gov.uk/api/retrieve/registry/format/csv'
charge_points = pd.read_csv(url_charge_points, lineterminator='\n', low_memory=False, usecols=[0,3,4])

# Create a geometry column
geometry = [Point(xy) for xy in zip(charge_points['longitude'], charge_points['latitude'])]

# Coordinate reference system : WGS84
crs = {'init': 'epsg:4326'}

# Create a Geographic data frame
charge_points = gpd.GeoDataFrame(charge_points, crs=crs, geometry=geometry)

# Remove any empty geometry
charge_points = charge_points[charge_points.geometry.type == 'Point']

# Execute spatial join
charge_points_LSOA = gpd.sjoin(charge_points, LSOA_polygons, how="inner", op='intersects')

我得到的错误:


AttributeError Traceback (most recent call last)

<ipython-input-13-d724e30179d7> in <module>
12
13 # Execute spatial join
---> 14 charge_points_LSOA = gpd.sjoin(charge_points, LSOA_polygons, how="inner", op='intersects')
15
16 charge_points_LSOA = (charge_points_LSOA >>

~/PycharmProjects/Desirability/venv/lib/python3.8/site-packages/geopandas/tools/sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
106 # get rtree spatial index
107 if tree_idx_right:
--> 108 idxmatch = left_df.geometry.apply(lambda x: x.bounds).apply(
109 lambda x: list(tree_idx.intersection(x)) if not x == () else []
110 )

~/PycharmProjects/Desirability/venv/lib/python3.8/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
4043 else:
4044 values = self.astype(object).values
-> 4045 mapped = lib.map_infer(values, f, convert=convert_dtype)
4046
4047 if len(mapped) and isinstance(mapped[0], Series):

pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

~/PycharmProjects/Desirability/venv/lib/python3.8/site-packages/geopandas/tools/sjoin.py in <lambda>(x)
107 if tree_idx_right:
108 idxmatch = left_df.geometry.apply(lambda x: x.bounds).apply(
--> 109 lambda x: list(tree_idx.intersection(x)) if not x == () else []
110 )
111 idxmatch = idxmatch[idxmatch.apply(len) > 0]

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

最佳答案

我收到了相同的错误消息。在跟踪 sjoin 的代码后,我发现我没有安装 rtree...:-( 安装后错误消失了。

不过,我无法亲自测试您的代码 - 多边形数据的 URL 返回 404。

关于python - geopandas: sjoin 'NoneType' 对象没有属性 'intersection',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59985197/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com