File size: 1,670 Bytes
84e6e82
 
 
 
 
 
 
 
 
 
 
 
 
02c996d
84e6e82
 
 
 
02c996d
84e6e82
 
02c996d
84e6e82
 
02c996d
84e6e82
 
 
 
 
 
02c996d
84e6e82
 
 
 
 
 
 
 
 
 
 
02c996d
 
 
 
84e6e82
 
 
 
 
 
 
 
 
3096e30
84e6e82
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
import ee
import geemap

import solara


class Map(geemap.Map):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.add_ee_data()

    def add_ee_data(self):
        # Select the eight NLCD epochs after 2000.
        years = ["2001", "2004", "2006", "2008", "2011", "2013", "2016", "2019"]

        # Get an NLCD image by year.
        def getNLCD(year):
            # Import the NLCD collection.
            dataset = ee.ImageCollection("USGS/NLCD_RELEASES/2019_REL/NLCD")

            # Filter the collection by year.
            nlcd = dataset.filter(ee.Filter.eq("system:index", year)).first()

            # Select the land cover band.
            landcover = nlcd.select("landcover")
            return landcover

        ## Create an NLCD image collection for the selected years.
        collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))

        # Create a list of labels to populate the dropdown list.
        labels = [f"NLCD {year}" for year in years]

        # Add a split-panel map for visualizing NLCD land cover change.
        self.ts_inspector(
            left_ts=collection,
            right_ts=collection,
            left_names=labels,
            right_names=labels,
        )

        # Add the NLCD legend to the map.
        self.add_legend(
            title="NLCD Land Cover Type",
            builtin_legend="NLCD",
            height="460px",
            add_header=False,
        )


@solara.component
def Page():
    with solara.Column(style={"min-width": "500px"}):
        Map.element(
            center=[40, -100],
            zoom=4,
            height="600px",
        )