Spaces:
Running
Running
File size: 5,987 Bytes
0ea57c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "a6624f5d-8d87-41e1-949e-e01ea4bfd1fd",
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5b37a322-6723-4eef-b248-eca735b2fb11",
"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, height=\"800px\")\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b939af3-e209-44fd-94cb-48027334ad71",
"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",
"nlcd2019 = dataset.filter(ee.Filter.eq('system:index', '2019')).first()\n",
"\n",
"# Select the land cover band.\n",
"landcover = nlcd2019.select('landcover')\n",
"\n",
"# Display land cover on the map.\n",
"Map.addLayer(landcover, {}, 'NLCD 2019')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc45b8da",
"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": "76b01ae9-d730-417f-88ff-143d0d4c20d6",
"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(legend_title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44c16a8e-7d13-4e46-bfaf-12178aa1b0be",
"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": "a49fbecc-b0bf-4010-83b1-8628f5b05459",
"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": "cf361b54",
"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": "6c0bbf8a-d4c9-402e-b0ff-b53f14d836bf",
"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": "3dcd6df2",
"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": "0a5eac53",
"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": "78e89ca5",
"metadata": {},
"outputs": [],
"source": [
"# Add a split-panel map for visualizing NLCD land cover change.\n",
"Map.ts_inspector(left_ts=collection, right_ts=collection, left_names=labels, right_names=labels)\n",
"# Map"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|