File size: 3,463 Bytes
4c82f8a |
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 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[](https://colab.research.google.com/github/opengeos/solara-geemap/blob/main/notebooks/04_split_map.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U geemap solara"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
"import solara\n",
"\n",
"\n",
"class Map(geemap.Map):\n",
" def __init__(self, **kwargs):\n",
" super().__init__(**kwargs)\n",
" self.add_ee_data()\n",
"\n",
" def add_ee_data(self):\n",
" # Select the eight NLCD epochs after 2000.\n",
" years = [\"2001\", \"2004\", \"2006\", \"2008\", \"2011\", \"2013\", \"2016\", \"2019\"]\n",
"\n",
" # 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\n",
"\n",
" ## Create an NLCD image collection for the selected years.\n",
" collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))\n",
"\n",
" # Create a list of labels to populate the dropdown list.\n",
" labels = [f\"NLCD {year}\" for year in years]\n",
"\n",
" # Add a split-panel map for visualizing NLCD land cover change.\n",
" self.ts_inspector(\n",
" left_ts=collection,\n",
" right_ts=collection,\n",
" left_names=labels,\n",
" right_names=labels,\n",
" )\n",
"\n",
" # Add the NLCD legend to the map.\n",
" self.add_legend(\n",
" title=\"NLCD Land Cover Type\",\n",
" builtin_legend=\"NLCD\",\n",
" height=\"460px\",\n",
" add_header=False,\n",
" )\n",
"\n",
"\n",
"@solara.component\n",
"def Page():\n",
" with solara.Column(style={\"min-width\": \"500px\", \"isolation\": \"isolate\"}):\n",
" Map.element(\n",
" center=[40, -100],\n",
" zoom=4,\n",
" height=\"600px\",\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Page()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geo",
"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.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|