Geemap Sampling Regions – Addressing Empty FeatureCollection Issues

geemapgoogle-earth-enginegoogle-earth-engine-python-apijupyter notebook

I have feature collection of 200 points and raster which is a result of sum of three bands of an Image. I want to create a table which will show the points (feature collection) and the value these points have on the raster, so the result should be table with 200 points and the value (from the raster).
I have tried doing it with Sample region function, which runs, but gives me an empty feature collection.

This script simulates my steps:

original_image = ee.Image("projects/images/my_image");

img_sum = original_image.expression(
    'b1+b2+b3', {
      'b1': original_image.select('b1'),
      'b2': original_image.select('b2'),
      'b3': original_image.select('b3')
})

#after this I have visualized the results and checked if the sum really worked. It did.

#now- I want to create table which will have the points value at the pixel they stand on.

trying_to_sample=img_sum.sampleRegions(collection=points)

#this runs but when I do getInfo I get empty FeatureCollection:

trying_to_sample.getInfo()
>>>
{'type': 'FeatureCollection',
 'columns': {},
 'properties': {'band_order': ['b1']},
 'features': []}

Is there any possibility that this function is not really exists in geemap? I couldn't find it under the documentation .
However,
my end goal is to extract the raster values for the points, and create new table from this.

Best Answer

It's hard to tell without a complete reproducible example. This should more or less do what you're asking for, I think:

import ee

ee.Initialize()

# Generate dummy points
points = ee.FeatureCollection(ee.List.sequence(1, 200)
  .map(
    lambda i: ee.Feature(ee.Geometay.Point([ee.Number(i), 0]))
  )
)

image = ee.Image([
  ee.Image.random(1),
  ee.Image.random(2),
  ee.Image.random(3)
]).reduce(ee.Reducer.sum()) # Simple way to sum all bands

samples = image.sampleRegions(
  collection=points, 
  scale=30,
  geometries=True # You said you wait to show the points, so you might want to include the geometries?
)
samples.getInfo()
Related Question