joashkisten123
joashkisten123

Reputation: 3

Query point data on a Google Earth Engine Image by specifying lat/long

I am trying to extract point values from a Google Earth Engine Image Collection by specifying lat/long information.

This seems to work perfectly fine when I am working with multiple images and use ee.Image.cat() to join them before I query the image. In the code example below composite = ee.Image.cat().

However, when I change composite (line 3 from the bottom) to one of the image collections (eg. chirps), it does not seem to work.

Please could someone assist me with this.

def getPropertyValue(settings):
    collection = settings['collection'];
    fieldName = settings['fieldName'];
    dateRange = settings['dateRange'];
    geoLocation = settings['geoLocation'];
    scale = settings['scale'];
    
    image = ee.ImageCollection(collection).select(fieldName).filterDate(dateRange[0], dateRange[1]).mean();
    point = ee.Geometry.Point(geoLocation);
    mean = image.reduceRegions(point, 'mean', scale);
    valueRef = mean.select([fieldName], ['precipitation'], retainGeometry=True).getInfo();
    value = valueRef[fieldName][0]['properties'][fieldName];
    
    return value;
    
fieldName = 'LST_AVE';
chirps = ee.ImageCollection("JAXA/GCOM-C/L3/LAND/LST/V2").select(fieldName).filterDate('2020-01-01', '2020-02-01').mean() 
point = ee.Geometry.Point([26.8206, 30.8025])

dist_stats = composite.reduceRegions(point, 'mean', 5000)
dist_stats = dist_stats.select([fieldName], [fieldName], retainGeometry=True).getInfo();

print(dist_stats['features'][0]['properties'][fieldName])

Result when using composite

14248.55

Error when replacing composite with a Google Earth Engine Image

EEException: Error in map(ID=0):
Feature.select: Selected a different number of properties (0) than names (1).

Upvotes: 0

Views: 747

Answers (1)

Jesse Anderson
Jesse Anderson

Reputation: 4613

reduceRegions names the output column after the reducer, not the field that is being reduced. (Though it's more complicated when you have multiple bands and reducers).

So this:

dist_stats = dist_stats.select([fieldName], [fieldName], retainGeometry=True).getInfo();

should be changed to this

dist_stats = dist_stats.select(['mean'], [fieldName], retainGeometry=True).getInfo();

Upvotes: 0

Related Questions