1

Now I'm drawing some pixels sampled from map, the code can be run easily:

var first = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(ee.Geometry.Point(-70.48, 43.3631))
  .filterDate('2019-01-01', '2019-12-31')
  .sort('CLOUDY_PIXEL_PERCENTAGE')
  .first()

var samples = first
  .sample({
    numPixels: 10,
    geometries: true,
  })
  .map(function(feature) {
    var min = 0
    var max = 300
    var opacity = toHex(min, max, feature.getNumber('B2'))
    var fillColor = ee.String('#ff0000').cat(opacity)
    return feature
      .set('style', {
        fillColor: fillColor
      })
  })

var styled = samples.style({
  pointSize: 40,
  width: 0,
  styleProperty: 'style'
})

Map.addLayer(styled, null, 'samples')
Map.centerObject(samples)


function toHex(min, max, value) {
  return ee.Number(value)
    .unitScale(min, max)
    .multiply(255)
    .round()
    .clamp(0, 255)
    .format('%x')
}

But now I want to draw the pixel size with (500m x 500m) on the map, or you can regard it as a 500x500 size mask. I try to tune the pointSize=500 in fucntion samples.style(), but it seems to be wrong. How can I do it?

1
  • My doubt is the unit of pointSize is not in meter. It may not be possible what you want to achieve. The pointshapes are currently circle, you can change it to square.
    – Padmanabha
    Commented Jun 9, 2023 at 5:39

1 Answer 1

1

You can turn the points into polygons by buffering the points with half the size you want, then take the bounds of the resulting circle. They will be hard to spot when you're zoomed out though, as they actually will be 500x500 meters.

var styled = samples
  // Turning samples into polygons separately, in case you need the original points for something
  .map(function (feature) {
    var size = 500
    return ee.Feature(
      feature.geometry().buffer(size / 2).bounds(), 
      feature.toDictionary()
    )
  })
  .style({
    width: 0,
    styleProperty: 'style'
  })

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

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.