I am trying to sample random 10 points from forested areas for different ecoregions as identified by RESOLVE Ecoregions 2017 (https://ecoregions.appspot.com/).
In the Google Earth Engine code below,I
- identify forested regions around the world using landcover classifications provided by MODIS
- create a mask to filter a specific ecoregion from the RESOLVE feature collection
- Clip the global forested regions raster using the ecoregion mask
- Use "stratifiedSample" to sample 10 random points on the clipped image
var geometry = ee.Geometry({
type: 'Polygon',
coordinates :
[[[-165.0046128552152, -57.92312657774621],
[184.8000746447848, -57.92312657774621],
[184.8000746447848, 69.26619097225324],
[ -165.0046128552152, 69.26619097225324],
[-165.0046128552152, -57.92312657774621]]],
geodesic: false}// geodesic = false means it will take a straight path and not the shortest path around the world
); //hand-drawn geometry required for sampling random points
var landcover = ee.Image("MODIS/061/MCD12Q1/2022_01_01").select('LC_Type1');
print(landcover);
//creating a mask with different types of forest/ savanna cover LC_Type1=8
var forest2022= landcover.lte(8); //identifying forested regions
print(forest2022);
var biomes=ee.FeatureCollection("RESOLVE/ECOREGIONS/2017");//Predefined ecoregions and biomes
//Identifying different ecoregions using RESOLVE and intersecting with forest landcover from 2022 to identify forested regions in each ecoregions.
var formask= biomes.filterMetadata("ECO_ID", 'equals',129);//creating a mask for a specific ecoregion
var combmap = forest2022.clip(formask);//clipping forest cover map to a specific ecoregion
Map.addLayer(combmap);
//sampling random points
var points1= combmap.updateMask(combmap.eq(1)).stratifiedSample({ //sampling points only when formask=1 values, i.e., regions with forests
region: geometry,
classBand: 'LC_Type1',
numPoints: 10,
geometries: true,
seed: 234
});
Map.addLayer(points1);
The above code works for certain ecoregions (e.g. anything from ecoregion ID 1 to 120), but not for the others (e.g., 128, 168, 173, 176, 177).
When it does not work, I usually get an error that says " Layer error: Unable to transform edge (4622.000000, 30575.000000 to 4622.007828, 30575.000000) from SR-ORG:6974 PLANAR [463.3127165279165, 0.0, -2.0015109354E7, 0.0, -463.3127165279167, 1.0007554677003E7] to EPSG:4326."
What is the issue and is there a way to fix it? I want to be able to convert this to a function and extract similar data for several pre-identified ecoregions.
(Note: I am new to GEE and GIS stackexchange. If more information is needed, I can provide that as well)