gee-community / geemap

A Python package for interactive geospatial analysis and visualization with Google Earth Engine.
https://geemap.org
MIT License
3.44k stars 1.08k forks source link

(how?) is it possible to download a clipped image? #96

Closed ChHarding closed 4 years ago

ChHarding commented 4 years ago

Description

Starting with https://github.com/giswqs/geemap/blob/master/examples/notebooks/11_export_image.ipynb , I tried to first clip an image with a polygon and then export it.

The clipped image shows up properly clipped and the download works.

clipped_image_added_to_map

However, the downloaded tif files are not clipped, i.e. the "outside" pixels are not 0 or invisible.

downloaded_tiff

What I Did

The notebook, screenshots of the clipped image inside the online map and the un-clipped downloaded tiffs are here: https://iastate.box.com/s/6j7gk7uzn3mhi7nocmphfzmndbaewoot

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
import ee
import geemap

Map = geemap.Map()
image = ee.Image('LE7_TOA_5YEAR/1999_2003')

landsat_vis = {
    'bands': ['B4', 'B3', 'B2'], 
    'gamma': 1.4
}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 0.7)
Map

# Draw any shapes on the map using the Drawing tools before executing this code block
feature = Map.draw_last_feature
roi = feature.geometry()

# clip image and add to map
clipped_image = image.clip(roi)
Map.addLayer(clipped_image, landsat_vis, 'Clipped image')

geemap.ee_export_image(clipped_image, filename='landsat.tif', scale=90, region=roi, file_per_band=True)

I've not used ee a lot and expect that I'm missing something (obvious). Could you tell me what I'm doing wrong?

giswqs commented 4 years ago

Use the .unmask() function after clipping. It should be able to export the image clipped to the polygon.

clipped_image = image.clip(roi).unmask()

ChHarding commented 4 years ago

yes, that works! Thank you very much!

If I can ask a followup question: Is there a way to set the “outside” polygon value to a specific value. 0 works for me most of the time but there’s a tiny chance that some valid inside pixels also have a 0 value, so it’d be nice to be able to use say -999999 for outside instead of 0

Cheers

Chris

On Jun 18, 2020, at 20:28, Qiusheng Wu notifications@github.com wrote:

Use the .unmask() function after clipping. It should be able to export the image clipped to the polygon.

clipped_image = image.clip(roi).unmask() https://camo.githubusercontent.com/d144625bf7bd53e48903646b99985802a63fdcc0/68747470733a2f2f692e696d6775722e636f6d2f784475594a6c672e676966 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/giswqs/geemap/issues/96#issuecomment-646385309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYDF5JPNCEWIWQOYHDYI3LRXK5MZANCNFSM4OAAMQYQ.

Chris Harding Associate Professor Department of Geological & Atmospheric Sciences

TouchTerrain.geol.iastate.edu

giswqs commented 4 years ago

You can try the unmask() function by setting the value parameter and export a rectangular area.

ChHarding commented 4 years ago

yes, unmask(-9999, False) worked, thank you very much!

On Jun 19, 2020, at 15:20, Qiusheng Wu notifications@github.com wrote:

You can try the unmask() function by setting the value parameter and export a rectangular area.

https://camo.githubusercontent.com/62bee05b00e9e1731b0928325251a495c0b9fbd7/68747470733a2f2f692e696d6775722e636f6d2f52514c4f5848612e706e67 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/giswqs/geemap/issues/96#issuecomment-646846400, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYDF5K2STQSDIIFIX7R2FDRXPCA7ANCNFSM4OAAMQYQ.

Chris Harding Associate Professor Department of Geological & Atmospheric Sciences

TouchTerrain.geol.iastate.edu