geotrellis.raster.mapalgebra.focal.Median.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geotrellis-raster_2.11 Show documentation
Show all versions of geotrellis-raster_2.11 Show documentation
GeoTrellis is an open source geographic data processing engine for high performance applications.
The newest version!
package geotrellis.raster.mapalgebra.focal
import geotrellis.raster._
object Median {
def calculation(tile: Tile, n: Neighborhood, bounds: Option[GridBounds]): FocalCalculation[Tile] = {
n match {
case Square(ext) => new CellwiseMedianCalc(tile, n, bounds, ext)
case _ => new CursorMedianCalc(tile, n, bounds, n.extent)
}
}
def apply(tile: Tile, n: Neighborhood, bounds: Option[GridBounds]): Tile =
calculation(tile, n, bounds).execute()
}
class CursorMedianCalc(r: Tile, n: Neighborhood, bounds: Option[GridBounds], extent: Int)
extends CursorCalculation[Tile](r, n, bounds)
with IntArrayTileResult
with MedianModeCalculation
{
initArray(extent)
def calc(r: Tile, cursor: Cursor) = {
cursor.removedCells.foreach { (x, y) =>
val v = r.get(x, y)
if(isData(v)) {
removeValue(v)
}
}
cursor.addedCells.foreach { (x, y) =>
val v = r.get(x, y)
if(isData(v)) addValueOrdered(v)
}
resultTile.set(cursor.col, cursor.row, median)
}
}
class CellwiseMedianCalc(r: Tile, n: Neighborhood, bounds: Option[GridBounds], extent: Int)
extends CellwiseCalculation[Tile](r, n, bounds)
with IntArrayTileResult
with MedianModeCalculation
{
initArray(extent)
def add(r: Tile, x: Int, y: Int) = {
val v = r.get(x, y)
if (isData(v)) {
addValueOrdered(v)
}
}
def remove(r: Tile, x: Int, y: Int) = {
val v = r.get(x, y)
if (isData(v)) {
removeValue(v)
}
}
def setValue(x: Int, y: Int) = { resultTile.setDouble(x, y, median) }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy