Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for colormap with floating point keys #206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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
- Non-integer (floating point) ColorMap keys now work with or without being quoted [#187](https://github.com/geotrellis/geotrellis-server/issues/187)
- Missing `<ows:Title>` and `<ows:Abstract>` 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)
Expand Down
23 changes: 23 additions & 0 deletions ogc-example/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
]
}
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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 {
Expand Down Expand Up @@ -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] =
Expand Down