I’m getting started accessing the OGC API through Python to download Sentinel data.
I would like to know if it is possible to make a request for data clipped to a polygon instead of a rectangular bounding box.
It’s possible to do in the EO browser, but I haven’t found a way to do it directly from the API.
I can of course download get the image cut to the bounding box, and then clip it, but being able to directly download only the data I need would save me some computer ressources, and possibly some processing units.
The way I set a polygon in my Python OGC requests is by using the custom_url_params argument in my request. You can find more information here.
You will still need to set a bounding box, but you can add your polygon as an optional parameter. Here is a code snippet in Python:
# Set bounding box
bbox_loc = BBox(bbox=[7.3994, 43.7190, 7.4531, 43.7564], crs=CRS.WGS84)
# Polygon WKT (pasted polygon WKT, you can import a file using shapely for example)
geometryWKT = "POLYGON((7.41877555847168 43.72459139811755,7.410106658935547 43.7294293330051,7.414312362670898 43.732158252099964,7.413797378540039 43.734700996616425,7.423152923583985 43.74102638042922,7.432508468627931 43.735693257872555,7.41877555847168 43.72459139811755))"
# WMS request
request = WmsRequest(data_source=DataSource.SENTINEL2_L1C,
When making a request for data clipped to a polygon, it’s a good idea to activate the transparency for the areas outside the polygon in the Evalscript that you are calling. Here I am requesting the layer 1_TRUE_COLOR from my dashboard, which has the following evalscript:
Thank you very much for taking the time to write such a comprehensive answer, this is exactly what I was looking for, and you explained it very clearly. I hope I can get enough experience to one day give this kind of contribution to the forum.
There are a couple of inconsistencies in the evalscript you posted, but these can be easily fixed.
The lines starting from if (ndvi<-0) statement are never called because your first if/else statement catches all situations.
Your return an array of 2 values in your first if statement, and 3 values in your else, but have set your output bands to 2 in the setup function (see documentation).
It depends what you want to return: the NDVI values or a visualisation of NDVI. If you want to return a visualisation of NDVI with only data showing (where dataMask = 1), you would want to set your output bands to 4 and return 4 values in your evaluatePixel function, where the first three correspond to RGB values, and the last one is the dataMask band (because 0 = noData, and will be interpreted as transparent).