Google Earth Engine – How to Select All Points of Polygon as Single Feature

google-earth-enginegoogle-fusion-tables

IMPORTS:

var geometry = /* color: #d63000 */ee.Geometry.Polygon(
    [[[-67.76435852050781, -22.213792811479802],
      [-67.76641845703125, -22.220785143658368],
      [-67.75646209716797, -22.228412744835992],
      [-67.74410247802734, -22.230319580297703],
      [-67.7420425415039, -22.221420792936158],
      [-67.74341583251953, -22.212203596469955],
      [-67.74787902832031, -22.207753698686023],
      [-67.75543212890625, -22.213474969917876]]]);

CODE I have tried :

var fg_points = ee.Feature(geometry);

I thought if we give geometry as a feature it will select all points in that polygon but it isn't.

Best Answer

In your case you have just a single part Polygon, I give you a solution for both, single and multi part Polygons:

// coordinates is a list of list (each list is a part)
var coordinates = geometry.coordinates()

// map over coordinates, each element is a part (list)
var fg_points = coordinates.map(function(part) {

  // map over current part, each element is a list [lon, lat]
  var points = ee.List(part).map(
  function(coord) {
    // make the point using its coordinates
    return ee.Geometry.Point(coord)
  })

  return points
})

// if you want all points together in one list
var all_points = fg_points.flatten()

print(fg_points)
print(all_points)