[GIS] Google Earth Engine: clip image into multiple regions defined by a shapefile and name the output by value in a column

clipgoogle-earth-engine

In Google Earth Engine I can clip the image using a shape drawn on the map canvas or by supplying a vector through Fusion table. This basically take the form.

var boundary = ee.FeatureCollection('ft:1W78nK9f3rkXBG3iuDdBidFHVGVnzvAqh7UEjRbeq');
var cliped = median_L8_2016.clip(boundary);
Export.image(median_L8_2016,'filename',

Suppose I have a vector file upload to Fusion table that contain three polygons and an attribute field called "district" with value as A, B, C for each polygon.

Is there any method in Google Earth Engine to clip the image output into different area and name the output file using the attribute. In this case I my expected output is three images named A, B, C.

The use case for this is plenty, for example, clip the study area into different province and district for further processing.

Currently I finish the image processing in GEE then download the result and do the clipping in FME which is working fine. But having the whole process in GEE would add much advantages to the workflow.

Best Answer

I show you two options: first make an ImageCollection in which each image has a property named 'district', and the second is what you asked, download every image. Replace YOUR_IMAGE with the name of your image, YOUR_FOLDER with the name of the folder you want the images in, and IMG_NAME with the base name you want to give to the images (it will attach the property afterwards).

EXPORTING is independent from TO IMAGECOLLECTION and viceversa.

As I couldn't access to your FeatureCollection, I tried with mine which had numbers, so it could be that you have to replace disS.toString() with only disS

// Feature Collection
var fc = ee.FeatureCollection("ft:1W78nK9f3rkXBG3iuDdBidFHVGVnzvAqh7UEjRbeq")

// Image
var img = YOUR_IMAGE

/////////////// TO IMAGECOLLECTION //////////////////////// 
// Function to make the Image Collection
var colFunc = function(feat) {
  var dis = feat.get("district")
  var clipped = img.clip(feat).set("district", dis)
  return clipped
}
// Map the FC to an IC 
var imcol = ee.ImageCollection(fc.map(colFunc))
///////////////////////////////////////////////////////////

////////////// EXPORTING ///////////////////////
var featlist = fc.getInfo()["features"]
for (var f in featlist) {
  var feat = ee.Feature(featlist[f])
  var dis = feat.get("district")
  var disS = dis.getInfo()
  var name = "IMG_NAME"      
  Export.image.toDrive({
    image: img,
    description: name+disS.toString(),
    folder: "YOUR_FOLDER",
    fileNamePrefix: name+disS.toString(),
    region: feat.geometry().bounds(),
    scale: 30
  })
}
////////////////////////////////////////////////
Related Question