1

CODE:

var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
       .filterBounds(geometry);

// TEST IMAGE

 var first = ee.Image(l8.first()).clip(geometry)

// get image projection
var proj = first.select([0]).projection()

// get coordinates image
var latlon = ee.Image.pixelLonLat().reproject(proj)

// put each lon lat in a list
var coords = latlon.select(['longitude', 'latitude'])
             .reduceRegion({
 reducer: ee.Reducer.toList(),
 geometry: geometry,
 scale: 30
})

// get lat & lon
var lat = ee.List(coords.get('latitude'))
var lon = ee.List(coords.get('longitude'))

// zip them. Example: zip([1, 3],[2, 4]) --> [[1, 2], [3,4]]
var point_list = lon.zip(lat)
print(point_list);
// Create points
var mp = ee.FeatureCollection(ee.Geometry.MultiPoint(point_list));
print(mp);
Map.addLayer(mp,{}, 'All Points')
Map.centerObject(geometry);

Here when I print mp it is showing it as a Feature collection of a single element of MultiPoint geometry.

Example for feature collection of different elements:

var ran = ee.FeatureCollection.randomPoints(geometry,4516,10);
print(ran);
Map.addLayer(ran,{}, 'Random Points')

What I want it is the same as the above one which feature collection of different elements.

What changes should I do to convert my feature collection same as this one?

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]]]);
3

Change variable mp for

var mp = ee.FeatureCollection(point_list.map(function(p){
  var point = ee.Feature(ee.Geometry.Point(p), {})
  return point
}))
1
  • I have a similar problem with MultiPolygon geometry.. when i run the above code.. it gives this error: GeometryConstructors.Polygon, argument 'coordinates': Invalid type. Expected: List<Object>. Actual: Feature. .. any idea how to solve this?
    – rao
    Jan 24 '20 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.