【发布时间】:2023-02-07 06:54:51
【问题描述】:
我正在制作一个程序,从风暴预测中心 (SPC) 过去的对流前景中检索 GeoJSON 数据,并使用 geopandas 绘制它。使用我当前的代码,它能够将 outlooks 正确地绘制到地图上。但是,着色不正确。我注意到 SPC 返回的 GeoJSON 包含类别的轮廓和填充着色数据 -(在 properties 字段中)
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates": ...}, "properties": {"DN": 2, "VALID": "202109010100", "EXPIRE": "202109011200", "ISSUE": "202109010042", "LABEL": "TSTM", "LABEL2": "General Thunderstorms Risk", "stroke": "#55BB55", "fill": "#C1E9C1"}}, {"type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates": ...}, "properties": {"DN": 3, "VALID": "202109010100", "EXPIRE": "202109011200", "ISSUE": "202109010042", "LABEL": "MRGL", "LABEL2": "Marginal Risk", "stroke": "#005500", "fill": "#66A366"}}, {"type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates": ...}, "properties": {"DN": 4, "VALID": "202109010100", "EXPIRE": "202109011200", "ISSUE": "202109010042", "LABEL": "SLGT", "LABEL2": "Slight Risk", "stroke": "#DDAA00", "fill": "#FFE066"}}]}
是否可以使用properties中的stroke和fill数据自动给每一个MultiPolygon上色?
我当前的代码如下(假设所有包都已导入)
outlook = "https://www.spc.noaa.gov/products/outlook/archive/2021/day1otlk_20210901_0100_cat.lyr.geojson"
world = geopandas.read_file(
geopandas.datasets.get_path('naturalearth_lowres')
)
df = geopandas.read_file(outlook)
ax = world.plot(color='white', edgecolor='#333333',linewidth=0.3)
print(type(df))
s = geopandas.GeoDataFrame(df)
s.plot(ax=ax,markersize=0.7,figsize=(1000,1000))
ax.set_xlim(-140, -70) # focus on continental US
ax.set_ylim(25, 50) # focus on continental US
plt.savefig('outlook.jpg', dpi=360) # save as outlook.jpg
我试着查看 geopandas 文档,但它没有说明如何使用 geojson 中的字段为多边形着色。
【问题讨论】:
标签: python matplotlib geojson geopandas