1

I want to create a button that download images without clicking the RUN button on the task tab. I want to do this for a GEE App, where is no possible for the user to go to the task tab and click Run.

Is this possible?

See my button so far:

function downloadImg() {
  // Get start and end dates from button selections 
  var startDate = startYear.getValue() + "-" + month[startMonth.getValue()][0]; 
  var endDate = endYear.getValue() + "-" + month[endMonth.getValue()][0];
  // Filter the collection by dates selected.
  var filterCollection = wetlands.filterDate(startDate, endDate)
                        .filterBounds(getSelectedFeatures());
  // Create mosaic
  var mosaicImage = filterCollection.max().clip(getSelectedFeatures());
  
  // Export the image to Drive.
  Export.image.toDrive({
  image: mosaicImage.toByte(),
  description: 'Wetland_Mosaic',
  scale: 1.8,
  region: getSelectedFeatures(),
  maxPixels: 1e13,
  fileFormat: 'GeoTIFF'
  });
}

// Download button
var downloadButton = ui.Button({
  label: 'Download', style: {padding:'0px 0px 0px 10px'}
})
downloadButton.onClick(downloadImg)
2

Unlike Export.image.toDrive, image.getThumbURL does not need the additional step of clicking "Run". Documentation for that is at the end of the page here.

So use I suggest you use mosaicImage.toByte().getThumbURL(), and print the URL to the right panel, which will let the users to click and see the image. Keep in mind that unlike the Export.image.toDrive, getThumbURL works for small images only.

Since you did not provide a full example, here is one. In lines 142 - 170, there is an export button along with the exportImage function you are interested in. For the App user, the app would look something like this.

1
  • I wanted to allow the user to download a .tiff image, but I think that is not possible using the App interface. Thank you for sharing that great example, I will probably use your method. Oct 5 '20 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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