【发布时间】:2021-08-18 06:23:45
【问题描述】:
我想绘制 GeoJson 文件中包含的一些多边形。是否可以在 Plotly 中可视化未直接链接到真实世界位置的 GeoJson 文件?
例如,我可以使用 GeoPandas 绘制通用 GeoJson 文件:
import json
geodata = json.loads(
"""{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Polygon", "coordinates": [[[0,0],[0,1],[1,1]]]},
"properties": {"id": "upper_left"}
},
{ "type": "Feature",
"geometry": {"type": "Polygon", "coordinates": [[[0,0],[1,1],[1,0]]]},
"properties": {"id": "lower_right"}
}
]
}""")
import geopandas as gpd
df_shapes = gpd.GeoDataFrame.from_features(geodata["features"])
df_shapes.plot(color="none")
结果显示 GeoJson 中包含的两个多边形(三角形):
如何使用 Plotly 绘制相同的地图? This answer 建议使用范围来限制显示的底图。没有底图怎么办?
(我不是在问如何用一条线绘制一个正方形。GeoJson 只是一个简化的例子。)
【问题讨论】: