1

I am working on analyzing satellite imagery in Earth Engine for an Area of Interest (AOI) specified by a shapefile polygon using python 3 on a jupyter notebook. However, the satellite images retrieved using the COPERNICUS/S2 image collection only partially cover the AOI. This is because the images are split into a fixed grid, and some tiles never get completely covered by a single image. As shown below;

The retrieve image does not cover the aoi

To solve this issue, I want to create an algorithm that first checks whether the retrieved images cover the AOI completely or not. If they don't, I want to mosaic all intersecting images to get the full AOI extent while retaining the band properties for analysis. But as you can observe in the snippet below, it is not working as desired

The image was only found in the area circled with RED

Here's the code I've tried so far:

initiazing map

Map = geemap.Map()

# Map.add_basemap('SATELLITE')
Map.add_basemap('ROADMAP')


shapefile_path = r"..\data\data_ghana\upper denkyira west\upper denkyira west.shp"
aoi = geemap.shp_to_ee(shapefile_path)
Map.addLayer(aoi,{},'AOI')


s2 = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED") \
    .filterBounds(aoi) \
    .filterDate("2019-01-01","2019-12-31")\
    .sort('CLOUDY_PIXEL_PERCENTAGE')

# Check whether the retrieved images cover the AOI completely
if s2.geometry().contains(aoi):
    # Images cover the AOI completely, proceed with analysis
    s2_aoi = s2.first().clip(aoi)
    print("AOI is completely within the Tile")
else:
    # Images do not cover the AOI completely, mosaic intersecting images
    s2_aoi = s2.mosaic().clip(aoi)
    print("AOI not covered")

Map.addLayer(s2_aoi,{},"s2")

Can anyone suggest an algorithm that can mosaic all intersecting images to cover the full AOI extent while retaining the band properties for analysis?

kojo justine
  • 103
  • 1
  • 12

0 Answers0