{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# GeoData" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipyleaflet as ipy \n", "import geopandas \n", "import json" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = ipy.Map(center=(52.3,8.0), zoom = 3, basemap= ipy.basemaps.Esri.WorldTopoMap)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", "cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))\n", "rivers = geopandas.read_file(\"https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## GeoDataFrame" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "countries.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geo_data = ipy.GeoData(geo_dataframe = countries,\n", " style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},\n", " hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},\n", " name = 'Countries')\n", "m.add_layer(geo_data)\n", "m.add_control(ipy.LayersControl())\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rivers_data = ipy.GeoData(geo_dataframe = rivers,\n", " style={'color': 'purple', 'opacity':3, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},\n", " hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},\n", " name = 'Rivers')\n", "m.add_layer(rivers_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#geo_data.geo_dataframe = cities " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#m.remove_layer(geo_data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Continent" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "africa_countries = countries[countries['continent'] == 'Africa']\n", "africa_countries.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "africa_data = ipy.GeoData(geo_dataframe = africa_countries,\n", " style={'color': 'black', 'fillColor': 'red', 'opacity':7, 'weight':1.9, 'dashArray':'7', 'fillOpacity':0.2},\n", " hover_style={'fillColor': 'grey', 'fillOpacity': 0.6},\n", " name = 'Africa')\n", "m.add_layer(africa_data)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#m.remove_layer(africa_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_control(ipy.FullScreenControl())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }