1

I have imported a shapefile of points into Google Earth Engine but am unable to find information on how to label them by their assigned number in the attribute table. I saw a related thread but the code provided was not successful. This is what I have tried:

// Step 7) Add GRTs points to map
var styling = {color: 'orange', fillColor: '00000000'};
Map.addLayer(HCSR_MgmtGRTs.style(styling), HCSR_MgmtGRTs, "HCSR GRTS");

// Step 8) Label points
var text = require('users/gena/packages:text')
// scale text font relative to the current map scale
var scale = Map.getScale() * 1

var labels = HCSR_MgmtGRTs.map(function(feat) {
  feat = ee.Feature(feat)
  var number = ee.String(feat.get("NUMBER"))
  var centroid = feat.geometry().centroid()
  var t = text.draw(number, centroid, scale, {
    fontSize:18, 
    textColor:'orange',
    outlineWidth: 1,
    outlineColor: 'orange'
  })
  return t
})

labels = ee.ImageCollection(labels)
Map.addLayer(labels)

It runs without error, but I am not seeing any labels on my points. I am a beginner, so an easy explanation would be helpful!

1 Answer 1

0

I tried this (probably following same youtube tutorial https://www.youtube.com/watch?v=AmaaEFbBtfQ) for my point shapefile and it worked:

var text = require('users/gena/packages:text')
var scale = Map.getScale() * 1 // You can reduce 1 to 0.25 or even less if labels too big like it was for me
var shp = ee.FeatureCollection(Vegetation_points) //Vegetation_points is my shapefile that I had imported in GEE before

var labels = shp.map(function(feat) {
  feat = ee.Feature(feat)
  var name = ee.String(feat.get("Name")) //"Name" is the name of the column of the table of attribute of my shapefile containing the labels.
  var centroid = feat.geometry().centroid()
  var t = text.draw(name, centroid, scale, {
    fontSize:12, //looks like you cannot chose another size than 12 (but it can be scaled anyway using the var scale above
    textColor:'black',
    outlineWidth: 0.5,
    outlineColor:'black'
  })
  return t
})

var labels_final = ee.ImageCollection(labels)
Map.addLayer(labels_final, {}, "Vegetation_points_labels")```

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.