Tile attribute functions

  • st_dimensions
    Retrieves the dimensions of a tile in pixels.
    Struct[Int, Int] st_dimensions(Tile tile)
  • st_cell_type
    Retrieves the cell type of a tile. You can change the cell type by using st_convert_cell_type.
    Struct[String] st_cell_type(Tile tile)
  • st_tile
    Retrieves fully loaded tiles from ProjectedRasterTile.
    Tile st_tile(ProjectedRasterTile proj_raster)
    Notice ProjectedRasterTile is a subclass of tiles that have a spatial range and reference.
  • st_extent
    Retrieves the spatial range of a tile.
    Struct[Double xmin, Double xmax, Double ymin, Double ymax] st_extent(ProjectedRasterTile proj_raster)
    Struct[Double xmin, Double xmax, Double ymin, Double ymax] st_extent(RasterSource proj_raster)
  • st_crs
    Retrieves Cluster Ready Services (CRS) objects from the coordinate reference system. You can retrieve CRS objects from the coordinate reference system based on the string columns that are in the form supported by st_mk_crs. The coordinate reference system has the tile columns of the ProjectedRasterTile or RasterSource type.
    Struct st_crs(ProjectedRasterTile proj_raster)
    Struct st_crs(RasterSource proj_raster)
    Struct st_crs(String crs_spec)
  • st_proj_raster
    Constructs a ProjectedRasterTile object based on a specified Tile, Extent, and CRS column.
    ProjectedRasterTile st_proj_raster(Tile tile, Extent extent, CRS crs)
  • st_mk_crs
    Generates a CRS object based on the value of crsText.
    Struct st_mk_crs(String crsText)   
    crsText can be one of the following types:
    • EPSG code: EPSG:Int format.
    • Proj4 string: +proj <proj parameter>
    • WKT string that is embedded with the EPSG code: GEOGCS["<name>", <datum>, <prime meridian>, <angular unit> {,<twin axes>} {,<authority>}]

    Example: SELECT rf_mk_crs('EPSG:4326')

  • st_convert_cell_type
    Converts the cell type of a tile.
    Tile st_convert_cell_type(Tile tile_col, CellType cell_type)
    Tile st_convert_cell_type(Tile tile_col, String cell_type)
  • st_interpret_cell_type_as
    Changes the interpretation of cell values in the column specified by tile_col based on the value of cell_type. You can pass the CellType object to cell_type in Python.
    Tile st_interpret_cell_type_as(Tile tile_col, CellType cell_type)
    Tile st_interpret_cell_type_as(Tile tile_col, String cell_type)
  • st_resample
    Resamples the dimensions of a tile. The factor parameter indicates the scale ratio. The value 1.0 indicates the numbers of columns and rows of the original tile. A value less than 1 indicates that the tile is downsampled. A value greater than 1 indicates that the tile is upsampled. The shape_tile parameter is the second parameter and specifies both the column and row numbers of the tile. Resampling is performed by using the Nearest Neighbor Search (NNS) method.
    Tile st_resample(Tile tile, Double factor)
    Tile st_resample(Tile tile, Int factor)
    Tile st_resample(Tile tile, Tile shape_tile)

