@@ -3,7 +3,7 @@ package org.openeo.geotrellis
3
3
import ai .catboost .CatBoostModel
4
4
import ai .catboost .spark .CatBoostClassificationModel
5
5
import geotrellis .raster .mapalgebra .local ._
6
- import geotrellis .raster .{ArrayTile , BitCellType , ByteUserDefinedNoDataCellType , CellType , ConstantTile , Dimensions , DoubleConstantNoDataCellType , DoubleConstantTile , FloatConstantNoDataCellType , FloatConstantTile , IntConstantNoDataCellType , IntConstantTile , MultibandTile , MutableArrayTile , NODATA , ShortConstantNoDataCellType , ShortConstantTile , Tile , UByteCells , UByteConstantTile , UByteUserDefinedNoDataCellType , UShortCells , UShortUserDefinedNoDataCellType , isData , isNoData }
6
+ import geotrellis .raster .{ArrayTile , BitCellType , BitConstantTile , ByteUserDefinedNoDataCellType , CellType , ConstantTile , Dimensions , DoubleConstantNoDataCellType , DoubleConstantTile , FloatConstantNoDataCellType , FloatConstantTile , IntConstantNoDataCellType , IntConstantTile , MultibandTile , MutableArrayTile , NODATA , ShortConstantNoDataCellType , ShortConstantTile , Tile , UByteCells , UByteConstantTile , UByteUserDefinedNoDataCellType , UShortCells , UShortUserDefinedNoDataCellType , isData , isNoData }
7
7
import org .apache .commons .math3 .exception .NotANumberException
8
8
import org .apache .commons .math3 .stat .descriptive .rank .Percentile
9
9
import org .apache .commons .math3 .stat .descriptive .rank .Percentile .EstimationType
@@ -21,11 +21,10 @@ import java.time.temporal.{ChronoUnit, TemporalAccessor}
21
21
import java .time .{Duration , ZonedDateTime }
22
22
import java .util
23
23
import scala .Double .NaN
24
- import scala .collection .JavaConversions .mapAsScalaMap
24
+ import scala .collection .JavaConverters .mapAsScalaMap
25
25
import scala .collection .JavaConverters .collectionAsScalaIterableConverter
26
26
import scala .collection .mutable .{ArrayBuffer , ListBuffer }
27
27
import scala .collection .{immutable , mutable }
28
- import scala .math .BigDecimal
29
28
import scala .util .Try
30
29
import scala .util .control .Breaks .{break , breakable }
31
30
@@ -633,6 +632,37 @@ class OpenEOProcessScriptBuilder {
633
632
contextStack.head.getOrElse(name, null ).asInstanceOf [OpenEOProcess ]
634
633
}
635
634
635
+ private def arrayContains (arguments: java.util.Map [String ,Object ]) : OpenEOProcess = {
636
+ val value = getProcessArg(" value" )
637
+ val data = getProcessArg(" data" )
638
+
639
+ val arrayContainsProcess = (context : Map [String , Any ]) => (tiles : Seq [Tile ]) => {
640
+ val value_input : Seq [Tile ] = evaluateToTiles(value, context, tiles)
641
+ val data_input : Seq [Tile ] = evaluateToTiles(data, context, tiles)
642
+ if (value_input.size != 1 ) {
643
+ throw new IllegalArgumentException (" The value argument of the array_contains function should resolve to exactly one input." )
644
+ }
645
+ val the_value = value_input.head
646
+ val tile = MultibandTile (data_input)
647
+
648
+ val mutableResult : MutableArrayTile = ArrayTile .empty(BitCellType ,tile.cols,tile.rows)
649
+ for (column <- Range (0 , tile.cols)) {
650
+ for (row <- Range (0 , tile.rows)) {
651
+ breakable {
652
+ for (band <- tile.bands) {
653
+ if (band.get(column, row) == the_value.get(column, row)) {
654
+ mutableResult.set(column, row, 1 )
655
+ break
656
+ }
657
+ }
658
+ }
659
+ }
660
+ }
661
+ Seq (mutableResult)
662
+ }
663
+
664
+ arrayContainsProcess
665
+ }
636
666
637
667
private def arrayFind (arguments: java.util.Map [String ,Object ]) : OpenEOProcess = {
638
668
val storedArgs = contextStack.head
@@ -1203,6 +1233,7 @@ class OpenEOProcessScriptBuilder {
1203
1233
case " array_modify" => arrayModifyFunction(arguments)
1204
1234
case " array_interpolate_linear" => applyListFunction(" data" , linearInterpolation, dataTypeMode = PRESERVE_DATATYPE_MODE )
1205
1235
case " array_find" => arrayFind(arguments)
1236
+ case " array_contains" => arrayContains(arguments)
1206
1237
case " linear_scale_range" => linearScaleRangeFunction(arguments)
1207
1238
case " quantiles" => quantilesFunction(arguments, ignoreNoData)
1208
1239
case " array_concat" => arrayConcatFunction(arguments)
0 commit comments