Folium GeoJson自定义颜色图

落基山脉滑雪者

我正在尝试使用Folium将多部分shapefile显示在地图上。代码如下:

import folium
import gdal
import geopandas as gpd
import branca.colormap as cm

gdf = gpd.read_file("field.shp")

def rank_colormap(gdf):
    if gdf['RANK'] is 1.0:
        return 'red'
    if gdf['RANK'] is 2.0 or 3.0:
        return 'orange'
    if gdf['RANK'] is 4.0:
        return 'gold'
    if gdf['RANK'] is 5.0 or 6.0:
        return 'yellow'
    if gdf['RANK'] is 7.0:
        return 'greenyellow'
    if gdf['RANK'] is 8.0 or 9.0:
        return 'lime'
    elif gdf['RANK'] is 10.0:
        return 'green'

#create map object
m = folium.Map(location=[49.112675, -104.104781], zoom_start=15)
folium.GeoJson(data=gdf, style_function=lambda feature: {
        'fillColor': rank_colormap(gdf),
        'color': 'black',
        'weight': '0.5',
        'fill': True,
        'fill_opacity' : '1'
    }).add_to(m)
tile = folium.TileLayer(
        tiles = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
        attr = 'Esri',
        name = 'Esri Satellite',
        overlay = False,
        control = True
       ).add_to(m)


legendcolormap = cm.LinearColormap(colors=['red', 'orange', 'gold' ,'yellow', 'greenyellow', 'lime', 'green'], vmin=1, vmax=10)
legendcolormap.add_to(m)


#global tooltip
tooltip = 'Click For More Info'

gdf当前看起来像这样,我正在尝试将颜色映射到相应的“ RANK”值:

在此处输入图片说明

但是,我的fillcolor调整不正确,仅剩下一种颜色:

在此处输入图片说明

如何正确地将色彩图分配给我的叶片图?

落基山脉滑雪者

解决了:

def getcolor(feature):
    if feature['properties']['RANK'] == 1.0:
        return 'red'
    if feature['properties']['RANK'] == 2.0:
        return 'orange'
    if feature['properties']['RANK'] == 3.0:
        return 'orange'
    if feature['properties']['RANK'] == 4.0:
        return 'gold'
    if feature['properties']['RANK'] == 5.0:
        return 'yellow'
    if feature['properties']['RANK'] == 6.0:
        return 'yellow'
    if feature['properties']['RANK'] == 7.0:
        return 'greenyellow'
    if feature['properties']['RANK'] == 8.0:
        return 'lime'
    if feature['properties']['RANK'] == 9.0:
        return 'lime'
    if feature['properties']['RANK'] == 10.0:
        return 'green'
    else:
        return 'gray'

folium.GeoJson(gdf1, smooth_factor = 1, style_function = lambda feature: {
        'fillColor': getcolor(feature),
        'weight': 0,
        'fillOpacity': 0.8,
}).add_to(fg1)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Folium:GeoJson的圆形标记

来自分类Dev

Folium Choropleth + GeoJSON引发AttributeError:'NoneType'

来自分类Dev

folium.plugins绘制热图的问题

来自分类Dev

根据标记颜色过滤Folium Map

来自分类Dev

GeoJson图层在python Folium地图上不可见

来自分类Dev

seaborn / matplotlib自定义颜色图

来自分类Dev

自定义Matplotlib颜色图

来自分类Dev

matplotlib错误栏图-使用自定义颜色图

来自分类Dev

MapBoxGL使用自定义颜色添加GeoJSON圆形标记

来自分类Dev

如何修复python folium geoJSON代码中的“AttributeError:'str'对象没有属性'setdefault'”?

来自分类Dev

Folium Chropleth Map呈现灰色阴影,而不是主题图的真实颜色

来自分类Dev

matplotlib中的自定义连续颜色图

来自分类Dev

使用python中的matplotlib制作自定义颜色图

来自分类Dev

JFreeChart条形图自定义颜色?

来自分类Dev

AMCharts甜甜圈图颜色渐变自定义

来自分类Dev

创建自定义seaborn颜色图时出错

来自分类Dev

使用python中的matplotlib制作自定义颜色图

来自分类Dev

使用CBfit Matlab自定义颜色图

来自分类Dev

matplotlib中的自定义连续颜色图

来自分类Dev

在轮廓上使用自定义颜色图

来自分类Dev

matplotlib中的自定义颜色图用于3D表面图

来自分类Dev

D3平面图自定义颜色的热图

来自分类Dev

Python-具有0.99和0.999不同颜色的自定义颜色图

来自分类Dev

带有浮点范围的自定义颜色图,可用于Matlab中的颜色

来自分类Dev

自定义素面图

来自分类Dev

自定义蜂巢图

来自分类Dev

自定义素面图

来自分类Dev

自定义颜色条

来自分类Dev

自定义颜色Swift