From ef90b92b8f9f91924a25f93d0bb7ede584ed87b9 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 15 Oct 2026 10:56:17 +0200 Subject: [PATCH] Read a raster derived by arithmetic along a trip on the typed Spark surface GeneratedSqlSurfaceTest.aRasterDerivedByArithmeticIsReadAlongATrip reads a 3x3 depth raster, built from the hex WKB PostGIS writes for it, along a trip in the same reference system. The depth less a draught of 8.5, rasterSub(depth, 8.5), reads along the trip as MobilityDB answers rasterValue(trip, depth - 8.5) in its raster regression test, and the depth added to itself and halved, rasterDiv(rasterAdd(depth, depth), 2.0), or multiplied by itself and divided by itself, rasterDiv(rasterMul(depth, depth), depth), reads as the depth itself, so each of the four arithmetic functions is called in its raster-number or raster-raster form. --- .../spark/GeneratedSqlSurfaceTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java b/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java index 42e64066..995bf95a 100644 --- a/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java +++ b/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java @@ -465,4 +465,26 @@ void peakCountOverMergedPieces() { + "(SELECT k, tgeompointFromText(s) AS g FROM VALUES " + rows + " AS t(k, s)) " + "WHERE k = 1 GROUP BY k)")); } + + @Test + void aRasterDerivedByArithmeticIsReadAlongATrip() { + // A 3x3 32BF depth raster in SRID 4326 holding 10, 20, 30 / 40, 50, 60 / 70, 80, 90, + // as PostGIS's ST_AsHexWKB writes it. + String depth = "rasterFromHexWKB('0100000100000000000000F03F000000000000F0BF0000000000000000" + + "000000000000084000000000000000000000000000000000E6100000030003000A000000000000204100" + + "00A0410000F04100002042000048420000704200008C420000A0420000B442')"; + String trip = "tgeompointFromText('SRID=4326;[POINT(0.5 2.5)@2001-01-01, " + + "POINT(2.5 2.5)@2001-01-02, POINT(0.5 0.5)@2001-01-03]')"; + // The clearance of a vessel of draught 8.5, as MobilityDB answers rasterValue(trip, + // depth - 8.5) in its raster regression test. + assertEquals("Interp=Step;[1.5@2001-01-01 00:00:00+00, 11.5@2001-01-01 06:00:00+00, " + + "21.5@2001-01-01 18:00:00+00, 41.5@2001-01-02 06:00:00+00, " + + "61.5@2001-01-02 18:00:00+00, 61.5@2001-01-03 00:00:00+00]", + scalar("SELECT asText(rasterValue(" + trip + ", rasterSub(" + depth + ", 8.5)))")); + String read = (String) scalar("SELECT asText(rasterValue(" + trip + ", " + depth + "))"); + assertEquals(read, scalar("SELECT asText(rasterValue(" + trip + ", rasterDiv(rasterAdd(" + + depth + ", " + depth + "), 2.0)))")); + assertEquals(read, scalar("SELECT asText(rasterValue(" + trip + ", rasterDiv(rasterMul(" + + depth + ", " + depth + "), " + depth + ")))")); + } }