Skip to content

Commit

Permalink
Merge branch 'release/5.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadain committed Apr 25, 2022
2 parents 030e666 + 6753a1f commit dcf2fc1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 5.3.0

- Add RasterGroupedCountMany operation that can take a list of input polygons
and returns a list of histograms, for each polygon in order. This is useful
for models that have spatial modifications, and need to get results for many
of them at once.

## 5.2.0

- Make application settings overridable by environment variables, so that
Expand Down
21 changes: 21 additions & 0 deletions api/src/main/scala/Geoprocessing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ trait Geoprocessing extends Utils {
}
}

/**
* For an InputData with multiple polygons, return a histogram of raster
* grouped count results for each of those polygons.
*
* @param input The InputData
* @return A sequence of histograms of results
*/
def getRasterGroupedCountMany(input: InputData): Future[ResultManyInt] = {
val aois = createAOIsFromInput(input)
val futureLayers =
cropRastersToAOI(
input.rasters,
input.zoom,
aois.unionGeometries.asMultiPolygon.get)
val opts = getRasterizerOptions(input.pixelIsArea)

futureLayers.map { layers =>
ResultManyInt(aois.map { aoi => rasterGroupedCount(layers, aoi, opts) })
}
}

/**
* For an InputData object, return a histogram of raster grouped average
* results.
Expand Down
14 changes: 14 additions & 0 deletions api/src/main/scala/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ trait Utils {
.get
}

/**
* Given input data containing a polygonCRS & a raster CRS, transform a
* a list of input polygon strings into a sequence of MultiPolygons
*
* @param input InputData including polygons, polygonCRS, and rasterCRS
* @return A Sequence of MultiPolygons
*/
def createAOIsFromInput(input: InputData): Seq[MultiPolygon] = {
val parseGeom =
parseGeometry(_: String, getCRS(input.polygonCRS), getCRS(input.rasterCRS))

input.polygon.map { str => parseGeom(str).buffer(0).asMultiPolygon.get }
}

/**
* Converts a HUC shape into a reprojected and normalized MultiPolygon
* Assumes input is in LatLng and rasters are in ConusAlbers
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/scala/WebServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ case class PostRequest(input: InputData)
case class ResultInt(result: Map[String, Int])
case class ResultDouble(result: Map[String, Double])
case class ResultSummary(result: Seq[Map[String, Double]])
case class ResultManyInt(result: Seq[Map[String, Int]])

// HUCs have an id and a shape. The shape is GeoJSON, but we've transmitted
// them as Strings in the past so we continue to do so here.
Expand Down Expand Up @@ -53,6 +54,7 @@ object PostRequestProtocol extends DefaultJsonProtocol {
implicit val resultFormat = jsonFormat1(ResultInt)
implicit val resultDoubleFormat = jsonFormat1(ResultDouble)
implicit val resultSummaryFormat = jsonFormat1(ResultSummary)
implicit val resultManyIntFormat = jsonFormat1(ResultManyInt)

implicit val hucFormat = jsonFormat2(HUC)
implicit val operationFormat = jsonFormat5(Operation)
Expand All @@ -76,6 +78,8 @@ object WebServer extends HttpApp with App with LazyLogging with Geoprocessing wi
data.input.operationType match {
case "RasterGroupedCount" =>
complete(getRasterGroupedCount(data.input))
case "RasterGroupedCountMany" =>
complete(getRasterGroupedCountMany(data.input))
case "RasterGroupedAverage" =>
complete(getRasterGroupedAverage(data.input))
case "RasterLinesJoin" =>
Expand Down
19 changes: 19 additions & 0 deletions examples/TR55_RasterGroupedCountMany.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"input": {
"polygon": [
"{\"type\": \"MultiPolygon\", \"coordinates\": [[[[-76.214368343, 40.054777467], [-76.215591431, 40.054350433], [-76.215430498, 40.053668816], [-76.218445301, 40.052946129], [-76.217275858, 40.050465943], [-76.215344667, 40.050999765], [-76.215612888, 40.051640347], [-76.213306189, 40.052133098], [-76.214368343, 40.054777467]]]]}",
"{\"type\": \"Polygon\", \"coordinates\": [[[-76.21552399034168, 40.054064794260896], [-76.21392306562677, 40.05366889170663], [-76.21355687864876, 40.05275722212493], [-76.21412648827955, 40.05195786781596], [-76.21483089569675, 40.05180739414808], [-76.21524692156184, 40.052762738523796], [-76.21475458145142, 40.05289687621089], [-76.21548538666218, 40.05331033979461], [-76.21562154952683, 40.05362301849523], [-76.215430498, 40.053668816], [-76.21552399034168, 40.054064794260896]]]}",
"{\"type\": \"Polygon\", \"coordinates\": [[[-76.21690034866333, 40.05299542487784], [-76.21572017669678, 40.052223456506226], [-76.21702909469604, 40.05191138170397], [-76.21690034866333, 40.05299542487784]]]}",
"{\"type\": \"Polygon\", \"coordinates\": [[[-76.21524692156184, 40.052762738523796], [-76.21548538666218, 40.05331033979461], [-76.21475458145142, 40.05289687621089], [-76.21524692156184, 40.052762738523796]]]}",
"{\"type\": \"Polygon\", \"coordinates\": [[[-76.2159140998055, 40.05355289043604], [-76.21548538666218, 40.05331033979461], [-76.21524692156184, 40.052762738523796], [-76.21602058410645, 40.052551954754364], [-76.21619019297006, 40.05348670735846], [-76.2159140998055, 40.05355289043604]]]}"
],
"polygonCRS": "LatLng",
"rasters": [
"nlcd-2011-30m-epsg5070-512-int8",
"ssurgo-hydro-groups-30m-epsg5070-512-int8"
],
"rasterCRS": "ConusAlbers",
"operationType": "RasterGroupedCountMany",
"zoom": 0
}
}
2 changes: 1 addition & 1 deletion project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Geoprocessing extends Build {
super.settings ++
Seq(
shellPrompt := { s => Project.extract(s).currentProject.id + " > " },
version := "5.2.0",
version := "5.3.0",
scalaVersion := Version.scala,
organization := "org.wikiwatershed.mmw.geoprocessing",
name := "mmw-geoprocessing",
Expand Down

0 comments on commit dcf2fc1

Please sign in to comment.