foliumポリゴン色付け

!pip install geopandas
!pip install rtree
!pip install pygeos

!wget https://www.esrij.com/cgi-bin/wp/wp-content/uploads/2012/10/japan_ver83.zip
import pandas as pd
import geopandas as gpd

japan = gpd.read_file("japan_ver83.zip!japan_ver83")

ehime = japan[japan["KEN"] == "愛媛県"].copy()

ehime

ehime["color"] = "gray"

ehime.loc[ehime["SIKUCHOSON"].str.endswith("市"), "color"] = "red"

import folium

map = folium.Map(
    tiles="cartodbpositron",
    location=[34.06604300, 132.99765800],
    zoom_start=12,
)

def style(feature):
    return {
        "fillColor": feature["properties"]["color"],
        "color": feature["properties"]["color"],
        "weight": 1,
    }

folium.GeoJson(data=ehime.to_json(), style_function=style).add_to(map)

ehime.to_json()

map

f:id:imabari_ehime:20210816002726p:plain