我有一个代码来获取图像的色彩映射表(*.tif)。
val geotiff = SinglebandGeoTiff(abcd.tif)
val colorMap1 = geotiff.options.colorMap
现在colorMap1的类型是IndexedColorMap。
有没有办法将colormap1转换为ColorMap(geotrellis.raster.render.ColorMap),因为我的整个代码都是基于ColorMap而不是IndexedColorMap的
发布于 2019-10-18 16:08:29
IndexedColorMap扩展了IntColorMap,后者扩展了ColorMap,因此它们是兼容的。但是看起来geotiff.options.colorMap返回的是Option[IndexedColourMap]而不是IndexedColorMap。所以你可以这样做:
val defaultColorMap: ColorMap = ???
val colorMap1: ColorMap = geotiff.options.colorMap.getOrElse(defaultColorMap)有关在Option中以干净、有效的方式处理Scala值的其他方法,请参阅在线文章。
https://stackoverflow.com/questions/58446118
复制相似问题