Custom scripts: check if pixel belongs to bbox or polygon?

Is is possible within a custom script to retrieve the coordinates of the current pixel or to check whether it belongs to some bbox or shapefile?


All the pixels evaluated in the evalscript evaluatePixel function are within the bounding box provided with the request, or within the bounding box of the geometry, provided with the request. Note that particular pixels within you bbox might not have data (e.g. border of a tile/orbit/byoc…).

PS: If you explain a bit better why would you need something like that, we might have a better answer.

Basically my motivation is that I would like to “force” all pixels being whitin a certain polygon to be water pixels, even if NDWI tells me no because of a high concentration of (floating) algae.

It is (currently?) not possible to feed the mask to the Process/Stat-API request.

So you are left with requesting data over a particular geometry. Would that work? If your request contains a geometry, then the result will contain an intersection of available data (over your request time-window) with your requested geometry.

One option is to ingest “water mask” as a BYOC layer and then use it within your script as a data fusion.

1 Like

batic, I would like to use this as part of a visualization by means of a WMS map (leaflet) so your suggestion would not help in fact. I suspected it would not be possible indeed. Thanks anyway!

gmilcinski, that is an interesting workaround! I may look into this thanks.

Processing API can be used in Leaflet in a similar way the WMS is used. It requires extending a Leaflet class, but once that’s done, it can be used in a same way. Check the examples in my answers to this forum post.

1 Like