0

I want to sample random points over an image I access using geemap. I was trying to do it as following:

#access elevation image and clip it with the feature collection
img = ee.Image('USGS/SRTMGL1_003').clip(fc)

visualize image:
enter image description here

#sample the image with random points:
fc_sample=ee.FeatureCollection.randomPoints(img.geometry(), points=3500)
fc_sample.getInfo()

>>>EEException: FeatureCollection.randomPoints: Polygon too large to be randomly sampled. Must be smaller than a hemisphere.

I could solve it based on the answer on this post as following:

fc_sample=ee.FeatureCollection.randomPoints(fc, points=3500)
fc_sample.getInfo()

enter image description here

This is not the first time that I encounter this behavior of image geometry behaves differently than what I would excepted.
My question is : why is this happens? what is the explanation of this behavior? how can I get the image extent as a parameter that can be used for the random points, instead of "fc" parameter?

2
  • 2
    I would guess this is a performance optimization. It doesn't actually set the footprint of the image when clipping to a feature collection. The geometry might be very complex and memory intensive to evaluate/work with. If you need the geometry, you can ee.Image('USGS/SRTMGL1_003').clip(fc.geometry()). Commented Jul 17, 2023 at 9:04
  • @DanielWiell do you want to post it as answer so you can award the bounty prize?
    – ReutKeller
    Commented Jul 23, 2023 at 9:04

1 Answer 1

1
+50

I would guess this is a performance optimization. It doesn't actually set the footprint of the image when clipping to a feature collection. The geometry might be very complex and memory intensive to evaluate/work with. If you need the geometry, you can ee.Image('USGS/SRTMGL1_003').clip(fc.geometry()).

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.