# GDAL - Write KMZ file with transparency

**URL:** <https://discourse.julialang.org/t/gdal-write-kmz-file-with-transparency/97087>\
**Category:** Geo\
**Created:** [April 4, 2023, 9:39pm UTC](https://discourse.julialang.org/t/gdal-write-kmz-file-with-transparency/97087 "2023-04-04T21:39:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanomoro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefanomoro/32/47473_2.png) [@stefanomoro](https://discourse.julialang.org/u/stefanomoro)\
**Post date:** [April 4, 2023, 9:39pm UTC](https://discourse.julialang.org/t/gdal-write-kmz-file-with-transparency/97087/1 "2023-04-04T21:39:27Z")

</div>

I’m trying to save a `.kmz` file from a dataset representing a DEM of an area stored in a GeoTiff file.

My code is reading the DEM, transforming the CRS to UTM, and defining a subset based on coordinates. On this subset I did some computation based on the DEM altitude.

I’d like to save the result in a `kmz` file to be opened in Google Earth using Julia.

What I’ve tried up to now is to use ArchGDAL together with [Rasters.jl](https://github.com/rafaqz/Rasters.jl). However the results is not what I wanted, I’m still missing the transparency for the missing values.  
I’ve found a similar [question](https://gis.stackexchange.com/questions/331109/gdal-translate-geotiff-to-kmz-results-in-transparent-image), but it didn’t explain how he fixed.

The gdal command that should do the job is

```julia
gdalwarp -srcnodata <in> -dstnodata <out> -crop_to_cutline -cutline INPUT.shp INPUT.tif OUTPUT.tif

```

I’ve tried to replicate it with [Rasters.jl](https://github.com/rafaqz/Rasters.jl), having defined the the cropline as a GeoJSON

```julia
A = Raster(dem_file)
flags = Dict(
        "-srcnodata"=> NaN, "-dstnodata" =>0, 
        "-crop_to_cutline" => "", "-cutline" =>"./shape.json",
        )
B = warp(A, flags)   
write("out.kmz",B)

```

The subset I’m working on in Julia is a structure with the same dimensions of the original DEM, but to define the subset I have set all the values out of the bounds to `NaN`. This is the subset plotted in Julia with the red crosses represetning the 4 points in Polygon of the cutline

[![Subset of DEM plotted in Julia](https://global.discourse-cdn.com/julialang/original/3X/1/0/106e469e24bd5d4ccb6ff34c1369e9cb615cdb9c.png)](https://i.stack.imgur.com/CzdwM.png)

This is the result of the `gdal_warp` function

[![Result of the cropping](https://global.discourse-cdn.com/julialang/original/3X/a/2/a2d80c05a3265814ac52f1c7d7f91aad62334f7d.jpeg)](https://i.stack.imgur.com/riB9n.jpg)

What I can see is that `gdal_warp` is cropping correctly the original DEM file but it is not considering the `nodata` field, and it is mapping it to a the black color. I’ve tried changing the values but it seems to not affect the output.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [April 4, 2023, 9:54pm UTC](https://discourse.julialang.org/t/gdal-write-kmz-file-with-transparency/97087/2 "2023-04-04T21:54:30Z")

</div>

You may wang to teu GMT’s grd2kml [grd2kml](https://www.generic-mapping-tools.org/GMTjl_doc/documentation/modules/grd2kml/index.html#grd2kml)
