diff --git a/CHANGELOG.md b/CHANGELOG.md index 6efffd8c..ae08319b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated MAML up to 0.6.0 [#199](https://github.com/geotrellis/geotrellis-server/pull/199) ### Fixed +- Fixed color interpolation bug related to constructing a range when the step is 0 [#111](https://github.com/geotrellis/geotrellis-server/issues/111) +- Non-integer (floating point) ColorMap keys now work with or without being quoted [#187](https://github.com/geotrellis/geotrellis-server/issues/187) - Missing `` and `` elements in WCS GetCapabilities response [#114](https://github.com/geotrellis/geotrellis-server/issues/114) - Layer definition elements unused in WMS GetCapabilities response [#115](https://github.com/geotrellis/geotrellis-server/issues/115) - Bad assembly strategy [#142](https://github.com/geotrellis/geotrellis-server/issues/142) diff --git a/ogc-example/src/main/resources/application.conf b/ogc-example/src/main/resources/application.conf index 93d60412..edce81a7 100644 --- a/ogc-example/src/main/resources/application.conf +++ b/ogc-example/src/main/resources/application.conf @@ -222,6 +222,12 @@ layers = { type = "colorrampconf" colors = ${color-ramps.red-to-blue} stops = 64 + }, + { + name = "ndvi" + title = "NDVI colors (for demonstration only)" + type = "colormapconf" + color-map = ${color-maps.ndvi} } ] } @@ -369,4 +375,21 @@ color-maps = { 2500: 0xD7D7D7FF, 3000: 0xFFFFFFFF } + "ndvi": { + -1.0: 0x1947B0FF, + -0.7: 0x3961B7FF, + -0.5: 0x5A7BBFFF, + -0.4: 0x7B95C6FF, + -0.3: 0x9CB0CEFF, + -0.2: 0xBDCAD5FF, + -0.1: 0xDEE4DDFF, + "0": 0xFFFFE5FF, + "0.1": 0xDAE4CAFF, + "0.2": 0xB6C9AFFF, + "0.3": 0x91AF94FF, + "0.4": 0x6D9479FF, + "0.5": 0x487A5EFF, + "0.7": 0x245F43FF, + "1.0": 0x004529FF + } } diff --git a/ogc-example/src/main/scala/geotrellis/server/ogc/conf/package.scala b/ogc-example/src/main/scala/geotrellis/server/ogc/conf/package.scala index c458bdb0..3cc44694 100644 --- a/ogc-example/src/main/scala/geotrellis/server/ogc/conf/package.scala +++ b/ogc-example/src/main/scala/geotrellis/server/ogc/conf/package.scala @@ -24,7 +24,7 @@ import geotrellis.raster.render.{ColorMap, ColorRamp} import com.azavea.maml.ast._ import com.azavea.maml.ast.codec.tree._ -import com.typesafe.config.{ConfigRenderOptions, ConfigValue} +import com.typesafe.config._ import io.circe._ import io.circe.parser._ import pureconfig._ @@ -33,6 +33,8 @@ import pureconfig.generic.FieldCoproductHint import pureconfig.generic.auto._ import scala.util.Try +import scala.collection.JavaConverters._ + /** A grab bag of [[ConfigReader]] instances necessary to read the configuration */ package object conf { @@ -67,9 +69,31 @@ package object conf { ColorRamp(colors.map(java.lang.Long.decode(_).toInt)) } + /** + * HOCON doesn't naturally handle unquoted strings which contain decimals ('.') very well. + * As a result, some special configuration handling is required here to allow unquoted + * strings specifically when we know we're trying to decode a ColorMap. + */ implicit def colormapReader: ConfigReader[ColorMap] = - ConfigReader[Map[String, String]].map { cmap => - ColorMap(cmap.map { case (k, v) => (k.toDouble -> java.lang.Long.decode(v).toInt) }.toMap) + ConfigReader[Map[String, ConfigValue]].map { cmap => + val numericMap = cmap.map({ case (k, v) => + v.valueType match { + case ConfigValueType.OBJECT => + val confmap = v.asInstanceOf[ConfigObject].asScala + val fixedKey: String = k + "." + confmap.keys.head + val fixedValue: String = confmap.values.head.unwrapped.asInstanceOf[String] + fixedKey -> fixedValue + case ConfigValueType.STRING => + k -> v.unwrapped.asInstanceOf[String] + case _ => + k -> v.toString + } + }).map({ case (k, v) => + val key = k.toDouble + val value = java.lang.Long.decode(v).toInt + key -> value + }).toMap + ColorMap(numericMap) } implicit def keywordConfigReader: ConfigReader[opengis.wms.Keyword] =