MobilitySpark

MobilitySpark registers its functions on every Spark session whose configuration names org.mobilitydb.spark.catalyst.MobilitySparkExtensions in spark.sql.extensions. Its version is mobilitysparkVersion() and its full version mobilitysparkFullVersion(). A Spark session can also hold the rasters of Apache Sedona beside those of MobilityDB.

Spark and Apache Sedona

Apache Sedona registers its raster type and its RS_ functions in a Spark session through SedonaContext.create(spark), beside the functions of MobilitySpark; none of the names of either is a name of the other. A Sedona raster is a value, read from a file with RS_FromGeoTiff and written with RS_AsGeoTiff, and it converts to and from a MobilityDB raster through the functions both already have: the georeferencing passes through the accessors of each, and the values of a band as an array.

A Sedona raster is built from a MobilityDB raster r by RS_MakeEmptyRaster with the georeferencing of r and RS_AddBandFromArray with the values of a band, its pixel type and its nodata value. A MobilityDB raster is built from a Sedona raster s by raster(pixels, width, height, upperleftx, upperlefty, scalex, scaley, skewx, skewy, srid, pixeltype[, nodataval]) over the RS_ accessors of s, its pixels being the bytes of the values of RS_BandAsArray(s, 1) in their order; each value becomes its bytes as the pixel of a one-pixel band, rasterPixels(addBand(makeEmptyRaster(1, 1, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0), 1, pixeltype, v), 1). Both directions read one band; a raster of several bands converts band by band.

The six pixel types Sedona holds convert both ways, with or without a nodata value, without changing a value, and a raster converted to Sedona and back is the raster it was, byte for byte; the others have no Sedona raster.

-- A Sedona raster from the georeferencing and the band of a MobilityDB raster r
SELECT RS_AddBandFromArray(
    RS_MakeEmptyRaster(1, CASE rasterBandPixelType(r, 1) WHEN 'uint8' THEN 'B'
        WHEN 'int16' THEN 'S' WHEN 'uint16' THEN 'US' WHEN 'int32' THEN 'I'
        WHEN 'float32' THEN 'F' WHEN 'float64' THEN 'D' END,
      rasterWidth(r), rasterHeight(r), upperLeftX(r), upperLeftY(r),
      scaleX(r), scaleY(r), skewX(r), skewY(r), SRID(r)),
    flatten(dumpValues(r, 1, false)), 1, rasterBandNoDataValue(r, 1)) AS s
FROM t;