Hi,
I want to download a clipped Sentinel2 image using ArcGIS Python API from Sentinel2 Views living atlas that was added as an image service by the ArcGIS enterprise Administrator. Since we don't have raster analytics service enabled. I want to download the clipped image as a .tif file and process it locally.
I tried 3 options:
Solution1: Arcpy Clip_management:
Solution2: Use Python requests
from datetime import date
import requests
#Authenticate to the enterprise GIS, Authentication class is created for that
authentication = Authentication()
gis = authentication.get_gis()
items = gis.content.search('sentinel2')
layer = items[0].layers[0]
query_boundary = layer.filter_by(geometry=intersects(gdf.SHAPE[0]))
fs = query_boundary.query()
result = fs.df
result = result[result.category==1]
result['acquisitiondate2'] = result.acquisitiondate.apply(lambda x: x.date())
result = result[(result['acquisitiondate2'] <=date(2024, 3, 1)) & (result['cloudcover']<0.25) & (date(2024, 1, 1)<= result['acquisitiondate2'])] #
result.sort_values(by='cloudcover', inplace=True)
item_id = result['objectid'].values[0]
item_name = result['name'].values[0]
selected = layer.filter_by(where=f'objectid={item_id}', geometry=intersects(gdf.SHAPE[0]), time=result['acquisitiondate'].values[0])
item_catalog = selected.catalog_item(item_id)
image = item_catalog.image(bbox=','.join([str(x) for x in gdf.SHAPE[0].as_shapely.bounds]), return_format= 'IMAGER',
bbox_sr='4326', image_format= 'tiff', interpolation= None, compression= 0)
response = requests.get(image['href'])
Problem: This solution works sometimes and doesn't work sometimes. When it doesn't work I get Invalid URL error -Please see below- (Example of generated URL: https://sentinel.arcgis.com/arcgis/rest/directories/arcgisoutput/Sentinel2_ImageServer/_ags_f2acff29...
Solution3: I decided to try ArcGIS REST API as in https://developers.arcgis.com/rest/services-reference/enterprise/download-rasters.htm
Problem: "Not having enough permissions" so I contacted our enterprise Admin they keep running into "Requested operation is not supported by this service" error, code 400 and extended code is -2147220222.
Kindly guide, thanks in advance.
Ghizlane