Skip to content

Issue #392 added support for "array_contains" in the OpenEOProcessScr… #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,37 @@ class OpenEOProcessScriptBuilder {
contextStack.head.getOrElse(name, null).asInstanceOf[OpenEOProcess]
}

private def arrayContains(arguments:java.util.Map[String,Object]) : OpenEOProcess = {
val value = getProcessArg("value")
val data = getProcessArg("data")

val arrayContainsProcess = (context: Map[String, Any]) => (tiles: Seq[Tile]) => {
val valueInput: Seq[Tile] = evaluateToTiles(value, context, tiles)
val dataInput: Seq[Tile] = evaluateToTiles(data, context, tiles)
if (valueInput.size != 1) {
throw new IllegalArgumentException(f"The value argument of the array_contains function should resolve to exactly one input, got ${valueInput.size}.")
}
val theValue = valueInput.head
val tile = MultibandTile(dataInput)

val mutableResult:MutableArrayTile = ArrayTile.empty(BitCellType,tile.cols,tile.rows)
for (column <- Range(0, tile.cols)) {
for (row <- Range(0, tile.rows)) {
breakable {
for (band <- tile.bands) {
if (band.get(column, row) == theValue.get(column, row)) {
mutableResult.set(column, row, 1)
break
}
}
}
}
}
Seq(mutableResult)
}

arrayContainsProcess
}

private def arrayFind(arguments:java.util.Map[String,Object]) : OpenEOProcess = {
val storedArgs = contextStack.head
Expand Down Expand Up @@ -1203,6 +1234,7 @@ class OpenEOProcessScriptBuilder {
case "array_modify" => arrayModifyFunction(arguments)
case "array_interpolate_linear" => applyListFunction("data", linearInterpolation, dataTypeMode = PRESERVE_DATATYPE_MODE)
case "array_find" => arrayFind(arguments)
case "array_contains" => arrayContains(arguments)
case "linear_scale_range" => linearScaleRangeFunction(arguments)
case "quantiles" => quantilesFunction(arguments, ignoreNoData)
case "array_concat" => arrayConcatFunction(arguments)
Expand Down
Loading