python-3.x - 如何使用 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_df
并cpr_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
任何帮助都会很棒。
解决方案
推荐阅读
- swift - 按下按钮时添加表格视图单元格
- kubernetes - 对于具有并行性的作业,如何确保所有节点在 K8S 中同时运行
- python - 如何在多个 Numpy 数组中获取相同值的位置
- python - 如何使用列表项的名称创建函数,
- html - 如何在聊天气泡外对齐用户名?
- android - android jetpack compose kotlin 合成扩展支持
- c++ - 是否有 C++ 库方法可以执行我编写的操作?
- r - 我可以在 R 中将 plotly() 与网络可视化一起使用吗?
- python - b64encode 带参数
- php - 如果产品类别有子项,则从 WooCommerce 中的父项中删除永久链接