How to iterate over and download each image in an image collection from the Google Earth Engine python api

前端 未结 3 618
别跟我提以往
别跟我提以往 2021-01-06 23:08

I am new to google earth engine and was trying to understand how to use the Google Earth Engine python api. I can create an image collection, but apparently the getdow

3条回答
  •  北海茫月
    2021-01-07 00:01

    It's a good idea to use ee.batch.Export for this. Also, it's good practice to avoid mixing client and server functions (reference). For that reason, a for-loop can be used, since Export is a client function. Here's a simple example to get you started:

    import ee
    ee.Initialize()
    
    rectangle = ee.Geometry.Rectangle([-1, -1, 1, 1])
    sillyCollection = ee.ImageCollection([ee.Image(1), ee.Image(2), ee.Image(3)])
    
    # This is OK for small collections
    collectionList = sillyCollection.toList(sillyCollection.size())
    collectionSize = collectionList.size().getInfo()
    for i in xrange(collectionSize):
        ee.batch.Export.image.toDrive(
            image = ee.Image(collectionList.get(i)).clip(rectangle), 
            fileNamePrefix = 'foo' + str(i + 1), 
            dimensions = '128x128').start()
    

    Note that converting a collection to a list in this manner is also dangerous for large collections (reference). However, this is probably the most scalable method if you really need to download.

提交回复
热议问题