Google Earth Engine – Converting Each Rastercell to Individual Point-Vector

google-earth-enginevectorization

Related Post

My goal is to perfectly obtain one vector point per raster cell, located at the Center of the RasterCell
Running .reduceToVectors() with the scale argument retrieves vector points, but none fit the raster.

var coorsfeat = mean.reduceToVectors({
reducer : null,
geometry : geometry,
scale:6800,
//crs :mean.projection().getInfo().crs,
//crsTransform :mean.projection().getInfo().transform,
geometryType : 'centroid',
labelProperty : 'Precip',
eightConnected: false
})

enter image description here

Running with:

scale: mean.projection().nominalScale().getInfo() = 111319.49079327357 retrieves no features

Running with :

crs :mean.projection().getInfo().crs,
crsTransform :mean.projection().getInfo().transform,

retrieves no Features

Is there a more elegant way of achieving the goal?

Link to GEE

Best Answer

Loosely based on this answer, you can make a feature collection consisting of points at the center of each pixel.

For your purpose, you can do that as follows:

// get the projection of the first image
var projection = ImCol.filterBounds(geometry).filterDate('2017-01-01','2017-12-31').first().projection();

function spacedPoints(AOI, projection) {
  // make a coordinate image
  // get coordinates image
  var latlon = ee.Image.pixelLonLat().reproject(projection);
  // put each lon lat in a list 
  var coords = latlon.select(['longitude', 'latitude'])
                 .reduceRegion({reducer: ee.Reducer.toList(),
                                geometry: AOI,
                                scale: projection.nominalScale().toInt(),
                                maxPixels: 10e10
  });
  // zip the coordinates for representation. Example: zip([1, 3],[2, 4]) --> [[1, 2], [3,4]]
  var point_list = ee.List(coords.get('longitude')).zip(ee.List(coords.get('latitude')));
  // preset a random list
  var list = ee.List([0]);
  // map over the point list and add features as geometry
    var feats = ee.FeatureCollection(point_list.map(function(point){
      var ind = point_list.indexOf(point);
      var feat = ee.Feature(ee.Geometry.Point(point_list.get(ind)), {'ID': ind});
    return list.add(feat);
    }).flatten().removeAll([0]));

  return feats;
}

// apply the function
var output = spacedPoints(geometry, projection); print(output)
Map.addLayer(output, {color: 'green'})

link script