-
Notifications
You must be signed in to change notification settings - Fork 1
/
urban_land_use.py
46 lines (38 loc) · 1.54 KB
/
urban_land_use.py
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
from dask.diagnostics import ProgressBar
import xarray as xr
import xee
import ee
from .layer import Layer, get_utm_zone_epsg, get_image_collection
class UrbanLandUse(Layer):
"""
Attributes:
band: raster band used for data retrieval
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster)
"""
def __init__(self, band='lulc', spatial_resolution=5, **kwargs):
super().__init__(**kwargs)
self.band = band
self.spatial_resolution = spatial_resolution
def get_data(self, bbox):
ulu = ee.ImageCollection("projects/wri-datalab/cities/urban_land_use/V1")
# ImageCollection didn't cover the globe
if ulu.filterBounds(ee.Geometry.BBox(*bbox)).size().getInfo() == 0:
ulu_ic = ee.ImageCollection(ee.Image
.constant(0)
.clip(ee.Geometry.BBox(*bbox))
.rename('lulc')
)
else:
ulu_ic = ee.ImageCollection(ulu
.filterBounds(ee.Geometry.BBox(*bbox))
.select(self.band)
.reduce(ee.Reducer.firstNonNull())
.rename('lulc')
)
data = get_image_collection(
ulu_ic,
bbox,
self.spatial_resolution,
"urban land use"
).lulc
return data