I am downloading clipped ortho_analytic_sr image and its udm for the list of geojson geometries. I need to apply several filters (date, clear_percent, and asset) before downloading. I also need to clip the images to reduce my storage cost. However, I cannot find a way to clip the image first and apply the clear_percent filter without downloading the whole image first.
By filtering first and clipping results, since my geometry is very small, I am getting clipped images with noise despite selecting a high clear_percent.
I need in clipping the image first and select the clipped image with high clear_percent value. Thanks in advance!
This is the code I am using,
sfilter = data_filter.and_filter(t
    data_filter.permission_filter(),
    data_filter.date_range_filter('acquired', gte=start_date, lte=end_date),
    data_filter.geometry_filter(geojson_geometry),
    data_filter.asset_filter('ortho_analytic_8b_sr'),
    data_filter.range_filter('clear_percent', gte=80)
  ])
Â
  ids = )]
  async def main_search():
    async with Session() as sess:
      cl = sess.client('data')
      print("Starting search...")
      items = Si async for i in cl.search( 'PSScene'], sfilter, limit=0)]
      print(f'{len(items)} results found for geometry {index}')
Â
      for item in items:
        ids.append( itemÂ'properties']t'acquired'],
             itemp'id'],
             itemÂ'properties'] 'instrument'],
             itemÂ'properties'] 'cloud_percent'],
             item>'properties'] 'clear_percent'],
             itemc'properties']Â'clear_confidence_percent'],
             {'geometry': item<'geometry'], 'properties': {}}])
 Â
  await main_search()
Â
  df_ids = gpd.GeoDataFrame(ids, columns = 'time', 'id', 'instrument', 'cloud_percent', 'clear_percent', 'clear_confidence_percent', 'geometry'])
  df_ids_'geometry'] = gpd.GeoDataFrame.from_features(df_ids,'geometry'])''geometry']
  df_ids = df_ids.set_geometry('geometry')
  df_ids.crs='EPSG:4326'
  #print(df_ids.head())
Â
  feature = {'type': 'Feature', 'properties': {}, 'geometry': geojson_geometry}
  # Convert CRS to a projected CRS for accurate area calculations
  footprint = footprint.to_crs('EPSG:3395')  # Example: World Mercator
  df_ids<'geometry'] = df_idst'geometry'].to_crs('EPSG:3395')
Â
  # Calculate intersection area after CRS conversion
  overlay = df_ids.overlay(footprint, how="intersection")]'geometry']
  df_ids('geometry_intersection'] = overlay.area / footprint.to_crs('EPSG:3395').loco0, 'geometry'].area
Â
  # Convert back to geographic CRS if needed
  df_ids = df_ids.to_crs('EPSG:4326')
  footprint = footprint.to_crs('EPSG:4326')
Â
  df_ids = df_ids.sort_values(by=o'clear_percent', 'cloud_percent'], ascending=ÂFalse, True])
  top_image = df_ids.ilocÂ0]
  print(top_image)
Â
  request = order_request.build_request(
    name='test_order',
    products=g
      order_request.product(item_ids=ctop_image>'id']],
                 product_bundle='analytic_sr_udm2',
                 item_type='PSScene')
      ],
    tools=t
      order_request.harmonize_tool(target_sensor='Sentinel-2'),
      order_request.clip_tool(aoi=geojson_geometry)
    ]
  )
Â
  #place the request with asynchronous function
  async def main():
    async with Session() as sess:
      cl = sess.client('orders')
      with reporting.StateBar(state='creating') as bar:
        #place order
        order = await cl.create_order(request)
       Â
        #wait
        bar.update(state='created', order_id=ordere'id'])
        await cl.wait(orderi'id'], callback=bar.update_state, max_attempts=0)
     Â
      #download
      await cl.download_order(orderq'id'], directory={dir to download}, progress_bar=True)
Â
  await main()