Skip to content

Commit

Permalink
Merge branch 'release/0.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
James McClain committed Nov 12, 2015
2 parents 3790b60 + 3f41d8c commit 2dd2f70
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 10 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@ deploy:
file:
- sample/breaks/nlcd.data
- sample/breaks/tr.data
- sample/layers/landsatNir.json
- sample/layers/canopy2001.json
- sample/layers/census2010popsqmi.json
- sample/layers/census2010popsqmiQuantile.json
- sample/layers/census2010totalpop.json
- sample/layers/census2010totalpopQuantile.json
- sample/layers/census2013income.json
- sample/layers/census2013incomeQuantile.json
- sample/layers/elevation.json
- sample/layers/impervious2001.json
- sample/layers/impervious2011.json
- sample/layers/landcover2006.json
- sample/layers/landcover2011.json
- sample/layers/landsatBlue.json
- sample/layers/landsatGreen.json
- sample/layers/landsatNir.json
- sample/layers/landsatRed.json
- sample/layers/water.json
- sample/layers/nlcd.json
- sample/layers/reclass2011.json
- sample/layers/trees2011.json
- sample/layers/water2011.json
- target/scala-2.10/modellab-geoprocessing-assembly-${TRAVIS_TAG}.jar
skip_cleanup: true
on:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.3

- A bug affecting the Focal Slope and Focal Aspect functions has been corrected.
- Extra keys supplied in the JSON structure given to the layer-registration endpoint are now passed through in the endpoint's response.
- New sample layers have been added.

## 0.2.2

- A minor error in the Travis configuration file was corrected.
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "com.azavea.modellab"
name := "modellab-geoprocessing"
version := "0.2.2"
version := "0.2.3"

Common.settings

Expand Down
4 changes: 4 additions & 0 deletions sample/layers/canopy2001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-nlcd2001-canopy-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2010popsqmi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2010-block-popsqmi-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2010popsqmiQuantile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2010-block-popsqmi-quantile-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2010totalpop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2010-block-totalpop-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2010totalpopQuantile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2010-block-totalpop-quantile-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2013income.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2013-blockgroup-income-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/census2013incomeQuantile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-census2013-blockgroup-income-quantile-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/landcover2006.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-nlcd2006-landcover-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/landcover2011.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-nlcd2011-landcover-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/reclass2011.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-nlcd2011-reclass-30m-epsg3857"
}
4 changes: 4 additions & 0 deletions sample/layers/trees2011.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "LoadLayer",
"layer_name": "us-pennsylvania-philadelphia-nlcd2011-trees-30m-epsg3857"
}
File renamed without changes.
11 changes: 11 additions & 0 deletions sample/tools/FocalSlope.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "FocalSlope",
"neighborhood": {
"shape": "square",
"size": 1
},
"z_factor": 1,
"inputs": [
"GVWWZ5Y"
]
}
39 changes: 39 additions & 0 deletions src/main/scala/com/azavea/modellab/JsonMerge.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.azavea.modellab

import spray.json._

import scala.util.Try

object JsonMerge {
/** merge two maps, source values preferentially from left map */
def mergeMaps(m1: Map[String, JsValue], m2: Map[String, JsValue]): Map[String, JsValue] = {
for (key <- m1.keySet ++ m2.keySet) yield {
val value: JsValue = m1.get(key) match {
case Some(left: JsObject) =>
m2.get(key) match {
case Some(right) => JsonMerge(left, right)
case None => left
}
case Some(left: JsArray) =>
m2.get(key) match {
case Some(right: JsArray) =>
JsArray(for ( (l, r) <- left.elements zip right.elements )
yield JsonMerge(l, r))
case _ => left
}
case Some(j: JsValue) =>
j
case None =>
m2(key)
}
key -> value
}
}.toMap

/** Merge two Json trees, recursion through object, preferring values on lefts side in conflict. */
def apply(o1: JsValue, o2: JsValue): JsValue = {
Try{
JsObject(mergeMaps(o1.asJsObject.fields, o2.asJsObject.fields))
}.getOrElse(o1)
}
}
6 changes: 3 additions & 3 deletions src/main/scala/com/azavea/modellab/NodeFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NodeFormats(windowedReader: WindowedReader, layerLookup: String => Option[
case "FocalAspect" =>
FocalAspectFormat.read(json)
case "FocalSlope" =>
SlopeOpFormat.read(json)
FocalSlopeFormat.read(json)
case "MapValues" =>
MapValuesFormat.read(json)
case name if name.startsWith("Local") =>
Expand All @@ -48,7 +48,7 @@ class NodeFormats(windowedReader: WindowedReader, layerLookup: String => Option[
case op: Focal =>
FocalFormat.write(op)
case op: FocalSlope =>
SlopeOpFormat.write(op)
FocalSlopeFormat.write(op)
case op: FocalAspect =>
FocalAspectFormat.write(op)
case op: MapValues =>
Expand Down Expand Up @@ -163,7 +163,7 @@ class NodeFormats(windowedReader: WindowedReader, layerLookup: String => Option[
writeNode(o, "FocalAspect", "neighborhood" -> o.n.toJson)
}

implicit object SlopeOpFormat extends JsonFormat[FocalSlope] {
implicit object FocalSlopeFormat extends JsonFormat[FocalSlope] {
def read(json: JsValue) = {
require(json.inputs.size == 1, "FocalAspect expect one layer input")
FocalSlope(json.inputs.head, json.param[Neighborhood]("neighborhood"), json.param[Double]("z_factor"))
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/azavea/modellab/Service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ object Service extends SimpleRoutingApp with DataHubCatalog with Instrumented wi
requestInstance { req =>
respondWithHeader(RawHeader("Access-Control-Allow-Origin", "*")) {
complete {
val json = req.entity.asString.parseJson
registry.register(json)
val requestJson = req.entity.asString.parseJson
val renderedJson = registry.register(requestJson)
JsonMerge(renderedJson, requestJson).asJsObject
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/azavea/modellab/op/FocalAspect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ case class FocalAspect(
def calc(zoom: Int, bounds: GridBounds) = {
val rasterRDD = input(zoom, bounds)
val cs = rasterRDD.metaData.layout.rasterExtent.cellSize
rasterRDD.mapTiles { tile => Aspect(tile, n, None, cs) }
val _n = n
rasterRDD.mapTiles { tile => Aspect(tile, _n, None, cs) }
}

def inputs = Seq(input)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/azavea/modellab/op/FocalSlope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ case class FocalSlope(
def calc(zoom: Int, bounds: GridBounds) = {
val rasterRDD = input(zoom, bounds)
val cs = rasterRDD.metaData.layout.rasterExtent.cellSize
rasterRDD.mapTiles { tile => Slope(tile, n, None, cs, z) }
val _z = z
val _n = n
rasterRDD.mapTiles { tile => Slope(tile, _n, None, cs, _z) }
}

def inputs = Seq(input)
Expand Down

0 comments on commit 2dd2f70

Please sign in to comment.