突出显示Folium中的一个特定国家 [英] Highlight one specific country in Folium
本文介绍了突出显示Folium中的一个特定国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张由大叶草绘制的地图,如下所示:
m = folium.Map(location = [51.1657,10.4515] ,zoom_start = 6,min_zoom = 5,max_zoom = 7)
我如何摆脱邻国而只保留德国?
或者邻近的国家变得褪色,模糊,苍白或类似的东西。
解决方案
包含感兴趣国家/地区的几何图形(坐标)的json文件,您可以添加
I have a map drawn by folium as follow:
m = folium.Map(location = [51.1657,10.4515], zoom_start=6, min_zoom = 5, max_zoom = 7)
How can I get rid of neighbor countries and just keep Germany? Or alternatively neighbor countries become fade, blur,pale or something like this.
解决方案
As long as you have a json file containing the geometry (coordinates) for the country of interest, you can add a GeoJson
layer:
import folium
import json
with open('datasets/world-countries.json') as handle:
country_geo = json.loads(handle.read())
for i in country_geo['features']:
if i['properties']['name'] == 'Germany':
country = i
break
m = folium.Map(location = [51.1657,10.4515],
zoom_start=6,
min_zoom = 5,
max_zoom = 7)
folium.GeoJson(country,
name='germany').add_to(m)
folium.LayerControl().add_to(m)
m
and you get:
这篇关于突出显示Folium中的一个特定国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文