#!/usr/bin/env python # coding: utf-8 # # GeoData # In[1]: import ipyleaflet as ipy import geopandas import json # In[2]: m = ipy.Map(center=(52.3,8.0), zoom = 3, basemap= ipy.basemaps.Esri.WorldTopoMap) # In[3]: countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities')) rivers = geopandas.read_file("https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip") # ## GeoDataFrame # In[4]: countries.head() # In[5]: geo_data = ipy.GeoData(geo_dataframe = countries, style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6}, hover_style={'fillColor': 'red' , 'fillOpacity': 0.2}, name = 'Countries') m.add_layer(geo_data) m.add_control(ipy.LayersControl()) m # In[6]: rivers_data = ipy.GeoData(geo_dataframe = rivers, style={'color': 'purple', 'opacity':3, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6}, hover_style={'fillColor': 'red' , 'fillOpacity': 0.2}, name = 'Rivers') m.add_layer(rivers_data) # In[7]: #geo_data.geo_dataframe = cities # In[8]: #m.remove_layer(geo_data) # ## Continent # In[9]: africa_countries = countries[countries['continent'] == 'Africa'] africa_countries.head() # In[10]: africa_data = ipy.GeoData(geo_dataframe = africa_countries, style={'color': 'black', 'fillColor': 'red', 'opacity':7, 'weight':1.9, 'dashArray':'7', 'fillOpacity':0.2}, hover_style={'fillColor': 'grey', 'fillOpacity': 0.6}, name = 'Africa') m.add_layer(africa_data) m # In[11]: #m.remove_layer(africa_data) # In[12]: m.add_control(ipy.FullScreenControl())