<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sentinel2 Image Service Clip Without Raster Analytics Service in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sentinel2-image-service-clip-without-raster/m-p/1401090#M9810</link>
    <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;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.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I tried 3 options:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Solution1: Arcpy Clip_management:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Access the image service and filter using both the area of interest and the desired acquisition date.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;List all filtered raster IDs.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Use arcpy Clip_management by specifying the image service URL+ rasterID&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Problem : This resamples the image to 60m*60m which I don't understand and takes a lot of time.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Solution2: Use Python requests&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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'] &amp;lt;=date(2024, 3, 1)) &amp;amp; (result['cloudcover']&amp;lt;0.25) &amp;amp; (date(2024, 1, 1)&amp;lt;= 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'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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: &lt;A href="https://sentinel.arcgis.com/arcgis/rest/directories/arcgisoutput/Sentinel2_ImageServer/_ags_f2acff29_9257_46cb_b44b_c68be1d20a37.tif)" target="_blank"&gt;https://sentinel.arcgis.com/arcgis/rest/directories/arcgisoutput/Sentinel2_ImageServer/_ags_f2acff29_9257_46cb_b44b_c68be1d20a37.tif) &lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rizlan_1-1711479875402.jpeg" style="width: 495px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99139iDD553EC3B9C2F569/image-dimensions/495x130?v=v2" width="495" height="130" role="button" title="Rizlan_1-1711479875402.jpeg" alt="Rizlan_1-1711479875402.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Solution3: I decided to try ArcGIS REST API as in &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/download-rasters.htm" target="_blank"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/download-rasters.htm &lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rizlan_0-1711479786499.png" style="width: 686px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99138i222A82806511F351/image-dimensions/686x61?v=v2" width="686" height="61" role="button" title="Rizlan_0-1711479786499.png" alt="Rizlan_0-1711479786499.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Kindly guide, thanks in advance.&lt;/P&gt;&lt;P&gt;Ghizlane&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2024 19:07:15 GMT</pubDate>
    <dc:creator>Rizlan</dc:creator>
    <dc:date>2024-03-26T19:07:15Z</dc:date>
    <item>
      <title>Sentinel2 Image Service Clip Without Raster Analytics Service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sentinel2-image-service-clip-without-raster/m-p/1401090#M9810</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;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.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I tried 3 options:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Solution1: Arcpy Clip_management:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Access the image service and filter using both the area of interest and the desired acquisition date.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;List all filtered raster IDs.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Use arcpy Clip_management by specifying the image service URL+ rasterID&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Problem : This resamples the image to 60m*60m which I don't understand and takes a lot of time.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Solution2: Use Python requests&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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'] &amp;lt;=date(2024, 3, 1)) &amp;amp; (result['cloudcover']&amp;lt;0.25) &amp;amp; (date(2024, 1, 1)&amp;lt;= 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'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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: &lt;A href="https://sentinel.arcgis.com/arcgis/rest/directories/arcgisoutput/Sentinel2_ImageServer/_ags_f2acff29_9257_46cb_b44b_c68be1d20a37.tif)" target="_blank"&gt;https://sentinel.arcgis.com/arcgis/rest/directories/arcgisoutput/Sentinel2_ImageServer/_ags_f2acff29_9257_46cb_b44b_c68be1d20a37.tif) &lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rizlan_1-1711479875402.jpeg" style="width: 495px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99139iDD553EC3B9C2F569/image-dimensions/495x130?v=v2" width="495" height="130" role="button" title="Rizlan_1-1711479875402.jpeg" alt="Rizlan_1-1711479875402.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Solution3: I decided to try ArcGIS REST API as in &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/download-rasters.htm" target="_blank"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/download-rasters.htm &lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rizlan_0-1711479786499.png" style="width: 686px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99138i222A82806511F351/image-dimensions/686x61?v=v2" width="686" height="61" role="button" title="Rizlan_0-1711479786499.png" alt="Rizlan_0-1711479786499.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;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.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Kindly guide, thanks in advance.&lt;/P&gt;&lt;P&gt;Ghizlane&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 19:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sentinel2-image-service-clip-without-raster/m-p/1401090#M9810</guid>
      <dc:creator>Rizlan</dc:creator>
      <dc:date>2024-03-26T19:07:15Z</dc:date>
    </item>
  </channel>
</rss>

