{ "cells": [ { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "import geemap\n", "import ee\n", "import folium\n", "import geopandas as gpd" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "ee.Initialize()" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7319d0b609f648c9b74211745a3fd77d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map(center=[-8.980207755364754, 13.310742868350161], controls=(WidgetControl(options=['position', 'transparent…" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datadir = 'C:/Users/jtrum/world_bank/data/'\n", "\n", "# Define the path to your GeoJSON file\n", "aoi_path = datadir + 'luanda2clean.geojson'\n", "\n", "# Load the GeoJSON as a Feature\n", "aoi = geemap.geojson_to_ee(aoi_path)\n", "\n", "# Create a map\n", "Map = geemap.Map()\n", "#choose a different basemap\n", "Map.add_basemap('CartoDB.DarkMatter')\n", "\n", "# Load the ESA Land Cover data\n", "esa = ee.ImageCollection(\"ESA/WorldCover/v100\").first()\n", "\n", "# Filter the data to your AOI\n", "esa = esa.clip(aoi)\n", "\n", "esa_vis = {'bands': ['Map']}\n", "\n", "# Add the ESA Land Cover layer to the map\n", "Map.addLayer(esa, esa_vis, \"ESA Land Cover\")\n", "\n", "# add legend with colors chosen from self-defined palette\n", "Map.add_legend(builtin_legend='ESA_WorldCover', \n", " #legend_title=\"ESA Land Cover\", \n", " #layer_name=\"ESA Land Cover\", \n", " colors=['#05450a', '#086a10', '#54a708', '#78d203', '#009900', '#c6b044', '#dcd159', '#dade48', '#fbff13','#d5n5n5', '#129279'],\n", " labels=['trees', 'shrublands', 'grasslands', 'croplands', 'built-up', 'bare', 'snow and ice', 'water bodies', 'herbaceous vegetation', 'mangroves', 'moss and lichen']\n", " )\n", "\n", "\n", "#start the zoom at the center of the AOI\n", "Map.centerObject(aoi, 10)\n", "\n", "\n", "\n", "# Display the map\n", "Map\n" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Calculating area for group 10 ...\n", "Calculating area for group 20 ...\n", "Calculating area for group 30 ...\n", "Calculating area for group 40 ...\n", "Calculating area for group 50 ...\n", "Calculating area for group 60 ...\n", "Calculating area for group 80 ...\n", "Calculating area for group 90 ...\n", "Calculating area for group 95 ...\n" ] } ], "source": [ "df = geemap.image_area_by_group(esa, scale=1000, denominator=1e6, decimal_places=4, verbose=True)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "area float64\n", "percentage float64\n", "dtype: object" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.dtypes" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | type | \n", "area | \n", "percentage | \n", "
---|---|---|---|
0 | \n", "Trees | \n", "42.6993 | \n", "1.75 | \n", "
1 | \n", "Shrublands | \n", "10.7903 | \n", "0.44 | \n", "
2 | \n", "Grasslands | \n", "1460.9425 | \n", "59.87 | \n", "
3 | \n", "Croplands | \n", "6.7740 | \n", "0.28 | \n", "
4 | \n", "Built-Up | \n", "505.1714 | \n", "20.70 | \n", "
5 | \n", "Barren | \n", "135.6323 | \n", "5.56 | \n", "
6 | \n", "Water Bodies | \n", "37.0484 | \n", "1.52 | \n", "
7 | \n", "Herbaceous Wetlands | \n", "195.5900 | \n", "8.02 | \n", "
8 | \n", "Mangroves | \n", "45.3820 | \n", "1.86 | \n", "