Skip to content

Commit fd7eeb7

Browse files
committed
feat(raster-api): new colormap for NLCD data
1 parent 1d21109 commit fd7eeb7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

raster_api/runtime/src/cmap_data/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,55 @@ cmap_vals = my_cmap(x)[:, :]
2828
cmap_uint8 = (cmap_vals * 255).astype('uint8')
2929
np.save("epa-ghgi-ch4.npy", cmap_uint8)
3030
```
31+
32+
##### NLCD colormap
33+
34+
refs:
35+
36+
- https://www.mrlc.gov/data/legends/national-land-cover-database-class-legend-and-description
37+
- https://github.com/NASA-IMPACT/veda-backend/issues/429
38+
39+
```python
40+
import rasterio
41+
from rio_tiler.colormap import parse_color
42+
import numpy as np
43+
44+
# The COGs in the nlcd-annual-conus collection store an internal colormap
45+
nlcd_filename = "/vsis3/veda-data-store/nlcd-annual-conus/nlcd_2001_cog_v2.tif"
46+
47+
# These categories are only used to set transparency and document categories defined in colormap
48+
# https://www.mrlc.gov/data/legends/national-land-cover-database-class-legend-and-description
49+
nlcd_categories = {
50+
"11": "Open Water",
51+
"12": "Perennial Ice/Snow",
52+
"21": "Developed, Open Space",
53+
"22": "Developed, Low Intensity",
54+
"23": "Developed, Medium Intensity",
55+
"24": "Developed, High Intensity",
56+
"31": "Barren Land (Rock/Sand/Clay)",
57+
"41": "Deciduous Forest",
58+
"42": "Evergreen Forest",
59+
"43": "Mixed Forest",
60+
"51": "Dwarf Scrub",
61+
"52": "Shrub/Scrub",
62+
"71": "Grassland/Herbaceous",
63+
"72": "Sedge/Herbaceous",
64+
"73": "Lichens",
65+
"74": "Moss",
66+
"81": "Pasture/Hay",
67+
"82": "Cultivated Crops",
68+
"90": "Woody Wetlands",
69+
"95": "Emergent Herbaceous Wetlands"
70+
}
71+
72+
with rasterio.open(nlcd_filename) as r:
73+
internal_colormap = r.colormap(1)
74+
75+
cmap = np.zeros((256, 4), dtype=np.uint8)
76+
cmap[:] = np.array([0, 0, 0, 255])
77+
for c, v in internal_colormap.items():
78+
if str(c) in nlcd_categories.keys():
79+
cmap[c] = np.array(parse_color(v))
80+
81+
np.save("nlcd.npy", cmap)
82+
```
1.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)