-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
server/src/main/scala/com/azavea/usaceflood/server/FloodPointValue.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.azavea.usaceflood.server | ||
|
||
import geotrellis.vector._ | ||
import geotrellis.raster._ | ||
import geotrellis.spark._ | ||
|
||
import org.apache.spark._ | ||
|
||
object FloodPointValue { | ||
/** | ||
* Takes a polygon, flood level, zoom level and tile coordinates, and a point. | ||
* Returns the flood amount at that point. | ||
* | ||
* @param tile The tile to get data from | ||
* @param extent Extent to restrict search to | ||
* @param point Point in EPSG:4269 to get output for | ||
* @param minElevation Minimum elevation under this polygon | ||
* @param floodLevel Flood level to use for determining cell flooding | ||
* | ||
* @return Flood level at that point | ||
*/ | ||
def apply(tile: Tile, extent: Extent, point: Point, minElevation: Double, floodLevel: Double)(implicit sc: SparkContext): Double = { | ||
val (col, row) = RasterExtent(extent, tile.cols, tile.rows).mapToGrid(point.x, point.y) | ||
val elevation = tile.getDouble(col, row) | ||
|
||
getFlooding(elevation, minElevation, floodLevel) | ||
} | ||
|
||
/** | ||
* Given the elevation value at a point, and a minElevation and floodLevel, | ||
* returns the flood value at that point. | ||
* | ||
* @param elevation Elevation of this point | ||
* @param minElevation Minimum elevation of the polygon in which this point belongs | ||
* @param floodLevel Flood level to use for determining cell flooding | ||
* @return | ||
*/ | ||
def getFlooding(elevation: Double, minElevation: Double, floodLevel: Double): Double = | ||
if (isData(elevation) && elevation - minElevation < floodLevel) { | ||
floodLevel - (elevation - minElevation) | ||
} else { | ||
Double.NaN | ||
} | ||
} |
This file contains 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
This file contains 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