Let's say I have a landcover map, assigning landcover codes to each pixel in a scene. Then I have a polygon and want to use some or all of the points in it to pick the landcover from the above map, and then sample a stack of Landsat images. I want to have control over final feature id's for my processing but I can not figure out how the id's are generated in GEE.

In the first stage, I will use either sampleRegions function (to retrieve all points in the intended polygon with their landcovers) or stratifiedSample function (to sample a fixed number of points for each landcover from the base map in the intended polygon). Base map is named 'image' and intended polygon is named 'geometry' i below code.

var points1 = image.sampleRegions({
          collection: geometry,
          scale: 30,
          geometries: true})
var points2 = image.stratifiedSample({
          numPoints: NumPoints,
          region: geometry,
          classBand: 'b1',
          geometries: true

At this point, I get my point features with id's being integer numbers as 0, 1, 2, ... in stratifiedSample case, or the integers prefixed with with 0 (0_0, 0_1, 0_2, ...). What does this added '0_' mean? It is the same for all points, even if I have multiple polygons passing to sampleRegions.

Then I build a Landsat imageCollection for my time period of interest, and map it with sampleRegions function by passing any of above point sets to it. This time, a suffix (not prefix) of 0 is added to the point id's. So it will be either 0_0, 1_0, 2_0, ... (for stratifiedSample output) or 0_0_0, 0_1_0, 0_2_0, ... (for sampleRegions output).

var collection = LandsatCol
  .filterDate(start, end)

var series = 
    collection.map(function(image) {
      return image.sampleRegions({
        collection: points,
        properties: ['b1'],
        scale: 30,
        geometries: true

I am confused what is the rule.


1 Answer 1


This is just the naming convention that GEE uses to identify the temporary features that have been created. Since the objects are immutable in GEE, all the objects that are received after doing something that involves altering the features are actually new feature objects. In case of each change, GEE adds a suffix or a prefix. In most cases GEE will add suffixes and not prefixes to the features. Prefixes are generally added when two or more collections with features that have same ID are merged so that it is clearer where the features came from.

In your case, for stratified sample, it is creating completely new points within the region so the points are given ids 0,1,2,3,... etc. But for sampleRegions, since you are using polygons it generates points based on the scale and the polygons so it gives IDs 0_0,0_1,0_2,1_0,1_1,1_2,... and so on. As for sampling within the mapping function it generally joins the ids like {imageid}_{pointid}. Your image probably didn't have an id as it might have been a temporary layer which was not assigned an id so it too 0 and just added the id of points 1,2,3 which made it 0_1,0_2,0_3.

That's more or less how it works but you can imagine it can quickly get out of hand in a practical application scenario as there are too many chains to keep in track. Since you want to track the point ID from start to finish, it might be a good idea to copy the ID to a property and just copy it to the new objects every time you are doing something with the features. sampleRegions has a key 'properties' which lets you preserve the properties in the feature while sampling, which can help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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