首页 > 解决方案 > 将 IndexedColorMap 类型转换为 ColorMap

问题描述

我有一个获取图像颜色图的代码(* .tif)。

val geotiff = SinglebandGeoTiff(abcd.tif)

val colorMap1 = geotiff.options.colorMap

现在 colorMap1 是 IndexedColorMap 类型。

有没有办法将 colormap1 转换或类型转换为 ColorMap(geotrellis.raster.render.ColorMap) ,因为我的整个代码是基于 ColorMap 而不是 IndexedColorMap

标签: scalageotrellis

解决方案


IndexedColorMapextends 扩展IntColorMapColorMap因此它们是兼容的。但它看起来不像是geotiff.options.colorMap回来了。所以你可以这样做:Option[IndexedColourMap]IndexedColorMap

val defaultColorMap: ColorMap = ???
val colorMap1: ColorMap = geotiff.options.colorMap.getOrElse(defaultColorMap)

在线查看其他Option在 Scala 中以干净、实用的方式处理值的方法。


推荐阅读