0

I would like to ask why I can't get the area value of the intersection even though I can see the intersection of the flooded area and the cropland part on the map. I'm not sure if it's a problem with the way my code is calculated or a problem with the threshold selection.

I attached my code as follows:

var geometry = ee.FeatureCollection("users/miaohu828/f_Dongxihuxuzhihuqu");
var before_start= '2020-06-20';
var before_end='2020-07-10';

var after_start='2020-08-23';
var after_end='2020-09-10';


var polarization = "VH"; 
var pass_direction = "ASCENDING"; 
var difference_threshold = 1.25; 

var aoi = ee.FeatureCollection(geometry);

var collection= ee.ImageCollection('COPERNICUS/S1_GRD')
  .filter(ee.Filter.eq('instrumentMode','IW'))
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', polarization))
  .filter(ee.Filter.eq('orbitProperties_pass',pass_direction)) 
  .filter(ee.Filter.eq('resolution_meters',10))
  .filterBounds(aoi)
  .select(polarization);
  
var before_collection = collection.filterDate(before_start, before_end);
var after_collection = collection.filterDate(after_start,after_end);


      function dates(imgcol){
        var range = imgcol.reduceColumns(ee.Reducer.minMax(), ["system:time_start"]);
        var printed = ee.String('from ')
          .cat(ee.Date(range.get('min')).format('YYYY-MM-dd'))
          .cat(' to ')
          .cat(ee.Date(range.get('max')).format('YYYY-MM-dd'));
        return printed;
      }

var before = before_collection.mosaic().clip(aoi);
var after = after_collection.mosaic().clip(aoi);

var smoothing_radius = 50;
var before_filtered = before.focal_mean(smoothing_radius, 'circle', 'meters');
var after_filtered = after.focal_mean(smoothing_radius, 'circle', 'meters');

var difference = after_filtered.divide(before_filtered);

var threshold = difference_threshold;
var difference_binary = difference.gt(threshold);
var swater = ee.Image('JRC/GSW1_0/GlobalSurfaceWater').select('seasonality');
      var swater_mask = swater.gte(10).updateMask(swater.gte(10));
      
      var flooded_mask = difference_binary.where(swater_mask,0);
      var flooded = flooded_mask.updateMask(flooded_mask);
     var connections = flooded.connectedPixelCount();    
      var flooded = flooded.updateMask(connections.gte(25));
     var DEM = ee.Image('WWF/HydroSHEDS/03VFDEM');
      var terrain = ee.Algorithms.Terrain(DEM);
      var slope = terrain.select('slope');
      var flooded = flooded.updateMask(slope.lt(5));

var flood_pixelarea = flooded.select(polarization)
  .multiply(ee.Image.pixelArea());

var flood_stats = flood_pixelarea.reduceRegion({
  reducer: ee.Reducer.sum(),              
  geometry: aoi,
  scale: 10, // native resolution 
  //maxPixels: 1e9,
  bestEffort: true
  });

var flood_area_ha = flood_stats
  .getNumber(polarization)
  .divide(10000)
  .round(); 
print(flood_area_ha,'flood_Area_ha')

var LC = ee.ImageCollection('MODIS/006/MCD12Q1')
  .filterDate('2014-01-01',after_end)
  .sort('system:index',false)
  .select("LC_Type1")
  .first()
  .clip(aoi);

var cropmask = LC
  .eq(12)
  .or(LC.eq(14))
var cropland = LC
  .updateMask(cropmask)
  
var MODISprojection = LC.projection();

var flooded_res = flooded
    .reproject({
    crs: MODISprojection
  });

var cropland_affected = flooded_res
  .updateMask(cropland)

var crop_pixelarea = cropland_affected
  .multiply(ee.Image.pixelArea()); //calcuate the area of each pixel 

var crop_stats = crop_pixelarea.reduceRegion({
  reducer: ee.Reducer.sum(), //sum all pixels with area information                
  geometry: aoi,
  scale: 500,
  maxPixels: 1e9
  });
  
var crop_area_ha = crop_stats
  .getNumber(polarization)
  .divide(10000);
print(crop_area_ha,'crop_area_ha')
Map.centerObject(aoi,8);
Map.addLayer(after_filtered, {min:-25,max:0}, 'After Flood',1);
// Cropland
var croplandVis = {
  min: 0,
  max: 14.0,
  palette: ['30b21c'],
};
Map.addLayer(cropland, croplandVis, 'Cropland',0)
// Flooded areas
Map.addLayer(flooded,{palette:"0000FF"},'Flooded areas');
// Affected cropland
Map.addLayer(cropland_affected, croplandVis, 'Affected Cropland'); 

Green part is the cropland, the blue part is the flood extent

1 Answer 1

1

Because you reprojected the flooded area to the MODIS projection and when it's computed in that projection, there is no flooding.

Don't use reproject; you don't need it anywhere in this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.