Created
February 6, 2019 03:43
-
-
Save echeipesh/d8110c8d57f9f6ece3d41fdfbd37dfb2 to your computer and use it in GitHub Desktop.
ConfigReader[RasterSource] for pureconfig 0.10.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package geotrellis.server.ogc.conf | |
import pureconfig._ | |
import pureconfig.error.{ConfigReaderFailures, NoValidCoproductChoiceFound} | |
import geotrellis.contrib.vlm.RasterSource | |
import geotrellis.contrib.vlm.avro.GeotrellisRasterSource | |
import geotrellis.contrib.vlm.gdal.GDALRasterSource | |
import geotrellis.contrib.vlm.geotiff.GeoTiffRasterSource | |
import geotrellis.spark.LayerId | |
trait RasterSourceConf { | |
private def readGeoTrellisRasterSourceConf(objCur: ConfigObjectCursor): Either[ConfigReaderFailures, GeotrellisRasterSource] = { | |
for { | |
uriCur <- objCur.atKey("catalog-uri").right | |
uri <- uriCur.asString.right | |
layerCur <- objCur.atKey("layer").right | |
layerName <- layerCur.asString.right | |
zoomCur <- objCur.atKey("zoom").right | |
zoom <- zoomCur.asInt.right | |
bandCur <- objCur.atKey("band-count").right | |
band <- bandCur.asInt.right | |
} yield GeotrellisRasterSource(uri, LayerId(layerName, zoom), band) | |
} | |
private def readGeoTiffRasterSourceConf(objCur: ConfigObjectCursor): Either[ConfigReaderFailures, GeoTiffRasterSource] = { | |
for { | |
uriCur <- objCur.atKey("uri").right | |
uri <- uriCur.asString.right | |
} yield GeoTiffRasterSource(uri) | |
} | |
private def readGDALRasterSourceConf(objCur: ConfigObjectCursor): Either[ConfigReaderFailures, GDALRasterSource] = { | |
for { | |
uriCur <- objCur.atKey("uri").right | |
uri <- uriCur.asString.right | |
} yield GDALRasterSource(uri) | |
} | |
implicit val rasterSourceReader = ConfigReader.fromCursor[RasterSource] { cur => | |
for { | |
objCur <- cur.asObjectCursor.right | |
typeCur <- objCur.atKey("type").right | |
typeName <- typeCur.asString.right | |
source <- {typeName match { | |
case "geotrellis" => readGeoTrellisRasterSourceConf(objCur) | |
case "geotiff" => readGeoTiffRasterSourceConf(objCur) | |
case "gdal" => readGDALRasterSourceConf(objCur) | |
case _ => typeCur.failed(NoValidCoproductChoiceFound(typeCur.value)) | |
}}.right | |
} yield source | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment