My goal is to get the Percentage of Class Values from a fine Raster into a Feature Collection, for Each Pixel of a Coarser Raster

enter image description here

I am Stuck at Creating Polygons per Courser Pixel (in Red) to use .reduceRegion() over.

I have this nice Code snippet to create Pixel Center Points. I want to Modify it so it calculated 4 Edge Coordinates for the Polygon and then Construct a Polygon. Although this way seems Dirty because the Edge Calculation is somewhat arbitrary since it depends on the Measures Distances instead of a clean Pixel Boundary extraction.

Function to Create Spaced Points, written by the user Kuik

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);
  return feats;

Is there a cleaner way of doing this? Otherwise, I'll write the proposed solution.

Your Answer

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

Browse other questions tagged or ask your own question.