3

I am trying to reduce the percentage of crops from the CGLS-100 Landcover dataset for a set of points uploaded as asset from a shapefile. This is an operation that I've done tens of times, but for some reason in this particular instance reduceRegions doesn't return any value from the image - only the fields from the original shapefile. I need someone to check my sanity:

# Load landcover
LC = ee.ImageCollection("COPERNICUS/Landcover/100m/Proba-V-C3/Global")\
    .filterDate('2015-01-01', '2015-12-31').first().select(['crops-coverfraction'])

# Load POIs
POI = ee.FeatureCollection('users/sebastienbiasse/barangays')

# Produce buffer around POIs
POI = POI.select(['NAME_1', 'NAME_2', 'NAME_3']).map(lambda feat: ee.Feature(feat).buffer(1000))

# Reduce
col = LC.reduceRegions(collection=POI, reducer=ee.Reducer.mean(), scale=100)

# Remove geometry
col = col.map(lambda feat: feat.setGeometry())

# Request GEE to perform its magics
ee.batch.Export.table.toDrive(collection=col, description=f'LC_crops8', folder='CALDERA', fileFormat="CSV").start()

No error is returned, but the output csv file contains only the fields system:index, NAME_1, NAME_2, NAME_3, and .geo. I expect a field called crops-coverfraction as requested. Other SO answers to similar problems suggest that one source of error could be the size of the featureCollection and mine happens to be rather large (84k points). I get the same problem when using this instead:

ee.batch.Export.table.toDrive(collection=col.limit(1000), description=f'LC_crops8', folder='CALDERA', fileFormat="CSV").start()

Can anyone spot an error?

The bizarre thing is that I reduce another image ~10 lines above this and it works perfectly.

2
  • You could try indicating the fields you wish to export in the selectors argument of the Export.table.toDrive. Commented Dec 15, 2021 at 15:53
  • I didn't know you could in Export.table.toDrive, I've tried specifying this in image.reduceRegions but to no change, and from my experience it natively exports all bands in the image.
    – e5k
    Commented Dec 15, 2021 at 21:52

1 Answer 1

1

I don't usually work with Python so I worked out a solution directly on the GEE code editor. From what I can gather, there are two things that are messing up your code:

First, I think you might have to limit the number of properties to something ≤5000, though this might not be the case when exporting the results to the Drive.

Second, for reasons unbeknownst to myself, reduceRegions needs a crs projection (even though it's supposedly optional) to work in this case.

Here's the GEE code I wrote to test your python code: https://code.earthengine.google.com/ee203842d4f9020ee718f1f6fb8451b7

1
  • 1
    Thanks Madeleine! As I mentioned, I also attempted to limit the number of exports without success. But I also reached the same conclusion yesterday: specifying crs='EPSG:4326' to reduceRegions solved the problem.
    – e5k
    Commented Dec 16, 2021 at 9:04

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.