exportByFeat(img, fc, prop, folder, name, scale, dataType, **kwargs):

Export an image clipped by features (Polygons). You can use the same arguments as the original function ee.batch.export.image.toDrive

Parameters

  • img: image to clip
  • fc: feature collection
  • prop: name of the property of the features to paste in the image
  • folder: same as ee.Export
  • name: name of the resulting image. If None uses image's ID
  • scale: same as ee.Export. Default to 1000
  • dataType: as downloaded images must have the same data type in all bands, you have to set it here. Can be one of: "float", "double", "int", "Uint8", "Int8" or a casting function like ee.Image.toFloat
  • kwargs: keyword arguments that will be passed to ee.batch.export.image.toDrive

Return a list of all tasks (for further processing/checking)


In [1]:
import ee
ee.Initialize()
from geetools import batch

FeatureCollection


In [2]:
p1 = ee.Geometry.Point([-71,-42])
p2 = ee.Geometry.Point([-71,-43])
p3 = ee.Geometry.Point([-71,-44])

In [3]:
feat1 = ee.Feature(p1.buffer(1000), {'site': 1})
feat2 = ee.Feature(p2.buffer(1000), {'site': 2})
feat3 = ee.Feature(p3.buffer(1000), {'site': 3})

In [4]:
fc = ee.FeatureCollection([feat1, feat2, feat3])

Image


In [5]:
collection = ee.ImageCollection('COPERNICUS/S2').filterBounds(fc.geometry())

In [6]:
image = collection.mosaic()

Execute


In [10]:
task = batch.Export.image.toDriveByFeature(
    image, 
    collection=fc, 
    folder='tools_exportbyfeat', 
    name='test {site}', 
    scale=10, 
    dataType='float',
    verbose=True
)


exporting 'test 1' to 'tools_exportbyfeat' folder in GDrive
exporting 'test 2' to 'tools_exportbyfeat' folder in GDrive
exporting 'test 3' to 'tools_exportbyfeat' folder in GDrive

In [ ]: