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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "a6624f5d-8d87-41e1-949e-e01ea4bfd1fd",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"# Import libraries\n",
|
| 11 |
+
"import ee\n",
|
| 12 |
+
"import geemap"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": null,
|
| 18 |
+
"id": "5b37a322-6723-4eef-b248-eca735b2fb11",
|
| 19 |
+
"metadata": {},
|
| 20 |
+
"outputs": [],
|
| 21 |
+
"source": [
|
| 22 |
+
"# Create an interactive map by specifying the center (lat, lon) and zoom level (1-18).\n",
|
| 23 |
+
"Map = geemap.Map(center=[40, -100], zoom=4, height=\"800px\")\n",
|
| 24 |
+
"Map"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": null,
|
| 30 |
+
"id": "8b939af3-e209-44fd-94cb-48027334ad71",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [],
|
| 33 |
+
"source": [
|
| 34 |
+
"# Import the NLCD collection.\n",
|
| 35 |
+
"dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"# Filter the collection to the 2016 product.\n",
|
| 38 |
+
"nlcd2019 = dataset.filter(ee.Filter.eq('system:index', '2019')).first()\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"# Select the land cover band.\n",
|
| 41 |
+
"landcover = nlcd2019.select('landcover')\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"# Display land cover on the map.\n",
|
| 44 |
+
"Map.addLayer(landcover, {}, 'NLCD 2019')"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"execution_count": null,
|
| 50 |
+
"id": "bc45b8da",
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"outputs": [],
|
| 53 |
+
"source": [
|
| 54 |
+
"# Add the NLCD legend to the map.\n",
|
| 55 |
+
"Map.add_legend(title='NLCD Land Cover Classification', builtin_legend='NLCD')"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": null,
|
| 61 |
+
"id": "76b01ae9-d730-417f-88ff-143d0d4c20d6",
|
| 62 |
+
"metadata": {},
|
| 63 |
+
"outputs": [],
|
| 64 |
+
"source": [
|
| 65 |
+
"# # To add a custom legend to the map, uncomment the following code and modify the legend dictionary.\n",
|
| 66 |
+
"# legend_dict = {\n",
|
| 67 |
+
"# '11 Open Water': '466b9f',\n",
|
| 68 |
+
"# '12 Perennial Ice/Snow': 'd1def8',\n",
|
| 69 |
+
"# '21 Developed, Open Space': 'dec5c5',\n",
|
| 70 |
+
"# '22 Developed, Low Intensity': 'd99282',\n",
|
| 71 |
+
"# '23 Developed, Medium Intensity': 'eb0000',\n",
|
| 72 |
+
"# '24 Developed High Intensity': 'ab0000',\n",
|
| 73 |
+
"# '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n",
|
| 74 |
+
"# '41 Deciduous Forest': '68ab5f',\n",
|
| 75 |
+
"# '42 Evergreen Forest': '1c5f2c',\n",
|
| 76 |
+
"# '43 Mixed Forest': 'b5c58f',\n",
|
| 77 |
+
"# '51 Dwarf Scrub': 'af963c',\n",
|
| 78 |
+
"# '52 Shrub/Scrub': 'ccb879',\n",
|
| 79 |
+
"# '71 Grassland/Herbaceous': 'dfdfc2',\n",
|
| 80 |
+
"# '72 Sedge/Herbaceous': 'd1d182',\n",
|
| 81 |
+
"# '73 Lichens': 'a3cc51',\n",
|
| 82 |
+
"# '74 Moss': '82ba9e',\n",
|
| 83 |
+
"# '81 Pasture/Hay': 'dcd939',\n",
|
| 84 |
+
"# '82 Cultivated Crops': 'ab6c28',\n",
|
| 85 |
+
"# '90 Woody Wetlands': 'b8d9eb',\n",
|
| 86 |
+
"# '95 Emergent Herbaceous Wetlands': '6c9fb8'\n",
|
| 87 |
+
"# }\n",
|
| 88 |
+
"# Map.add_legend(legend_title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"cell_type": "code",
|
| 93 |
+
"execution_count": null,
|
| 94 |
+
"id": "44c16a8e-7d13-4e46-bfaf-12178aa1b0be",
|
| 95 |
+
"metadata": {},
|
| 96 |
+
"outputs": [],
|
| 97 |
+
"source": [
|
| 98 |
+
"# # Print the list of system ids of all available NLCD images.\n",
|
| 99 |
+
"# dataset.aggregate_array(\"system:id\").getInfo()"
|
| 100 |
+
]
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"cell_type": "code",
|
| 104 |
+
"execution_count": null,
|
| 105 |
+
"id": "a49fbecc-b0bf-4010-83b1-8628f5b05459",
|
| 106 |
+
"metadata": {},
|
| 107 |
+
"outputs": [],
|
| 108 |
+
"source": [
|
| 109 |
+
"# Select the seven NLCD epoches after 2000.\n",
|
| 110 |
+
"years = ['2001', '2004', '2006', '2008', '2011', '2013', '2016', '2019']"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"cell_type": "code",
|
| 115 |
+
"execution_count": null,
|
| 116 |
+
"id": "cf361b54",
|
| 117 |
+
"metadata": {},
|
| 118 |
+
"outputs": [],
|
| 119 |
+
"source": [
|
| 120 |
+
"# Get an NLCD image by year.\n",
|
| 121 |
+
"def getNLCD(year):\n",
|
| 122 |
+
" # Import the NLCD collection.\n",
|
| 123 |
+
" dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')\n",
|
| 124 |
+
"\n",
|
| 125 |
+
" # Filter the collection by year.\n",
|
| 126 |
+
" nlcd = dataset.filter(ee.Filter.eq('system:index', year)).first()\n",
|
| 127 |
+
" \n",
|
| 128 |
+
" # Select the land cover band.\n",
|
| 129 |
+
" landcover = nlcd.select('landcover');\n",
|
| 130 |
+
" return landcover"
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"cell_type": "code",
|
| 135 |
+
"execution_count": null,
|
| 136 |
+
"id": "6c0bbf8a-d4c9-402e-b0ff-b53f14d836bf",
|
| 137 |
+
"metadata": {},
|
| 138 |
+
"outputs": [],
|
| 139 |
+
"source": [
|
| 140 |
+
"## Create an NLCD image collection for the selected years.\n",
|
| 141 |
+
"collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))"
|
| 142 |
+
]
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"cell_type": "code",
|
| 146 |
+
"execution_count": null,
|
| 147 |
+
"id": "3dcd6df2",
|
| 148 |
+
"metadata": {},
|
| 149 |
+
"outputs": [],
|
| 150 |
+
"source": [
|
| 151 |
+
"# # Print the list of system ids of selected NLCD images.\n",
|
| 152 |
+
"# collection.aggregate_array('system:id').getInfo()"
|
| 153 |
+
]
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"cell_type": "code",
|
| 157 |
+
"execution_count": null,
|
| 158 |
+
"id": "0a5eac53",
|
| 159 |
+
"metadata": {},
|
| 160 |
+
"outputs": [],
|
| 161 |
+
"source": [
|
| 162 |
+
"# Create a list of labels to populate the dropdown list. \n",
|
| 163 |
+
"labels = [f'NLCD {year}' for year in years]\n",
|
| 164 |
+
"# labels"
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"cell_type": "code",
|
| 169 |
+
"execution_count": null,
|
| 170 |
+
"id": "78e89ca5",
|
| 171 |
+
"metadata": {},
|
| 172 |
+
"outputs": [],
|
| 173 |
+
"source": [
|
| 174 |
+
"# Add a split-panel map for visualizing NLCD land cover change.\n",
|
| 175 |
+
"Map.ts_inspector(left_ts=collection, right_ts=collection, left_names=labels, right_names=labels)\n",
|
| 176 |
+
"# Map"
|
| 177 |
+
]
|
| 178 |
+
}
|
| 179 |
+
],
|
| 180 |
+
"metadata": {
|
| 181 |
+
"kernelspec": {
|
| 182 |
+
"display_name": "Python 3",
|
| 183 |
+
"language": "python",
|
| 184 |
+
"name": "python3"
|
| 185 |
+
},
|
| 186 |
+
"language_info": {
|
| 187 |
+
"codemirror_mode": {
|
| 188 |
+
"name": "ipython",
|
| 189 |
+
"version": 3
|
| 190 |
+
},
|
| 191 |
+
"file_extension": ".py",
|
| 192 |
+
"mimetype": "text/x-python",
|
| 193 |
+
"name": "python",
|
| 194 |
+
"nbconvert_exporter": "python",
|
| 195 |
+
"pygments_lexer": "ipython3",
|
| 196 |
+
"version": "3.10.8"
|
| 197 |
+
},
|
| 198 |
+
"toc": {
|
| 199 |
+
"base_numbering": 1,
|
| 200 |
+
"nav_menu": {},
|
| 201 |
+
"number_sections": true,
|
| 202 |
+
"sideBar": true,
|
| 203 |
+
"skip_h1_title": false,
|
| 204 |
+
"title_cell": "Table of Contents",
|
| 205 |
+
"title_sidebar": "Contents",
|
| 206 |
+
"toc_cell": false,
|
| 207 |
+
"toc_position": {},
|
| 208 |
+
"toc_section_display": true,
|
| 209 |
+
"toc_window_display": false
|
| 210 |
+
}
|
| 211 |
+
},
|
| 212 |
+
"nbformat": 4,
|
| 213 |
+
"nbformat_minor": 5
|
| 214 |
+
}
|