Google Earth Engine – Reprojecting Vector FeatureCollections

coordinate systemgoogle-earth-engineraster

I am calculating zonal statistics in Google Earth Engine, using an uploaded shapefile(EPSG:4326) and raster dataset (GHSL – EPSG:54009), so I need to reproject one of the layers.

Whilst I have reprojected the raster dataset to the EPSG:4326 and this solves the problem, I still would like to know how to reproject the vector layer to EPSG:54009 for future calculations.

I have tried several solutions, one of which results in an error of:Cannot read property 'transform' of undefined.

Please can someone update my script?

// Define an arbitrary region in which to compute random points.
var region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064);

// Create 1000 random points in the region.
var randomPoints = ee.FeatureCollection.randomPoints(region);

// Display the points.
Map.centerObject(randomPoints);
Map.addLayer(randomPoints, {}, 'random points');


// Define mollweide projection as wkt
var wkt = ' \
  PROJCS["World_Mollweide", \
    GEOGCS["GCS_WGS_1984", \
      DATUM["WGS_1984", \
        SPHEROID["WGS_1984",6378137,298.257223563]], \
      PRIMEM["Greenwich",0], \
      UNIT["Degree",0.017453292519943295]], \
    PROJECTION["Mollweide"], \
    PARAMETER["False_Easting",0], \
    PARAMETER["False_Northing",0], \
    PARAMETER["Central_Meridian",0], \
    UNIT["Meter",1], \
    AUTHORITY["EPSG","54009"]]';


// Define wkt as projection
var proj_mollweide = ee.Projection(wkt);


// Apply transformation
var points_moll = ee.randomPoints.transform(proj_mollweide, 0.001);

print(points_moll);

Best Answer

Not sure if transforming vector is worth it, but here's the trick.

According to docs, .transform() is ony applied to an ee.Feature, not ee.FeatureCollection. So you have to map the procedure over a FeatureCollection.

// Define an arbitrary region in which to compute random points.
var region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064);

// Create 1000 random points in the region.
var randomPoints = ee.FeatureCollection.randomPoints(region);

// Display the points.
Map.centerObject(randomPoints);
Map.addLayer(randomPoints, {}, 'random points');


var dst_projection = 'EPSG:3857';


// Apply transformation
var transformer = function(a_feature) {
  var transformed_feature = a_feature.transform(dst_projection, 0.001);
  return transformed_feature;
};

var points_prj = randomPoints.map(transformer);

print(points_prj);

This is a link to the snippet on EE