首页 > 解决方案 > 如何使用 sjoin 合并两个 GeoDataFrames 而不会出错

问题描述

我正在尝试完成两个 GeodataFrames 之间的空间连接,但出现此错误:

ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat.

这是我的代码/计划,它让我犯了那个错误;

这两个数据框被命名tag_dfcpr_df包含纬度和经度值,所以我首先为两者创建了一个地理数据框;

tag_df['coordinates']=list(zip(tag_df.Longitude,tag_df.Latitude))
tag_df['coordinates']=tag_df['coordinates'].apply(Point)
tag_gdf=gpd.GeoDataFrame(tag_df,geometry='coordinates',crs={'init' :'epsg:4326'})

cpr_df['coordinates']=list(zip(cpr_df.sample_longitude_decimal,cpr_df.sample_latitude_decimal))
cpr_df['coordinates']=cpr_df['coordinates'].apply(Point)
cpr_gdf=gpd.GeoDataFrame(cpr_df,geometry='coordinates',crs={'init' :'epsg:4326'})

然后我创建了一个 5 海里的缓冲区cpr_gdf

cpr_gdf['p_buffer']=cpr_gdf['coordinates'].buffer(5*(1/60))

我现在想做一个空间连接来找出哪些tag_gdf值在哪些缓冲cpr_gdf值中;

tag_in_cpr=sjoin(tag_gdf,cpr_gdf,how='left',op='within')

出现此错误:

ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat

任何帮助都会很棒。

标签: python-3.xgeopandas

解决方案


推荐阅读