Skip to content

Commit e74224a

Browse files
committed
moved color_values to utils
1 parent c232e3d commit e74224a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

xrspatial/utils.py

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datashader.transfer_functions as tf
66
import numpy as np
77
import xarray as xr
8+
from datashader.colors import rgb
89
from numba import cuda, jit
910

1011
try:
@@ -433,3 +434,13 @@ def canvas_like(
433434
out = cvs.raster(raster, **kwargs)
434435

435436
return out
437+
438+
439+
def color_values(agg, color_key, alpha=255):
440+
def _convert_color(c):
441+
r, g, b = rgb(c)
442+
return np.array([r, g, b, alpha]).astype(np.uint8).view(np.uint32)[0]
443+
444+
_converted_colors = {k: _convert_color(v) for k, v in color_key.items()}
445+
f = np.vectorize(lambda v: _converted_colors.get(v, 0))
446+
return tf.Image(f(agg.data))

0 commit comments

Comments
 (0)