{ "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(\n", " \"https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip\"\n", ")" ] }, { "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(\n", " geo_dataframe=countries,\n", " style={\n", " \"color\": \"black\",\n", " \"fillColor\": \"#3366cc\",\n", " \"opacity\": 0.05,\n", " \"weight\": 1.9,\n", " \"dashArray\": \"2\",\n", " \"fillOpacity\": 0.6,\n", " },\n", " hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.2},\n", " name=\"Countries\",\n", ")\n", "m.add(geo_data)\n", "m.add(ipy.LayersControl())\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rivers_data = ipy.GeoData(\n", " geo_dataframe=rivers,\n", " style={\n", " \"color\": \"purple\",\n", " \"opacity\": 3,\n", " \"weight\": 1.9,\n", " \"dashArray\": \"2\",\n", " \"fillOpacity\": 0.6,\n", " },\n", " hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.2},\n", " name=\"Rivers\",\n", ")\n", "m.add(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(\n", " geo_dataframe=africa_countries,\n", " style={\n", " \"color\": \"black\",\n", " \"fillColor\": \"red\",\n", " \"opacity\": 7,\n", " \"weight\": 1.9,\n", " \"dashArray\": \"7\",\n", " \"fillOpacity\": 0.2,\n", " },\n", " hover_style={\"fillColor\": \"grey\", \"fillOpacity\": 0.6},\n", " name=\"Africa\",\n", ")\n", "m.add(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(ipy.FullScreenControl())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.0" } }, "nbformat": 4, "nbformat_minor": 4 }