1

I want to visualize an image on the Earth Engine with an opacity ramp such that the low value pixels are completely transparent. Take as as example road intensity. I am trying to make an opacity ramp from fully transparent at 0 to alpha = 0.7 at the max value, ~1000.

The visParams argument in Map$addLayer() takes an opacity argument that is applied to the whole layer and accepts only a single value. I learned here that the 6-digit hex colour codes can include two additional digits for the alpha value, but this doesn't seem to translate to an opacity gradient when the colours are mapped to the values, while the opacity argument overwrites these hex-coded alpha values.

I am working from within R, using the rgee package:

roads <- ee$ImageCollection("projects/HII/v1/driver/roads")$ select("hii_road_driver")$ filterDate("2020-01-01")$ toBands()$ rename("roads_2020") Map$addLayer(roads$select("roads_2020"), visParams = list(min = 0, max = 1000, palette = c("#FFFFFF01", "#8B225270")), name = "raods") 

1 Answer 1

1

You can use ee.Image.updateMask. For example:

var alpha = roads.divide(1000).multiply(0.7) roads = roads.updateMask(alpha) 

https://code.earthengine.google.com/2237ccea27697d901644a2e6d71ba089

When you click on a given pixel using the inspector tool, you will see the value of the image and the value of the mask. For example:

roads_2020: 1000 (70%)

the (70%) is the mask of the image, which on the Map means the opacity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.