Flood Mapping using Sentinel-1 SAR data in Google Earth Engine

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • الحصول على الكود
    // Define the date ranges for pre-flood and post-flood analysis
    var beforeStart = '2023-08-15';
    var beforeEnd = '2023-09-13'; // End date of the pre-flood period (modifiable)
    var afterStart = '2023-09-14'; // Start date of the post-flood period (modifiable)
    var afterEnd = '2023-09-29'; // End date of the post-flood period (modifiable)
    // Define the location of Derna using coordinates
    var dernaPoint = ee.Geometry.Point([22.63204547765079,32.751539758574786]);
    var bufferDistance = 10000; // Buffer distance in meters, can be adjusted
    var geometry = dernaPoint.buffer(bufferDistance);
    // Add the geometry to the map for visualization
    Map.addLayer(geometry, {color: 'grey'}, 'Derna Area');
    // Filter and select the SAR image collection for analysis
    var collection = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filter(ee.Filter.eq('instrumentMode','IW'))
    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
    .filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
    .filter(ee.Filter.eq('resolution_meters',10))
    .filter(ee.Filter.bounds(geometry))
    .select(['VV', 'VH']);
    // Filter the collection for the pre-flood and post-flood periods
    var beforeCollection = collection
    .filter(ee.Filter.date(beforeStart, beforeEnd));
    var afterCollection = collection
    .filter(ee.Filter.date(afterStart, afterEnd));
    // Mosaic the images and clip them to the study area
    var before = beforeCollection.mosaic().clip(geometry);
    var after = afterCollection.mosaic().clip(geometry);
    // Function to add a ratio band (VV/VH) to the images
    var addRatioBand = function(image) {
    var ratioBand = image.select('VV').divide(image.select('VH')).rename('VV/VH');
    return image.addBands(ratioBand);
    };
    // Calculate the ratio bands for before and after images
    var beforeRgb = addRatioBand(before);
    var afterRgb = addRatioBand(after);
    // Visualization parameters for the map
    var visParams = {min:[-25, -25, 0] ,max:[0, 0, 2]};
    // Center the map on the study area and add the layers for visualization
    Map.centerObject(geometry, 10);
    Map.addLayer(beforeRgb, visParams, 'Before Floods');
    Map.addLayer(afterRgb, visParams, 'After Floods');
    // Define a function to export an image to Google Drive
    var exportImage = function(image, name) {
    var exportOptions = {
    scale: 10, // Adjust the scale as needed
    region: geometry,
    format: 'GeoTIFF', // Change the format if needed
    fileFormat: 'GeoTIFF', // Change the file format if needed
    maxPixels: 1e13 // Adjust as needed
    };
    Export.image.toDrive({
    image: image,
    description: name,
    folder: 'YourFolderName', // Specify your Google Drive folder
    fileNamePrefix: name,
    crs: 'EPSG:4326',
    crsTransform: [10, 0, 0, 0, -10, 0], // Adjust the CRS transform as needed
    maxPixels: 1e13 // Adjust as needed
    });
    };
    // Add a download button to export the "Before Floods" image
    var downloadBeforeButton = ui.Button('Download Before Floods', function() {
    exportImage(beforeRgb, 'Before_Floods');
    });
    downloadBeforeButton.style().set({position: 'top-right'});
    Map.add(downloadBeforeButton);
    // Add a download button to export the "After Floods" image
    var downloadAfterButton = ui.Button('Download After Floods', function() {
    exportImage(afterRgb, 'After_Floods');
    });
    downloadAfterButton.style().set({position: 'top-right'});
    Map.add(downloadAfterButton);

Комментарии • 1