Skip to content

Commit

Permalink
fixed python bindings and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sllynn committed Nov 1, 2024
1 parent bc1b86f commit ab46dfd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions python/mosaic/api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ def st_triangulate(
lines_array: ColumnOrName,
merge_tolerance: ColumnOrName,
snap_tolerance: ColumnOrName,
split_point_finder: str = "NONENCROACHING",
) -> Column:
"""
Generate a triangulated surface mesh from the set of points `points_array` and constraint lines `lines_array`.
Expand All @@ -641,6 +642,9 @@ def st_triangulate(
A tolerance used to coalesce points in close proximity to each other before performing triangulation.
snap_tolerance : Column
A snapping tolerance used to relate created points to their corresponding lines for elevation interpolation.
split_point_finder : String
(Optional) The split point finding algorithm used to incorporate `lines_array` into the triangulation.
Default is "NONENCROACHING", alternative is "MIDPOINT".
Returns
-------
Expand All @@ -652,6 +656,7 @@ def st_triangulate(
pyspark_to_java_column(lines_array),
pyspark_to_java_column(merge_tolerance),
pyspark_to_java_column(snap_tolerance),
pyspark_to_java_column(lit(split_point_finder)),
)


Expand All @@ -665,6 +670,7 @@ def st_interpolateelevation(
y_width: ColumnOrName,
x_size: ColumnOrName,
y_size: ColumnOrName,
split_point_finder: str = "NONENCROACHING",
) -> Column:
"""
Compute interpolated elevations across a grid of points described by
Expand Down Expand Up @@ -701,6 +707,9 @@ def st_interpolateelevation(
y_size : Column
The spacing between each point on the grid's y-axis
(in meters or degrees depending on the projection of `points_array`)
split_point_finder : String
(Optional) The split point finding algorithm used to incorporate `lines_array` into the triangulation.
Default is "NONENCROACHING", alternative is "MIDPOINT".
Returns
-------
Expand All @@ -712,6 +721,7 @@ def st_interpolateelevation(
pyspark_to_java_column(lines_array),
pyspark_to_java_column(merge_tolerance),
pyspark_to_java_column(snap_tolerance),
pyspark_to_java_column(lit(split_point_finder)),
pyspark_to_java_column(origin),
pyspark_to_java_column(x_width),
pyspark_to_java_column(y_width),
Expand Down
11 changes: 11 additions & 0 deletions python/mosaic/api/raster.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from typing import Any

from pyspark.sql import Column
Expand Down Expand Up @@ -267,6 +269,8 @@ def rst_dtmfromgeoms(
y_width: ColumnOrName,
x_size: ColumnOrName,
y_size: ColumnOrName,
split_point_finder: str = "NONENCROACHING",
no_data_value: float = np.nan,
) -> Column:
"""
Generate a raster with interpolated elevations across a grid of points described by
Expand Down Expand Up @@ -303,6 +307,11 @@ def rst_dtmfromgeoms(
y_size : Column
The spacing between each point on the grid's y-axis
(in meters or degrees depending on the projection of `points_array`)
split_point_finder : String
(Optional) The split point finding algorithm used to incorporate `lines_array` into the triangulation.
Default is "NONENCROACHING", alternative is "MIDPOINT".
no_data_value : Float
(Optional) The nodata value to assign to the output raster. Must be a Double Type value. Default is NaN.
Returns
-------
Expand All @@ -315,11 +324,13 @@ def rst_dtmfromgeoms(
pyspark_to_java_column(lines_array),
pyspark_to_java_column(merge_tolerance),
pyspark_to_java_column(snap_tolerance),
pyspark_to_java_column(lit(split_point_finder)),
pyspark_to_java_column(origin),
pyspark_to_java_column(x_width),
pyspark_to_java_column(y_width),
pyspark_to_java_column(x_size),
pyspark_to_java_column(y_size),
pyspark_to_java_column(lit(no_data_value)),
)


Expand Down
6 changes: 5 additions & 1 deletion python/test/test_raster_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def test_raster_scalar_functions(self):
"rst_worldtorastercoord",
api.rst_worldtorastercoord("tile", lit(0.0), lit(0.0)),
)
.withColumn("rst_write", api.rst_write("tile", lit("/mnt/mosaic_tmp/write-tile")))
.withColumn(
"rst_write", api.rst_write("tile", lit("/mnt/mosaic_tmp/write-tile"))
)
)
result.write.format("noop").mode("overwrite").save()
self.assertEqual(result.count(), 1)
Expand Down Expand Up @@ -300,6 +302,8 @@ def test_dtmfromgeoms(self):
"grid_size_y",
"pixel_size_x",
"pixel_size_y",
"NONENCROACHING",
-9999.0,
),
)
.drop(
Expand Down
9 changes: 6 additions & 3 deletions python/test/test_vector_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def test_triangulate_interpolate(self):

triangulation_df = df.withColumn(
"triangles",
api.st_triangulate("masspoints", "breaklines", lit(0.0), lit(0.01)),
api.st_triangulate(
"masspoints", "breaklines", lit(0.0), lit(0.01), lit("NONENCROACHING")
),
)
triangulation_df.cache()
self.assertEqual(triangulation_df.count(), 2)
Expand All @@ -338,7 +340,7 @@ def test_triangulate_interpolate(self):
)

interpolation_df = (
df.withColumn("origin", api.st_geomfromwkt(lit("POINT (0.6 1.8)")))
df.withColumn("origin", api.st_geomfromwkt(lit("POINT (0.55 1.75)")))
.withColumn("xWidth", lit(12))
.withColumn("yWidth", lit(6))
.withColumn("xSize", lit(0.1))
Expand All @@ -355,13 +357,14 @@ def test_triangulate_interpolate(self):
"yWidth",
"xSize",
"ySize",
lit("NONENCROACHING"),
),
)
)

interpolation_df.cache()
self.assertEqual(interpolation_df.count(), 12 * 6)
self.assertIn(
"POINT Z(0.6 2 1.8)",
"POINT Z(1.6 1.8 1.2)",
[r["interpolated"] for r in interpolation_df.collect()],
)

0 comments on commit ab46dfd

Please sign in to comment.