2

enter image description hereI have a featurecollection with 141 objects inside (135 polygon, 4 geometrycollection and 2 multipolygon) an I have problems to indicate in a loop the region for images exportation in GEE, so I need to filter in the collection only the objects of polygon type for example for run the code easily.

table= ee.FeatureCollection("users/tpc/capas")
lista = table.toList(table.size())
m= lista.getInfo()

for i in range(0,141):

    predio_id = ee.Feature(lista.get(i)).getInfo()["properties"]["id"]
    predio = ee.Feature(lista.get(i)).geometry()
    predio_region= predio.getInfo()["coordinates"]

    S2_NDVI_Col= ee.ImageCollection('COPERNICUS/S2_SR').filterBounds(predio).filterDate(dateNDVI,today).filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 30)).map(addNDVI).map(addSAVI).map(addNDMI).map(addEVI)
    S2_NDVI = S2_NDVI_Col.sort("system:time_start")

    n_img=4000
    colListNDVI = S2_NDVI.toList(n_img)
    n= colListNDVI.size().getInfo()

    for j in range(0,n):
        NDVI = ee.Image(colListNDVI.get(j)) #obtiene la imagen n
        id_NDVI = NDVI.id().getInfo()
        x1 = len(id_NDVI)
        dateNDVI = id_NDVI[x1-38:8].replace('_','')
        int_dateNDVI = int(dateNDVI[5:7])
        print(dateNDVI)
        export = ee.batch.Export.image.toDrive(\
                                               image=NDVI.select("NDVI").float(),
                                               description='S2_NDVI_'+predio_id+"_"+dateNDVI,
                                               maxPixels= 220582361000,
                                               region=predio_region,
                                               folder='S2_FNDR_NDVI',
                                               scale = 10,
                                               crs='EPSG:4326')#,
        export.start()
    print('Descarga MODIS finalizada')
1

You didn't share your collection.

You can map over your collection, adding the geometry type, then filter on it.

https://code.earthengine.google.com/bc3bc26ebda415d48bdfee6df3f1577d

var table = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
  .map(function (feature) {
    return feature.set('geometryType', feature.geometry().type())
  })
  .filterMetadata('geometryType', 'equals', 'Polygon')
print(table.first())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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