5

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)

enter image description here

How can I get rid of neighbor countries and just keep Germany? Or alternatively neighbor countries become fade, blur,pale or something like this.

sentence
  • 8,213
  • 4
  • 31
  • 40
mpy
  • 622
  • 9
  • 23

1 Answers1

7

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:

enter image description here

sentence
  • 8,213
  • 4
  • 31
  • 40
  • 1
    Thanks... could you please elaborate on the "LayerControl" – mpy Apr 10 '20 at 10:55
  • 1
    You are just adding a layer (controlled by the small box at the top right) which allows you to highlight the geometry specified in `folium.GeoJson()`. – sentence Apr 10 '20 at 11:08
  • I were searching google "Folium, how to get country with coordinates", This was the first answer that came up. But I want to do `place = [Lat, Lng]` `land = place.country` – AnonymousUser Oct 31 '21 at 06:29
  • Thank you, I applied the same approach and highlighted specific states – ahmedshahriar Dec 05 '21 at 10:41