diff --git a/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testRasterFunctions.R b/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testRasterFunctions.R index 538062b9c..13e78ac24 100644 --- a/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testRasterFunctions.R +++ b/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testRasterFunctions.R @@ -8,7 +8,7 @@ generate_singleband_raster_df <- function() { test_that("mosaic can read single-band GeoTiff", { sdf <- generate_singleband_raster_df() - + row <- first(sdf) expect_equal(row$length, 1067862L) expect_equal(row$x_size, 2400) @@ -158,14 +158,16 @@ sdf <- createDataFrame( sdf <- agg(groupBy(sdf), masspoints = collect_list(column("wkt"))) sdf <- withColumn(sdf, "breaklines", expr("array('LINESTRING EMPTY')")) +sdf <- withColumn(sdf, "splitPointFinder", lit("NONENCROACHING")) sdf <- withColumn(sdf, "origin", st_geomfromwkt(lit("POINT (0.6 1.8)"))) sdf <- withColumn(sdf, "xWidth", lit(12L)) sdf <- withColumn(sdf, "yWidth", lit(6L)) sdf <- withColumn(sdf, "xSize", lit(0.1)) sdf <- withColumn(sdf, "ySize", lit(0.1)) +sdf <- withColumn(sdf, "noData", lit(-9999.0)) sdf <- withColumn(sdf, "tile", rst_dtmfromgeoms( -column("masspoints"), column("breaklines"), lit(0.0), lit(0.01), -column("origin"), column("xWidth"), column("yWidth"), column("xSize"), column("ySize")) -) +column("masspoints"), column("breaklines"), lit(0.0), lit(0.01), column("splitPointFinder"), +column("origin"), column("xWidth"), column("yWidth"), column("xSize"), column("ySize"), column("noData") +)) expect_equal(SparkR::count(sdf), 1) }) \ No newline at end of file diff --git a/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testVectorFunctions.R b/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testVectorFunctions.R index 4294e1a15..07744b2bf 100644 --- a/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testVectorFunctions.R +++ b/R/sparkR-mosaic/sparkrMosaic/tests/testthat/testVectorFunctions.R @@ -109,14 +109,14 @@ sdf <- createDataFrame( sdf <- agg(groupBy(sdf), masspoints = collect_list(column("wkt"))) sdf <- withColumn(sdf, "breaklines", expr("array('LINESTRING EMPTY')")) -triangulation_sdf <- withColumn(sdf, "triangles", st_triangulate(column("masspoints"), column("breaklines"), lit(0.0), lit(0.01))) +triangulation_sdf <- withColumn(sdf, "triangles", st_triangulate(column("masspoints"), column("breaklines"), lit(0.0), lit(0.01), lit("NONENCROACHING"))) cache(triangulation_sdf) expect_equal(SparkR::count(triangulation_sdf), 2) expected <- c("POLYGON Z((0 2 2, 2 1 0, 1 3 3, 0 2 2))", "POLYGON Z((1 3 3, 2 1 0, 3 2 1, 1 3 3))") expect_contains(expected, first(triangulation_sdf)$triangles) interpolation_sdf <- sdf -interpolation_sdf <- withColumn(interpolation_sdf, "origin", st_geomfromwkt(lit("POINT (0.6 1.8)"))) +interpolation_sdf <- withColumn(interpolation_sdf, "origin", st_geomfromwkt(lit("POINT (0.55 1.75)"))) interpolation_sdf <- withColumn(interpolation_sdf, "xWidth", lit(12L)) interpolation_sdf <- withColumn(interpolation_sdf, "yWidth", lit(6L)) interpolation_sdf <- withColumn(interpolation_sdf, "xSize", lit(0.1)) @@ -124,8 +124,9 @@ interpolation_sdf <- withColumn(interpolation_sdf, "ySize", lit(0.1)) interpolation_sdf <- withColumn(interpolation_sdf, "interpolated", st_interpolateelevation( column("masspoints"), column("breaklines"), - lit(0.0), lit(0.01), + lit(0.01), + lit("NONENCROACHING"), column("origin"), column("xWidth"), column("yWidth"), @@ -134,5 +135,5 @@ interpolation_sdf <- withColumn(interpolation_sdf, "interpolated", st_interpolat )) cache(interpolation_sdf) expect_equal(SparkR::count(interpolation_sdf), 6 * 12) -expect_contains(collect(interpolation_sdf)$interpolated, "POINT Z(0.6 2 1.8)") +expect_contains(collect(interpolation_sdf)$interpolated, "POINT Z(1.6 1.8 1.2)") }) diff --git a/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testRasterFunctions.R b/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testRasterFunctions.R index ddbcce8c8..d67888725 100644 --- a/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testRasterFunctions.R +++ b/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testRasterFunctions.R @@ -209,11 +209,13 @@ test_that ("a terrain model can be produced from point geometries", { breaklines, as.double(0.0), as.double(0.01), + "NONENCROACHING", origin, xWidth, yWidth, xSize, - ySize + ySize, + as.double(-9999.0) ) ) expect_equal(sdf_nrow(sdf), 1) diff --git a/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testVectorFunctions.R b/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testVectorFunctions.R index a177b37bf..c8baaf572 100644 --- a/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testVectorFunctions.R +++ b/R/sparklyr-mosaic/sparklyrMosaic/tests/testthat/testVectorFunctions.R @@ -134,7 +134,7 @@ test_that ("triangulation and interpolation functions behave as intended", { mutate(breaklines = array("LINESTRING EMPTY")) triangulation_sdf <- sdf %>% - mutate(triangles = st_triangulate(masspoints, breaklines, as.double(0.00), as.double(0.01))) + mutate(triangles = st_triangulate(masspoints, breaklines, as.double(0.00), as.double(0.01), "NONENCROACHING")) expect_equal(sdf_nrow(triangulation_sdf), 2) @@ -144,7 +144,7 @@ test_that ("triangulation and interpolation functions behave as intended", { interpolation_sdf <- sdf %>% mutate( - origin = st_geomfromwkt("POINT (0.6 1.8)"), + origin = st_geomfromwkt("POINT (0.55 1.75)"), xWidth = 12L, yWidth = 6L, xSize = as.double(0.1), @@ -152,8 +152,9 @@ test_that ("triangulation and interpolation functions behave as intended", { interpolated = st_interpolateelevation( masspoints, breaklines, - as.double(0.0), as.double(0.01), + as.double(0.01), + "NONENCROACHING", origin, xWidth, yWidth, @@ -163,5 +164,5 @@ test_that ("triangulation and interpolation functions behave as intended", { ) expect_equal(sdf_nrow(interpolation_sdf), 6 * 12) expect_contains(sdf_collect(interpolation_sdf)$interpolated, - "POINT Z(0.6 2 1.8)") + "POINT Z(1.6 1.8 1.2)") }) diff --git a/src/main/scala/com/databricks/labs/mosaic/functions/MosaicContext.scala b/src/main/scala/com/databricks/labs/mosaic/functions/MosaicContext.scala index 6bb4480c6..b909bdde0 100644 --- a/src/main/scala/com/databricks/labs/mosaic/functions/MosaicContext.scala +++ b/src/main/scala/com/databricks/labs/mosaic/functions/MosaicContext.scala @@ -626,8 +626,6 @@ class MosaicContext(indexSystem: IndexSystem, geometryAPI: GeometryAPI) extends ColumnAdapter(ST_HasValidCoordinates(geom.expr, crsCode.expr, which.expr, expressionConfig)) def st_interpolateelevation(pointsArray: Column, linesArray: Column, mergetol: Column, snaptol: Column, splitPointFinder: Column, origin: Column, xWidth: Column, yWidth: Column, xSize: Column, ySize: Column): Column = ColumnAdapter(geometry.ST_InterpolateElevation(pointsArray.expr, linesArray.expr, mergetol.expr, snaptol.expr, splitPointFinder.expr, origin.expr, xWidth.expr, yWidth.expr, xSize.expr, ySize.expr, expressionConfig)) - def st_interpolateelevation(pointsArray: Column, linesArray: Column, mergetol: Column, snaptol: Column, origin: Column, xWidth: Column, yWidth: Column, xSize: Column, ySize: Column): Column = - ColumnAdapter(geometry.ST_InterpolateElevation(pointsArray.expr, linesArray.expr, mergetol.expr, snaptol.expr, lit("NONENCROACHING").expr, origin.expr, xWidth.expr, yWidth.expr, xSize.expr, ySize.expr, expressionConfig)) def st_intersection(left: Column, right: Column): Column = ColumnAdapter(ST_Intersection(left.expr, right.expr, expressionConfig)) def st_isvalid(geom: Column): Column = ColumnAdapter(ST_IsValid(geom.expr, expressionConfig)) def st_length(geom: Column): Column = ColumnAdapter(ST_Length(geom.expr, expressionConfig)) @@ -651,8 +649,6 @@ class MosaicContext(indexSystem: IndexSystem, geometryAPI: GeometryAPI) extends ColumnAdapter(ST_Translate(geom1.expr, xd.expr, yd.expr, expressionConfig)) def st_triangulate(pointsArray: Column, linesArray: Column, mergeTol: Column, snapTol: Column, splitPointFinder: Column): Column = ColumnAdapter(ST_Triangulate(pointsArray.expr, linesArray.expr, mergeTol.expr, snapTol.expr, splitPointFinder.expr, expressionConfig)) - def st_triangulate(pointsArray: Column, linesArray: Column, mergeTol: Column, snapTol: Column): Column = - ColumnAdapter(ST_Triangulate(pointsArray.expr, linesArray.expr, mergeTol.expr, snapTol.expr, lit("NONENCROACHING").expr, expressionConfig)) def st_x(geom: Column): Column = ColumnAdapter(ST_X(geom.expr, expressionConfig)) def st_y(geom: Column): Column = ColumnAdapter(ST_Y(geom.expr, expressionConfig)) def st_z(geom: Column): Column = ColumnAdapter(ST_Z(geom.expr, expressionConfig)) @@ -710,8 +706,6 @@ class MosaicContext(indexSystem: IndexSystem, geometryAPI: GeometryAPI) extends def rst_convolve(raster: Column, kernel: Column): Column = ColumnAdapter(RST_Convolve(raster.expr, kernel.expr, expressionConfig)) def rst_dtmfromgeoms(pointsArray: Column, linesArray: Column, mergeTol: Column, snapTol: Column, splitPointFinder: Column, origin: Column, xWidth: Column, yWidth: Column, xSize: Column, ySize: Column, noData: Column): Column = ColumnAdapter(RST_DTMFromGeoms(pointsArray.expr, linesArray.expr, mergeTol.expr, snapTol.expr, splitPointFinder.expr, origin.expr, xWidth.expr, yWidth.expr, xSize.expr, ySize.expr, noData.expr, expressionConfig)) - def rst_dtmfromgeoms(pointsArray: Column, linesArray: Column, mergeTol: Column, snapTol: Column, origin: Column, xWidth: Column, yWidth: Column, xSize: Column, ySize: Column, noData: Column): Column = - ColumnAdapter(RST_DTMFromGeoms(pointsArray.expr, linesArray.expr, mergeTol.expr, snapTol.expr, lit("NONENCROACHING").expr, origin.expr, xWidth.expr, yWidth.expr, xSize.expr, ySize.expr, noData.expr, expressionConfig)) def rst_pixelcount(raster: Column): Column = ColumnAdapter(RST_PixelCount(raster.expr, lit(false).expr, lit(false).expr, expressionConfig)) def rst_pixelcount(raster: Column, countNoData: Column): Column = ColumnAdapter(RST_PixelCount(raster.expr, countNoData.expr, lit(false).expr, expressionConfig)) def rst_pixelcount(raster: Column, countNoData: Column, countAll: Column): Column = ColumnAdapter(RST_PixelCount(raster.expr, countNoData.expr, countAll.expr, expressionConfig)) diff --git a/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_InterpolateElevationBehaviours.scala b/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_InterpolateElevationBehaviours.scala index 42c719a31..e57f0f435 100644 --- a/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_InterpolateElevationBehaviours.scala +++ b/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_InterpolateElevationBehaviours.scala @@ -2,6 +2,7 @@ package com.databricks.labs.mosaic.expressions.geometry import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI import com.databricks.labs.mosaic.core.index.IndexSystem +import com.databricks.labs.mosaic.core.types.model.TriangulationSplitPointTypeEnum import com.databricks.labs.mosaic.functions.MosaicContext import com.databricks.labs.mosaic.functions.MosaicRegistryBehaviors.mosaicContext import org.apache.spark.sql.functions._ @@ -22,6 +23,7 @@ trait ST_InterpolateElevationBehaviours extends QueryTest { val ySize = -1.0 val mergeTolerance = 0.0 val snapTolerance = 0.01 + val splitPointFinder = TriangulationSplitPointTypeEnum.NONENCROACHING val origin = "POINT(348000 462000)" def simpleInterpolationBehavior(indexSystem: IndexSystem, geometryAPI: GeometryAPI): Unit = { @@ -45,18 +47,22 @@ trait ST_InterpolateElevationBehaviours extends QueryTest { .withColumn("breaklines", array().cast(ArrayType(StringType))) .withColumn("mergeTolerance", lit(mergeTolerance)) .withColumn("snapTolerance", lit(snapTolerance)) + .withColumn("splitPointFinder", lit(splitPointFinder.toString)) .withColumn("origin", st_geomfromwkt(lit(origin))) .withColumn("grid_size_x", lit(xWidth)) .withColumn("grid_size_y", lit(yWidth)) .withColumn("pixel_size_x", lit(xSize)) .withColumn("pixel_size_y", lit(ySize)) .withColumn("elevation", st_interpolateelevation( - $"masspoints", $"breaklines", $"mergeTolerance", $"snapTolerance", + $"masspoints", $"breaklines", + $"mergeTolerance", $"snapTolerance", $"splitPointFinder", $"origin", $"grid_size_x", $"grid_size_y", $"pixel_size_x", $"pixel_size_y")) .drop( - $"masspoints", $"breaklines", $"mergeTolerance", $"snapTolerance", $"origin", - $"grid_size_x", $"grid_size_y", $"pixel_size_x", $"pixel_size_y" + $"masspoints", $"breaklines", + $"mergeTolerance", $"snapTolerance", $"splitPointFinder", + $"origin", $"grid_size_x", $"grid_size_y", + $"pixel_size_x", $"pixel_size_y" ) noException should be thrownBy result.collect() result.count() shouldBe 1000000L @@ -93,19 +99,23 @@ trait ST_InterpolateElevationBehaviours extends QueryTest { .crossJoin(linesDf) .withColumn("mergeTolerance", lit(mergeTolerance)) .withColumn("snapTolerance", lit(snapTolerance)) + .withColumn("splitPointFinder", lit(splitPointFinder.toString)) .withColumn("origin", st_geomfromwkt(lit(origin))) .withColumn("grid_size_x", lit(xWidth)) .withColumn("grid_size_y", lit(yWidth)) .withColumn("pixel_size_x", lit(xSize)) .withColumn("pixel_size_y", lit(ySize)) .withColumn("interpolated_grid_point", st_interpolateelevation( - $"masspoints", $"breaklines",$"mergeTolerance", $"snapTolerance", + $"masspoints", $"breaklines", + $"mergeTolerance", $"snapTolerance", $"splitPointFinder", $"origin", $"grid_size_x", $"grid_size_y", $"pixel_size_x", $"pixel_size_y")) .withColumn("elevation", st_z($"interpolated_grid_point")) .drop( - $"masspoints", $"breaklines", $"mergeTolerance", $"snapTolerance", $"origin", - $"grid_size_x", $"grid_size_y", $"pixel_size_x", $"pixel_size_y" + $"masspoints", $"breaklines", + $"mergeTolerance", $"snapTolerance", $"splitPointFinder", + $"origin", $"grid_size_x", $"grid_size_y", + $"pixel_size_x", $"pixel_size_y" ) .cache() noException should be thrownBy result.collect() diff --git a/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_TriangulateBehaviours.scala b/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_TriangulateBehaviours.scala index 32547ecda..dc3679c7d 100644 --- a/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_TriangulateBehaviours.scala +++ b/src/test/scala/com/databricks/labs/mosaic/expressions/geometry/ST_TriangulateBehaviours.scala @@ -2,6 +2,7 @@ package com.databricks.labs.mosaic.expressions.geometry import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI import com.databricks.labs.mosaic.core.index.IndexSystem +import com.databricks.labs.mosaic.core.types.model.TriangulationSplitPointTypeEnum import com.databricks.labs.mosaic.functions.MosaicContext import org.apache.spark.sql.QueryTest import org.apache.spark.sql.functions._ @@ -18,6 +19,7 @@ trait ST_TriangulateBehaviours extends QueryTest { val buffer = 50.0 val mergeTolerance = 1e-2 val snapTolerance = 0.01 + val splitPointFinder = TriangulationSplitPointTypeEnum.NONENCROACHING def simpleTriangulateBehavior(indexSystem: IndexSystem, geometryAPI: GeometryAPI): Unit = { @@ -38,7 +40,7 @@ trait ST_TriangulateBehaviours extends QueryTest { .groupBy() .agg(collect_list($"geom_0").as("masspoints")) .withColumn("breaklines", array().cast(ArrayType(StringType))) - .withColumn("mesh", st_triangulate($"masspoints", $"breaklines", lit(mergeTolerance), lit(snapTolerance))) + .withColumn("mesh", st_triangulate($"masspoints", $"breaklines", lit(mergeTolerance), lit(snapTolerance), lit(splitPointFinder.toString))) .drop($"masspoints") noException should be thrownBy result.collect() result.count() shouldBe 4453 @@ -76,7 +78,7 @@ trait ST_TriangulateBehaviours extends QueryTest { .groupBy() .agg(collect_list($"geom_0").as("masspoints")) .crossJoin(linesDf) - .withColumn("mesh", st_triangulate($"masspoints", $"breaklines", lit(mergeTolerance), lit(snapTolerance))) + .withColumn("mesh", st_triangulate($"masspoints", $"breaklines", lit(mergeTolerance), lit(snapTolerance), lit(splitPointFinder.toString))) .drop($"masspoints", $"breaklines") noException should be thrownBy result.collect()