Vector calculation functions

  • st_extent

    Retrieves the range of the bounding box of a specified spatial feature.

    • Syntax
      Struct[Double xmin, Double xmax, Double ymin, Double ymax] st_extent(Geometry geom)
    • Example
      val boxed = df.select(GEOMETRY_COLUMN, st_extent(GEOMETRY_COLUMN) as "extent")
  • st_reproject
    Reprojects the vector geometry from origin_crs to destination_crs. All CRS objects must be represented in the standard format of the coordinate reference system, such as proj4 string, EPSG code, or WKT.
    • Syntax
      Geometry st_reproject(Geometry geom, String origin_crs, String destination_crs)
    • Example
      SELECT st_reproject(ll, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs', 'EPSG:3857') 
      AS wm4 from geom
  • st_geometry
    Converts an extent object to a geometry object.
    • Syntax
      Geometry st_geometry(Struct[Double xmin, Double xmax, Double ymin, Double ymax] extent)
    • Example
      val geom = df.select(st_geometry(st_extent(GEOMETRY_COLUMN)))
  • st_xz2_index
    Calculates the XZ2 index of a Geometry, Extent, or ProjectedRasterTile object that has the spatial reference of WGS84/EPSG:4326. This function can be used to calculate tiles within a specific range.
    • Syntax
      Long st_xz2_index(Geometry geom, CRS crs)
      Long st_xz2_index(Extent extent, CRS crs)
      Long st_xz2_index(ProjectedRasterTile proj_raster)
    • Example
      val indexes = df.select(st_xz2_index($"extent", serialized_literal(crs))).collect()
  • st_z2_index
    Calculates the Z2 index of a Geometry, Extent, or ProjectedRasterTile object that has the spatial reference of WGS84/EPSG:4326. The system extracts the extent of the spatial object and then calculates the Z2 index of the center point in the extent. This function can be used to calculate tiles within a specific range. This function is automatically called when the system reads raster data.
    • Syntax
      Long st_z2_index(Geometry geom, CRS crs)
      Long st_z2_index(Extent extent, CRS crs)
      Long st_z2_index(ProjectedRasterTile proj_raster)
    • Example
      val crs: CRS = CRS.fromName("EPSG:4326")
      val indexes = df.withColumn("xz2",st_z2_index($"extent", serialized_literal(crs)))
                                       .withColumn("z2",st_z2_index($"extent", serialized_literal(crs)))
      indexes.show
    • Output result:
      +-----------+--------------------+-----------+-------------------+
      |spatial_key|              extent|        xz2|                 z2|
      +-----------+--------------------+-----------+-------------------+
      |     [0, 0]|[118.336550697428... |77880735068|3919866226478294259|
      |     [1, 0]|[118.356350742817... |77880736433|3919866232129151218|
      |     [0, 1]|[118.336550697428... |77880732338|3919865820477424883|
      |     [1, 1]|[118.356350742817... |77880733703|3919865826128281842|
      |     [2, 0]|[118.376150788207... |77880736433|3919866249224287474|
      |     [3, 0]|[118.395950833596... |77880740529|3919866437950910706|
      |     [2, 1]|[118.376150788207... |77880733703|3919865843223418098|
      |     [3, 1]|[118.395950833596... |77880737799|3919866031950041330|
      |     [0, 2]|[118.336550697428... |77880614918|3919865683711796473|
      |     [1, 2]|[118.356350742817... |77880616283|3919865689362653432|
      |     [0, 3]|[118.336550697428... |77880615260|3919859775873615097|
      |     [1, 3]|[118.356350742817... |77880616284|3919859781524472056|
      |     [2, 2]|[118.376150788207... |77880616283|3919865706457789688|
      |     [3, 2]|[118.395950833596... |77880620379|3919865895184412920|
      |     [2, 3]|[118.376150788207... |77880616625|3919859798619608312|
      |     [3, 3]|[118.395950833596... |77880620380|3919859987346231544|
      |     [4, 0]|[118.415750878986... |77880740529|3919866454330795250|
      |     [5, 0]|[118.435550924375... |77880741894|3919866505651495154|
      |     [4, 1]|[118.415750878986... |77880737799|3919866048329925874|
      |     [5, 1]|[118.435550924375... |77880739164|3919866099650625778|
      +-----------+--------------------+-----------+-------------------+

Masking functions

  • st_mask
    Performs the masking operation on a tile. The mask parameter contains NoData.
    Tile st_mask(Tile tile, Tile mask, bool inverse)
  • st_mask_by_value
    Performs the masking operation on a tile. If the value of mask_tile equals the value of mask_value, NoData is used as the value of this function.
    Tile st_mask_by_value(Tile data_tile, Tile mask_tile, Int mask_value, bool inverse)
  • st_mask_by_values
    Retrieves the value of a tile. The value is specified by data_tile. If the value of mask_tile equals the value of mask_values, NoData is used as the value in the pixel position of this function.
    Tile st_mask_by_values(Tile data_tile, Tile mask_tile, Array mask_values)
    Tile st_mask_by_values(Tile data_tile, Tile mask_tile, list mask_values)

Tile formation functions

  • st_make_zeros_tile
    Creates a tile with rows specified by tile_rows and columns specified by tile_columns. The value of the tile is 0, the data type is optional, and the default cell type is float64. All parameters are in the form of text expressions, rather than column expressions.
    Tile rf_make_zeros_tile(Int tile_columns, Int tile_rows, [CellType cell_type])
    Tile rf_make_zeros_tile(Int tile_columns, Int tile_rows, [String cell_type_name])
  • st_make_ones_tile
    Creates a tile with rows specified by tile_rows and columns specified by tile_columns. The value of the tile is 1, the data type is optional, and the default cell type is float64. All parameters are in the form of text expressions, rather than column expressions.
    Tile st_make_ones_tile(Int tile_columns, Int tile_rows, [CellType cell_type])
    Tile st_make_ones_tile(Int tile_columns, Int tile_rows, [String cell_type_name])
  • st_make_constant_tile
    Creates a tile with rows specified by tile_rows and columns specified by tile_columns. The value of the tile is specified by using the constant parameter, the data type is optional, and the default cell type is float64. All parameters are in the form of text expressions, rather than column expressions. Tile st_make_constant_tile(Numeric constant, Int tile_columns, Int tile_rows, [CellType cell_type])Tile st_make_constant_tile(Numeric constant, Int tile_columns, Int tile_rows, [String cell_type_name])
    Tile st_make_constant_tile(Numeric constant, Int tile_columns, Int tile_rows,  [CellType cell_type])
    Tile st_make_constant_tile(Numeric constant, Int tile_columns, Int tile_rows,  [String cell_type_name])
  • st_rasterize
    Converts the geom object of the Geometry type to the tile object. The intersection between geom and tile_bounds is assigned the value specified by the value parameter in the tile. The dimensions of the returned tile are the product of tile_columns and tile_rows. NoData is used to replace the values that are out of the intersection between geom and tile_bounds. The cell type of the returned tile is INT32. Note that the output cell type of the tile is INT.
    Tile st_rasterize(Geometry geom, Geometry tile_bounds, Int value, Int tile_columns, Int tile_rows)
    Note The tile_columns and tile_rows parameters are in the form of text expressions, rather than column expressions. Other parameters are in the form of column expressions.
  • st_assemble_tile
    Creates a tile with the size specified by numRows and numCols from the column cells of a specified index. This function is a reverse of the st_explode_tiles function. This function is intended to be used with GROUP BY. A row with a new tile is generated in each group. The default value is FLOAT64.
    Tile st_assemble_tile(Int colIndex, Int rowIndex, Numeric cellData, Int numCols, Int numRows, [CellType cell_type])
    Tile st_assemble_tile(Int colIndex, Int rowIndex, Numeric cellData, Int numCols, Int numRows, [String cell_type_name])

Algebraic operation functions

  • st_add
    Calculates the sum of tiles within a specified band.
    st_add(Tile tile1, Tile rhs)
    st_add(Tile tile1, Int rhs)
    st_add(Tile tile1, Double rhs)
  • st_substract
    Calculates the difference between tiles within a specified band.
    st_substract(Tile tile1, Tile rhs)
    st_substract(Tile tile1, Int rhs)
    st_substract(Tile tile1, Double rhs)
  • st_multiply
    st_multiply(Tile tile1, Tile rhs)
    st_multiply(Tile tile1, Int rhs)
    st_multiply(Tile tile1, Double rhs)
  • st_divide
    st_divide(Tile tile1, Tile rhs)
    st_divide(Tile tile1, Int rhs)
    st_divide(Tile tile1, Double rhs)
  • st_round
    Tile st_round(Tile tile)
  • st_exp
    Tile st_exp(Tile tile)
  • st_exp2
    Tile st_exp2(Tile tile)
  • st_exp10
    Tile st_exp10(Tile tile)
  • st_abs
    Tile st_abs(Tile tile)
  • st_log
    Tile st_log(Tile tile)
  • st_log10
    Tile st_log10(Tile tile)
  • st_sqrt
    Tile st_sqrt(Tile tile)
  • st_normalized_difference
    Calculates the normalized index between two bands of tiles by using the following formula: (tile1 - tile2)/(tile1 + tile2)
    Tile st_normalized_difference(Tile tile1,Tile tile2)
  • st_rescale
    Rescales the cell value to change its minimum value to 0 and its maximum value to 1. Other values are linearly interpolated within this range. If both the min and max parameters are specified, the value of the min parameter changes to 0 and the value of the max parameter changes to 1. The values that are out of this range are set to 0 or 1. If the min and max parameters are not specified, the minimum and maximum values of the tile are used.
    Tile st_rescale(Tile tile)
    Tile st_rescale(Tile tile, Double min, Double max)
  • st_standardize
    Standardizes tiles by using the mean and stddev parameters. If both parameters are not specified, the value of mean is 0 and the value of stddev is 1.
    st_standardize(Tile tile)
    st_standardize(Tile tile, Double mean, Double stddev)

Tile aggregate functions

  • st_tile_mean
    Calculates the average value of tiles.
    Double st_tile_mean(Tile tile)
  • st_tile_max
    Calculates the maximum value among tiles.
    Double st_tile_max(Tile tile)
  • st_tile_min
    Calculates the minimum value among tiles.
    Double st_tile_min(Tile tile)
  • st_tile_sum
    Calculates the sum of pixel values in tiles.
    Double st_tile_sum(Tile tile)
  • st_tile_stats
    Aggregates and returns the statistical information of the cell values in a tile. The information includes the number of cells, the number of NoData values, maximum value, minimum value, average value, and variance. The NoData values are ignored during the calculation of the maximum value, minimum value, average value, and variance.
    Struct[Long, Long, Double, Double, Double, Double] st_tile_stats(Tile tile)
    Example:
    spark.sql("SELECT rf_tile_stats(rf_make_ones_tile(5, 5, 'float32')) as tile_stats").printSchema()
  • st_tile_approx_histogram
    Collects information about the histograms of tiles.
    Struct[Array[Struct[Double, Long]]] st_tile_approx_histogram(Tile tile)
  • st_agg_extent
    Aggregates the entire extent based on the extents of all tiles.
    Extent st_agg_extent(Extent extent)
  • st_agg_reprojected_extent
    Aggregates the entire extent based on the extents of all tiles and reprojects the entire extent.
    Extent st_agg_reprojected_extent(Extent extent, CRS source_crs, String dest_crs)

Tile conversion functions

  • st_explode_tiles
    Creates a row for each cell in a Tile column. Multiple Tile columns can be passed in and each input parameter contained in the information of the returned DataFrame object has a numeric column. The column_index and row_index columns are also included. This function is a reverse of the rf_assemble_tile function. When you use this function, make sure that each row has a unique identifier so that the reverse operation can be performed.
    Int, Int, Numeric* st_explode_tiles(Tile* tile)
  • st_tile_to_array_int
    Converts Tile columns to the Spark SQL Array type based on the row priority specified by row-major. Cells of the DOUBLE type are converted to the INT type.
    Array st_tile_to_array_int(Tile tile)
  • st_tile_to_array_double
    Converts tile columns to the Spark SQL Array type based on the row priority specified by row-major. Cells of the INT type are converted to the floating point type.
    Array st_tile_to_arry_double(Tile tile)
  • st_render_ascii
    Prints tiles as ASCII text.
    String rf_render_ascii(Tile tile)
  • rf_render_matrix
    Generates a string of numeric values for the cell values of tiles.
    String st_render_matrix(Tile tile)
  • st_render_png
    Renders tiles in the three RGB bands as PNG bytearray.
    Array st_render_png(Tile red, Tile green, Tile blue)
  • st_render_color_ramp_png
    Renders tiles as PNG bytearray based on the specified tiles and color scheme.
    Array st_render_color_ramp_png(Tile tile, String color_ramp_name)
    Valid values of color_ramp_name:
    • "BlueToOrange"
    • "LightYellowToOrange"
    • "BlueToRed"
    • "GreenToRedOrange"
    • "LightToDarkSunset"
    • "LightToDarkGreen"
    • "HeatmapYellowToRed"
    • "HeatmapBlueToYellowToRedSpectrum"
    • "HeatmapDarkRedToYellowWhite"
    • "HeatmapLightPurpleToDarkPurpleToWhite"
    • "ClassificationBoldLandUse"
    • "ClassificationMutedTerrain"
    • "Magma"
    • "Inferno"
    • "Plasma"
    • "Viridis"
    • "Greyscale2"
    • "Greyscale8"
    • "Greyscale32"
    • "Greyscale64"
    • "Greyscale128"
    • "Greyscale256"
    • RT_OverviewRaster
    The bilinear interpolation method is used to generate an overview based on the specified AOI and the dimensions specified by cols and rows. If a tile contains Extent and CRS, the tile_extent_col and tile_crs_col parameters are optional.
    Tile ST_OverviewRaster(Tile proj_raster_col, int cols, int rows, Extent aoi)
    Tile ST_OverviewRaster(Tile tile_col, int cols, int rows, Extent aoi, Extent tile_extent_col, CRS tile_crs_col)
  • st_rgb_composite
    Combines the tiles from the three RGB bands into one RGB tile. During this process, the system converts the value of each cell into a value of the unsigned byte type that ranges from 0 to 255. Then, it combines the three channels as a 32-bit unsigned integer.
    Tile st_rgb_composite(Tile red, Tile green, Tile blue)

DataFrame API operations

Some features do not support SQL functions. In this case, you can call DataFrame API operations to use these features.

  • stitch
    Performs the tiling operation to combine multiple tiles into one tile.
    def stitch(extentCol: Column, tileCol: Column): Tile
    Example:
    val result = spark.sql("SELECT rows,cols,envelope,st_ndvi(red,nir) as ndvi FROM gf2")
    result.stitch($"envelope", $"ndvi").renderPng(ndviColorMap).write("polardb_ndvi.png")
  • transformToZoomLayer
    Performs the single-band spatial tiling operation to convert parameters to the zoom mode and generate a Resilient Distributed Dataset (RDD) model.
    def transformToZoomLayer(rowCol: Column, 
                          colCol: Column, 
                          extentCol: Column, 
                          tileCol: Column)
    :(Int, RDD[(SpatialKey, Tile)] with Metadata[TileLayerMetadata[SpatialKey]])
  • transformToMultibandZoomLayer
    Performs the multi-band spatial tiling operation to convert parameters to the zoom mode and generate an RDD model.
    def transformToMultibandZoomLayer(rowCol: Column, 
                                   colCol: Column, 
                                   extentCol: Column, 
                                   tileCol: Column)
    :(Int, RDD[(SpatialKey, MultibandTile)] with Metadata[TileLayerMetadata[SpatialKey]])
    Example:
    val result = spark.sql("SELECT rows,cols,envelope,st_ndvi(red,nir) as ndvi FROM gf2")
    
    val (zoom, rdd1): (Int, RDD[(SpatialKey, Tile)] with Metadata[TileLayerMetadata[SpatialKey]]) = result.stitchToZoomLayer($"rows",$"cols",$"envelope", $"ndvi")
    val path = "result" // Exports the result to a specified folder by layer.
      val layoutScheme = ZoomedLayoutScheme(WebMercator, tileSize = 256)
      Pyramid.upLevels(rdd1.asInstanceOf[RDD[(SpatialKey, Tile)] with Metadata[TileLayerMetadata[SpatialKey]]], layoutScheme, zoom, NearestNeighbor) { (rdd, z) =>
        val layerId = LayerId("", z)
        println(layerId)
        new File("result/" + z).mkdir()
        rdd.collect().foreach(elem => {
          elem. _2.renderPng(ndviColorMap).write(path + "/" + z + "/" + elem. _1.col + "_" + elem. _1.row + ".png")
        })
      }