@@ -59,6 +59,22 @@ trait RasterFunctions {
5959 /** Extracts the bounding box from a RasterSource or ProjectedRasterTile */
6060 def rf_extent (col : Column ): TypedColumn [Any , Extent ] = GetExtent (col)
6161
62+ /** Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
63+ * For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
64+ def rf_spatial_index (targetExtent : Column , targetCRS : Column , indexResolution : Short ) = XZ2Indexer (targetExtent, targetCRS, indexResolution)
65+
66+ /** Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
67+ * For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
68+ def rf_spatial_index (targetExtent : Column , targetCRS : Column ) = XZ2Indexer (targetExtent, targetCRS, 18 : Short )
69+
70+ /** Constructs a XZ2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
71+ * For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
72+ def rf_spatial_index (targetExtent : Column , indexResolution : Short ) = XZ2Indexer (targetExtent, indexResolution)
73+
74+ /** Constructs a XZ2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
75+ * For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
76+ def rf_spatial_index (targetExtent : Column ) = XZ2Indexer (targetExtent, 18 : Short )
77+
6278 /** Extracts the CRS from a RasterSource or ProjectedRasterTile */
6379 def rf_crs (col : Column ): TypedColumn [Any , CRS ] = GetCRS (col)
6480
@@ -276,12 +292,38 @@ trait RasterFunctions {
276292 }
277293
278294 /** Where the rf_mask tile contains NODATA, replace values in the source tile with NODATA */
279- def rf_mask (sourceTile : Column , maskTile : Column ): TypedColumn [Any , Tile ] =
280- Mask .MaskByDefined (sourceTile, maskTile)
295+ def rf_mask (sourceTile : Column , maskTile : Column ): TypedColumn [Any , Tile ] = rf_mask(sourceTile, maskTile, false )
296+
297+ /** Where the rf_mask tile contains NODATA, replace values in the source tile with NODATA */
298+ def rf_mask (sourceTile : Column , maskTile : Column , inverse : Boolean = false ): TypedColumn [Any , Tile ] =
299+ if (! inverse) Mask .MaskByDefined (sourceTile, maskTile)
300+ else Mask .InverseMaskByDefined (sourceTile, maskTile)
301+
302+ /** Where the `maskTile` equals `maskValue`, replace values in the source tile with `NoData` */
303+ def rf_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Column , inverse : Boolean = false ): TypedColumn [Any , Tile ] =
304+ if (! inverse) Mask .MaskByValue (sourceTile, maskTile, maskValue)
305+ else Mask .InverseMaskByValue (sourceTile, maskTile, maskValue)
281306
282307 /** Where the `maskTile` equals `maskValue`, replace values in the source tile with `NoData` */
283- def rf_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Column ): TypedColumn [Any , Tile ] =
284- Mask .MaskByValue (sourceTile, maskTile, maskValue)
308+ def rf_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Int , inverse : Boolean ): TypedColumn [Any , Tile ] =
309+ rf_mask_by_value(sourceTile, maskTile, lit(maskValue), inverse)
310+
311+ /** Where the `maskTile` equals `maskValue`, replace values in the source tile with `NoData` */
312+ def rf_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Int ): TypedColumn [Any , Tile ] =
313+ rf_mask_by_value(sourceTile, maskTile, maskValue, false )
314+
315+ /** Generate a tile with the values from `data_tile`, but where cells in the `mask_tile` are in the `mask_values`
316+ list, replace the value with NODATA. */
317+ def rf_mask_by_values (sourceTile : Column , maskTile : Column , maskValues : Column ): TypedColumn [Any , Tile ] =
318+ Mask .MaskByValues (sourceTile, maskTile, maskValues)
319+
320+ /** Generate a tile with the values from `data_tile`, but where cells in the `mask_tile` are in the `mask_values`
321+ list, replace the value with NODATA. */
322+ def rf_mask_by_values (sourceTile : Column , maskTile : Column , maskValues : Seq [Int ]): TypedColumn [Any , Tile ] = {
323+ import org .apache .spark .sql .functions .array
324+ val valuesCol : Column = array(maskValues.map(lit).toSeq: _* )
325+ rf_mask_by_values(sourceTile, maskTile, valuesCol)
326+ }
285327
286328 /** Where the `maskTile` does **not** contain `NoData`, replace values in the source tile with `NoData` */
287329 def rf_inverse_mask (sourceTile : Column , maskTile : Column ): TypedColumn [Any , Tile ] =
@@ -291,6 +333,10 @@ trait RasterFunctions {
291333 def rf_inverse_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Column ): TypedColumn [Any , Tile ] =
292334 Mask .InverseMaskByValue (sourceTile, maskTile, maskValue)
293335
336+ /** Where the `maskTile` does **not** equal `maskValue`, replace values in the source tile with `NoData` */
337+ def rf_inverse_mask_by_value (sourceTile : Column , maskTile : Column , maskValue : Int ): TypedColumn [Any , Tile ] =
338+ Mask .InverseMaskByValue (sourceTile, maskTile, lit(maskValue))
339+
294340 /** Create a tile where cells in the grid defined by cols, rows, and bounds are filled with the given value. */
295341 def rf_rasterize (geometry : Column , bounds : Column , value : Column , cols : Int , rows : Int ): TypedColumn [Any , Tile ] =
296342 withTypedAlias(" rf_rasterize" , geometry)(
@@ -389,6 +435,12 @@ trait RasterFunctions {
389435 /** Cellwise inequality comparison between a tile and a scalar. */
390436 def rf_local_unequal [T : Numeric ](tileCol : Column , value : T ): Column = Unequal (tileCol, value)
391437
438+ /** Test if each cell value is in provided array */
439+ def rf_local_is_in (tileCol : Column , arrayCol : Column ) = IsIn (tileCol, arrayCol)
440+
441+ /** Test if each cell value is in provided array */
442+ def rf_local_is_in (tileCol : Column , array : Array [Int ]) = IsIn (tileCol, array)
443+
392444 /** Return a tile with ones where the input is NoData, otherwise zero */
393445 def rf_local_no_data (tileCol : Column ): Column = Undefined (tileCol)
394446
0 commit comments