{ "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": "markdown", "metadata": {}, "source": [ "Import libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "import geemap.colormaps as cm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an interactive map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a DEM to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dem = ee.Image('USGS/3DEP/10m')\n", "vis = {'min': 0, 'max': 4000, 'palette': cm.palettes.dem}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(dem, vis, 'DEM')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add NLCD land cover data and legend to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "landcover = ee.Image(\"USGS/NLCD_RELEASES/2019_REL/NLCD/2019\").select('landcover')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(landcover, {}, 'NLCD 2019')\n", "Map.add_legend(builtin_legend='NLCD')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate image zonal statistics by zone. In this case, we are going to calculate the mean elevation by each land cover type. The result can be returned as a Panda DataFrame or saved as a CSV." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stats = geemap.image_stats_by_zone(dem, landcover, reducer='MEAN')\n", "stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save the resulting Pandas DataFrame as a CSV." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stats.to_csv('mean.csv', index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the standard deviation of elevation by each land cover type and save the result as a CSV." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.image_stats_by_zone(dem, landcover, out_csv=\"std.csv\", reducer='STD')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }