I am running several thousand polygons through a Google Earth Engine code and many of them have names with spaces in them and when I try to run the initiate image export I get "Task name may contain alphanumeric characters, underscores, and dashes. No spaces." It would be impractical for me to go through and add and underscore to them in the attribute table.

So in this one case I am trying to run a fire with the name Flying R. In the attribute table it has a space in the name so it will not successfully run. Is there a way I can code it so that it will automatically insert an "_" wherever there is a " "?

This is the code I though would be relevant. Let me know if you need more.

var fires = ee.FeatureCollection("users/mtd25/fires/AZ3143311069520170614_FLYING_R");
var fireID    = ee.List(fires.aggregate_array('Fire_ID')).getInfo();
var nFires = fireID.length;
var Fire_Name = ee.List(fires.aggregate_array('Fire_Name')).getInfo(); //For Megan's dataset
for (var j = 0; j < nFires; j++){
  var id   = fireID[j];
  var Name = id;
  var fireExport = ee.Image(indices.filterMetadata('fireID', 'equals', id).first());
  var fireBounds = ee.Feature(fires.filterMetadata('Fire_ID', 'equals', id).first()).geometry().bounds();

  for (var i = 0; i < nBands; i++) {
    var bandExport = bandList[i];  
    var exportImg = fireExport.select(bandExport);
      image: exportImg,
      description: Name + '_' + Fire_Name + '_' + bandExport,
      fileNamePrefix: Name + '_' + Fire_Name + '_' + bandExport,
      maxPixels: 1e13,
      scale: 30,
      crs: "EPSG:4326",
      folder: 'fires',      
      region: fireBounds

1 Answer 1


Two things:

Firstly, this isn't really a Earth Engine question, since your variables Name and Fire_Name are native JavaScript strings. In that case, you can simply use JavaScript functions to deal with them.

The function you are looking for is .replace(). So this would work for you:

var exportStr = Name + '_' + Fire_Name + '_' + bandExport
var noSpaces = exportStr.replace(" ", "_")

Secondly, in Javascript the naming convention for variables and classes is that everything which is named in PascalCase should be a class (i.e. ClassName). So your variables Name and Fire_Name should not start with a capital letter and should ideally be in camelCase.


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.