2

Can you add a color gradient to GeoTiffs?

I am trying to do what is explained in Kernel Density

We already know that with a line like this:

kde.renderPng(kdeColorMap).write(“kde-buoy-waveHeight.png”)

we can write out a PNG with color…

But I can’t seem to figure out how to add that color to a GeoTiff…

I've tried this:

val iColorMap: IndexedColorMap = new IndexedColorMap(delauColorMap.colors)

val geoTiffOptions = GeoTiffOptions(colorMap = iColorMap)

val delauWebMer: Raster[Tile] = delau.reproject(extent, LatLng, WebMercator)
val extentWebMer: Extent = extent.reproject(LatLng, WebMercator)

val headTags: Map[String, String] = Map()
val bandTags: List[Map[String, String]] = List()
val tags: Tags = Tags(headTags, bandTags)
val tiff = SinglebandGeoTiff(delauWebMer, extentWebMer, WebMercator, tags, geoTiffOptions)
tiff.write("BuoyDelau3857.tif")

but get the following exception:

IncompatibleGeoTiffOptionsException: 'Palette' color space only supported for 8 or 16 bit integral cell types.

This works:

val tiff = GeoTiff(delauWebMer, extentWebMer, WebMercator)
tiff.write("BuoyDelau3857.tif")

but doesn't give us a color map, the output is in grey-scale.

Paul Reiners
  • 8,576
  • 33
  • 117
  • 202

1 Answers1

0

Convert the Tile's CellType

val converted = delau.interpretAs(CellType.fromName("int16"))
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202
  • I think it might actually be `val converted = delau.convert(UShortConstantNoDataCellType)`, but I'd need to know what the original cell type of `delau` is. – metasim Feb 28 '18 at 14:45