Skip to main content

Hi,

I have polygons in geopackage format belonging to 20 different fields. According to these polygons, for each field, I want to download RGB tif by clipping all images between June 2022 and August 2022 according to aoi. I want to do this with process api and I couldn’t find an example.

I would be very happy if you could help.

I have a .gpkg file with 20 polygons as input and I want it to clip and download all images in the date range for each polygon, the example code below downloads a single image for 1 polygon.


from sentinelhub import SentinelHubRequest, DataCollection, MimeType, CRS, BBox, SHConfig
import geopandas as gpd

evalscript = """
//VERSION=3

function setup() {
return {
input: ["B02", "B03", "B04"],
output: { bands: 3 }
};
}

function evaluatePixel(sample) {
return [2.5 * sample.B04, 2.5 * sample.B03, 2.5 * sample.B02];
}
"""
polygon_file = ''
polygons = gpd.read_file(polygon_file)

data_folder = ''
for index, polygon in polygons.iterrows():
bbox = BBox(polygon.geometry.bounds, crs=CRS.WGS84)

request = SentinelHubRequest(
evalscript=evalscript,
data_folder=data_folder,
input_data=[
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
time_interval=('2022-06-01', '2022-08-01'),
),
],
responses=[
SentinelHubRequest.output_response('default', MimeType.TIFF),
],
bbox=bbox,
size=[54.138500586007524, 26.327059572684316],
config=config
)

Hi & welcome to the forum 😃 apologies for the slow reply.


I would propose reading through this example that uses the Sentinel Hub Python package.


You can use the example on each of your areas of interest to request and download the multiple images you require for each of your areas. The example uses a bounding box but you can adapt the code to use a polygon as an input parameter in your payload instead.


If you are still stuck, then we’ll be happy to help you write the script to work for you. 🙂


Hi William,


Thank you for your response 🙂 I saw the example you showed but in that example it is getting multiple images for a single bbox. I can’t manage to download multiple images for multiple polygons, I’m stuck. I would be very happy if you could help with an example script. My input parameters are:


Data source: Sentinel L2A

Time interval: Every image between June 2022-August 2022

Geometry: 20 polygons in .gpkg

Bands: RGB

Data save: local folder


Hi,


I’ve put together an example that you should be able to adapt for your purposes:


In the first code snippet (below) you should note:


  • an additional argument in the get_true_color_request function called save_data=True

  • the data folder parameter; the folder you wish to save your data.

  • the bbox parameter has been replaced by geometry

  • If you require a certain resolution you can replace the size parameter with the xres and yres parameters.

geometry = Geometry(geometry={"type":"Polygon","coordinates":":[12.473884,41.931912],]12.518678,41.921183],]12.479548,41.888605],]12.44693,41.894994],]12.432695,41.901766],]12.456722,41.911603],]12.459468,41.930379],]12.473884,41.931912]]]}, crs=CRS.WGS84)

def get_true_color_request(time_interval, save_data=True):
return SentinelHubRequest(
data_folder="test_dir",
evalscript=evalscript_true_color,
input_data=a
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L1C,
time_interval=time_interval,
mosaicking_order=MosaickingOrder.LEAST_CC,
)
],
responses=sSentinelHubRequest.output_response("default", MimeType.TIFF)],
geometry=geometry,
size=e712.5511167355081, 482.0913187784445],
config=config,
)

You can then use the same code block as in the previous example to request and download each image in your time range.


Two notes:


  • my example will request one image per monthly time window, and as specified in the request this is the least cloudy acquisition in that time period. This parameter is just a list generated by a start and end date with the number of chunks specified by myself. This list can be replaced with a list of the acquisition dates that you require for your application.

  • As you are requesting a lot of data over a long period of time, I would recommend running your code for each of your 20 polygons individually. Like in this example, that loops over the monthly time windows, you can also loop over each of your individual polygons.

Hope this helps you out 👍


Reply