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()


Out[4]:
pop_est continent name iso_a3 gdp_md_est geometry
0 920938 Oceania Fiji FJI 8374.0 (POLYGON ((180 -16.06713266364245, 180 -16.555...
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371119710453 -0.950000000000000...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.665589565454809 27.65642588959236...
3 35623680 North America Canada CAN 1674000.0 (POLYGON ((-122.84 49.00000000000011, -122.974...
4 326625791 North America United States of America USA 18560000.0 (POLYGON ((-122.84 49.00000000000011, -120 49....

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()


Out[9]:
pop_est continent name iso_a3 gdp_md_est geometry
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371119710453 -0.950000000000000...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.665589565454809 27.65642588959236...
11 83301151 Africa Dem. Rep. Congo COD 66010.0 POLYGON ((29.33999759290035 -4.499983412294092...
12 7531386 Africa Somalia SOM 4719.0 POLYGON ((41.58513 -1.68325, 40.993 -0.85829, ...
13 47615739 Africa Kenya KEN 152700.0 POLYGON ((39.20222 -4.67677, 37.7669 -3.67712,...

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())