{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add ESA Land Cover data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "dataset = ee.ImageCollection(\"ESA/WorldCover/v100\").first()\n", "Map.addLayer(dataset, {'bands': ['Map']}, 'ESA Land Cover')\n", "Map.add_legend(builtin_legend='ESA_WorldCover')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the area of each land cover type." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = geemap.image_area_by_group(\n", " dataset, scale=1000, denominator=1e6, decimal_places=4, verbose=True\n", ")\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save the results to a CSV." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.to_csv('esa_area.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add NLCD land cover data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "Map.add_basemap('HYBRID')\n", "\n", "nlcd = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019')\n", "landcover = nlcd.select('landcover')\n", "\n", "Map.addLayer(landcover, {}, 'NLCD Land Cover 2019')\n", "Map.add_legend(\n", " title=\"NLCD Land Cover Classification\", builtin_legend='NLCD', height='465px'\n", ")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the area of each land cover type." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = geemap.image_area_by_group(\n", " landcover, scale=1000, denominator=1e6, decimal_places=4, verbose=True\n", ")\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save the results to a CSV." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.to_csv('nlcd_area.csv')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }