python - 在 FOLIUM python 中处理缺失的几何图形
问题描述
GeoJSON 来自这里
country_geodf = gpd.read_file("https://datahub.io/core/geo-countries/r/countries.geojson")
我正在尝试使用上述 geoJSON 数据和 Kaggle 的 2021 ML 和 DS 调查数据来创建等值线图。但反复面对这些错误。有没有办法处理丢失的几何图形?
Folium 可以处理缺失值,但不能处理缺失几何。
错误跟踪
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_42/729212434.py in <module>
16 show=False,
17 overlay=True,
---> 18 nan_fill_color = "White"
19 ).add_to(country_map)
20
/opt/conda/lib/python3.7/site-packages/folium/features.py in __init__(self, geo_data, data, columns, key_on, bins, fill_color, nan_fill_color, fill_opacity, nan_fill_opacity, line_color, line_weight, line_opacity, name, legend_name, overlay, control, show, topojson, smooth_factor, highlight, **kwargs)
1291 style_function=style_function,
1292 smooth_factor=smooth_factor,
-> 1293 highlight_function=highlight_function if highlight else None)
1294
1295 self.add_child(self.geojson)
/opt/conda/lib/python3.7/site-packages/folium/features.py in __init__(self, data, style_function, highlight_function, name, overlay, control, show, smooth_factor, tooltip, embed, popup, zoom_on_click, marker)
497 self.marker = marker
498
--> 499 self.data = self.process_data(data)
500
501 if self.style or self.highlight:
/opt/conda/lib/python3.7/site-packages/folium/features.py in process_data(self, data)
543 else:
544 raise ValueError('Cannot render objects with any missing geometries'
--> 545 ': {!r}'.format(data))
546
547 def convert_to_feature_collection(self):
ValueError: Cannot render objects with any missing geometries: ISO_A3 Q3 ADMIN \
0 IND 30.18 India
1 USA 10.76 United States of America
2 JPN 3.74 Japan
3 CHN 3.30 China
4 BRA 3.05 Brazil
.. ... ... ...
59 KAZ 0.18 Kazakhstan
60 NOR 0.18 Norway
61 DZA 0.18 Algeria
62 IRQ 0.17 Iraq
63 ETH 0.17 Ethiopia
geometry
0 MULTIPOLYGON (((93.85532 7.21418, 93.86500 7.2...
1 MULTIPOLYGON (((-155.60652 20.13796, -155.5863...
2 MULTIPOLYGON (((141.46795 24.21377, 141.46315 ...
3 MULTIPOLYGON (((111.20460 15.77924, 111.19654 ...
4 MULTIPOLYGON (((-48.54259 -27.81666, -48.55187...
.. ...
59 MULTIPOLYGON (((50.65952 44.93895, 50.67799 44...
60 MULTIPOLYGON (((3.38258 -54.44931, 3.36451 -54...
61 POLYGON ((8.60251 36.93951, 8.60566 36.91305, ...
62 POLYGON ((42.89674 37.32491, 42.93705 37.32015...
63 POLYGON ((38.13331 14.67776, 38.19026 14.68732...
[64 rows x 4 columns]
解决方案
推荐阅读
- javascript - Exp 后缀附加到标记模板 (JavaScript) 中的参数/变量
- sql - 无法使用外键创建 sqlite 表
- c# - 如何使用 asp.net C# 在循环中进行 Gridview 列选择
- html - 如何分别在嵌套列表有序数字中应用样式?
- encryption - 如何在 Windows 上使用 PGP 加密使用 ASC 公钥文件加密磁盘上的文件
- dart - VSCode Flutter Dart 慢的建议
- python - 如何为 Python 包装 C++ VTK 自定义函数
- javascript - 关于实现分页 API 的两种不同方法的问题
- php - php没有与mysql连接
- sass - 使用 Bootstrap 5 添加新实用程序