Custom colormaps for add_cog_layer()
#867
Answered
by
giswqs
jmarokhovsky
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
giswqs
Aug 7, 2024
Replies: 3 comments 5 replies
-
This seems a Titiler issue. See developmentseed/titiler#788 I tried the following code, it didn't work either. import leafmap
import json
m = leafmap.Map()
country_url = "https://clarkcga-aquaculture.s3.amazonaws.com/data/el_salvador/cover/El_Salvador_Landcover_2022.tif"
custom_cmap = {"0": "#000000", "1": "#008040", "2": "#ff0000", "3": "#ffff00", "4": "#8000ff", "5": "#8080ff", "6": "#00ff00", "7": "#c0c0c0", "8": "#16002d", "9": "#ff80ff", "10": "#b3ffb3", "11": "#ff8080", "12": "#ffffbf", "13": "#000080", "14": "#808000", "15": "#00ffff"}
m.add_cog_layer(country_url, "Foo", bidx=[1], opacity=0.8, colormap=json.dumps(custom_cmap))
m |
Beta Was this translation helpful? Give feedback.
2 replies
-
Seem like a leafmap issue. import json
import httpx
from folium import Map, TileLayer
titiler_endpoint = "https://titiler.xyz" # Developmentseed Demo endpoint. Please be kind.
url = "https://clarkcga-aquaculture.s3.amazonaws.com/data/el_salvador/cover/El_Salvador_Landcover_2022.tif"
custom_cmap = {"0": "#000000", "1": "#008040", "2": "#ff0000", "3": "#ffff00", "4": "#8000ff", "5": "#8080ff", "6": "#00ff00", "7": "#c0c0c0", "8": "#16002d", "9": "#ff80ff", "10": "#b3ffb3", "11": "#ff8080", "12": "#ffffbf", "13": "#000080", "14": "#808000", "15": "#00ffff"}
r = httpx.get(
f"{titiler_endpoint}/cog/WebMercatorQuad/tilejson.json",
params = {
"url": url,
"colormap": json.dumps(custom_cmap),
}
).json()
bounds = r["bounds"]
m = Map(
location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),
zoom_start=r["minzoom"] + 1
)
TileLayer(
tiles=r["tiles"][0],
opacity=1,
attr="Swisstopo"
).add_to(m)
m |
Beta Was this translation helpful? Give feedback.
3 replies
-
Fixed in #868 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
giswqs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed in #868