AOI in EVALSCRIPT

Is it possible to set inside EVALSCRIPT an area of interest.

Something like the input bounds with polygon geometry I guess, or even simple coordinate list.

I was hoping this could be specified for the collection filtering, but probably it is the wrong place for its definition.

I want to mask out (not retrieve those pixels) - I hope this is going to save me some processing units.

Hi,

The Evalscript is not the place to set a polygon geometry, as the code tells Sentinel Hub services how to process each pixel in your image, regardless of where it is located. The place to set the geometry is in the payload: the part of the request where you set parameters such as time-range, area of interest, sensor, etc…

The concept of Sentinel hub is to avoid processing areas you don’t need and only consume the data that is useful for you. By setting the geometry in your payload, you can save PUs.

Here is a list of resources that will help you understand the payload and how to set the geometry:

Lastly, here is an example of a request that will enable you to set a geometry:


curl -X POST https://services.sentinel-hub.com/api/v1/process \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer <YOUR_TOKEN_HERE>' \
 -d '{
  "input": {
    "bounds": {
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              12.472507,
              41.911471
            ],
            [
              12.506151,
              41.894862
            ],
            [
              12.462551,
              41.874925
            ],
            [
              12.472507,
              41.911471
            ]
          ]
        ]
      }
    },
    "data": [
      {
        "dataFilter": {
          "timeRange": {
            "from": "2024-05-18T00:00:00Z",
            "to": "2024-06-18T23:59:59Z"
          }
        },
        "type": "sentinel-2-l2a"
      }
    ]
  },
  "output": {
    "width": 512,
    "height": 576.366,
    "responses": [
      {
        "identifier": "default",
        "format": {
          "type": "image/jpeg"
        }
      }
    ]
  },
  "evalscript": "//VERSION=3\n\nfunction setup() {\n  return {\n    input: [\"B02\", \"B03\", \"B04\"],\n    output: { bands: 3 }\n  };\n}\n\nfunction evaluatePixel(sample) {\n  return [2.5 * sample.B04, 2.5 * sample.B03, 2.5 * sample.B02];\n}"
}'

Hope this helps!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.