How to export an image as Tiff with a transparent background #1901
-
Hi, import ee
import geemap
ee.Initialize()
image = ee.Image('COPERNICUS/S2_SR_HARMONIZED/20200507T104031_20200507T104558_T31UGR')
roi = ee.Geometry.Rectangle([[6.11,50.30],[6.16,50.33]])
field = ee.Geometry.Polygon([[[6.126251, 50.325847],
[6.123934, 50.324642],
[6.130114, 50.320368],
[6.131744, 50.31675],
[6.133633, 50.312969],
[6.139641, 50.314284],
[6.143503, 50.310338],
[6.147194, 50.311872],
[6.144361, 50.316367],
[6.137152, 50.317956],
[6.126251, 50.325847]]])
image = image.addBands(image.normalizedDifference(['B8','B4']).rename('NDVI'))
NDVI_image = image.select('NDVI').clip(field)
ndvi_colors = ["#8f2723", "#8f2723", "#8f2723", "#8f2723", "#af201b", "#af201b", "#af201b", "#af201b", "#ce4a2e", "#ce4a2e", "#ce4a2e", "#ce4a2e",
"#df744a", "#df744a", "#df744a", "#df744a", "#f0a875", "#f0a875", "#f0a875", "#f0a875", "#fad398", "#fad398", "#fad398", "#fad398",
"#fff8ba",
"#d8eda0", "#d8eda0", "#d8eda0", "#d8eda0", "#bddd8a", "#bddd8a", "#bddd8a", "#bddd8a", "#93c669", "#93c669", "#93c669", "#93c669",
"#5da73e", "#5da73e", "#5da73e", "#5da73e", "#3c9427", "#3c9427", "#3c9427", "#3c9427", "#235117", "#235117", "#235117", "#235117"]
ndvi_vis = {'bands':['NDVI'],'min': 0,'max': 1,'palette': ndvi_colors}
Map = geemap.Map()
Map.centerObject(roi,13)
vis_params = {"min": 0, "max": 2000, "bands": ["B4", "B3", "B2"]}
Map.addLayer(image,vis_params,'image')
Map.addLayer(roi,{"color": 'yellow'})
Map.addLayer(field,{"color": 'purple'})
Map.addLayer(NDVI_image,ndvi_vis,'NDVI')
Map
### Here I tried two ways of exporting as Tiff. When I import them in Google Earth, however, both of them appear with a black background. My question is: How can I get a Tiff that opens with a transparent background in Google Earth?
geemap.ee_export_image(NDVI_image, filename='NDVI_image1.tif', scale=10, file_per_band=False)
NDVI_image2 = NDVI_image.visualize(min=0.5, max=1, palette=ndvi_colors)
geemap.ee_export_image(NDVI_image2, filename='NDVI_image2.tif', scale=10, file_per_band=False) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you open the image using QGIS, you should see a transparent background. Google Earth Pro can't render the GeoTIFF with a tranparent background. You need to convert it to PNG. However, once the GeoTIFF is converted to a PNG, it loses the geoference, and you can't overlay the image easily on the map. |
Beta Was this translation helpful? Give feedback.
If you open the image using QGIS, you should see a transparent background.
Google Earth Pro can't render the GeoTIFF with a tranparent background. You need to convert it to PNG. However, once the GeoTIFF is converted to a PNG, it loses the geoference, and you can't overlay the image easily on the map.
https://community.esri.com/t5/drones-uavs-uas-and-rpas-questions/how-to-import-tif-to-google-earth-without-black/td-p/765919