{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "0", "metadata": {}, "outputs": [], "source": [ "# Import libraries\n", "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# Create an interactive map by specifying the center (lat, lon) and zoom level (1-18).\n", "Map = geemap.Map(center=[40, -100], zoom=4)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "# Import the NLCD collection.\n", "dataset = ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\")\n", "\n", "# Filter the collection to the 2016 product.\n", "nlcd2016 = dataset.filter(ee.Filter.eq(\"system:index\", \"2019\")).first()\n", "\n", "# Select the land cover band.\n", "landcover = nlcd2016.select(\"landcover\")\n", "\n", "# Display land cover on the map.\n", "Map.addLayer(landcover, {}, \"NLCD 2019\")" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "# Add the NLCD legend to the map.\n", "Map.add_legend(title=\"NLCD Land Cover Classification\", builtin_legend=\"NLCD\")" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "# # To add a custom legend to the map, uncomment the following code and modify the legend dictionary.\n", "# legend_dict = {\n", "# '11 Open Water': '466b9f',\n", "# '12 Perennial Ice/Snow': 'd1def8',\n", "# '21 Developed, Open Space': 'dec5c5',\n", "# '22 Developed, Low Intensity': 'd99282',\n", "# '23 Developed, Medium Intensity': 'eb0000',\n", "# '24 Developed High Intensity': 'ab0000',\n", "# '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n", "# '41 Deciduous Forest': '68ab5f',\n", "# '42 Evergreen Forest': '1c5f2c',\n", "# '43 Mixed Forest': 'b5c58f',\n", "# '51 Dwarf Scrub': 'af963c',\n", "# '52 Shrub/Scrub': 'ccb879',\n", "# '71 Grassland/Herbaceous': 'dfdfc2',\n", "# '72 Sedge/Herbaceous': 'd1d182',\n", "# '73 Lichens': 'a3cc51',\n", "# '74 Moss': '82ba9e',\n", "# '81 Pasture/Hay': 'dcd939',\n", "# '82 Cultivated Crops': 'ab6c28',\n", "# '90 Woody Wetlands': 'b8d9eb',\n", "# '95 Emergent Herbaceous Wetlands': '6c9fb8'\n", "# }\n", "# Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "# Print the list of system ids of all available NLCD images.\n", "dataset.aggregate_array(\"system:id\").getInfo()" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "# Select the seven NLCD epoches after 2000.\n", "years = [\"2001\", \"2004\", \"2006\", \"2008\", \"2011\", \"2013\", \"2016\", \"2019\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "# Get an NLCD image by year.\n", "def getNLCD(year):\n", " # Import the NLCD collection.\n", " dataset = ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\")\n", "\n", " # Filter the collection by year.\n", " nlcd = dataset.filter(ee.Filter.eq(\"system:index\", year)).first()\n", "\n", " # Select the land cover band.\n", " landcover = nlcd.select(\"landcover\")\n", " return landcover" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "## Create an NLCD image collection for the selected years.\n", "collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "# Print the list of system ids of selected NLCD images.\n", "collection.aggregate_array(\"system:id\").getInfo()" ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "# Create a list of labels to populate the dropdown list.\n", "labels = [f\"NLCD {year}\" for year in years]\n", "labels" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "# Add a split-panel map for visualizing NLCD land cover change.\n", "Map.ts_inspector(\n", " left_ts=collection, right_ts=collection, left_names=labels, right_names=labels\n", ")\n", "Map" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }