paleolimbot commented on code in PR #990:
URL: https://github.com/apache/sedona-db/pull/990#discussion_r3471685577


##########
python/sedonadb/tests/functions/test_functions.py:
##########
@@ -750,6 +750,59 @@ def test_st_buffer_style_parameters(
     )
 
 
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "expected"),
+    [
+        (None, None),
+        ("LINESTRING (0 0, 1 0, 1 1, 0 0)", "POLYGON ((0 0, 1 1, 1 0, 0 0))"),
+        (
+            "MULTILINESTRING ((0 0, 1 0, 1 1, 0 0), (2 2, 3 2, 3 3, 2 2))",
+            "MULTIPOLYGON (((1 1, 1 0, 0 0, 1 1)), ((3 3, 3 2, 2 2, 3 3)))",
+        ),
+    ],
+)
+def test_st_buildarea(eng, geom, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(f"SELECT ST_BuildArea({geom_or_null(geom)})", 
expected)
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "sedona_expected", "postgis_expected"),
+    [
+        # Both engines return an empty geometry for empty linework, not NULL.
+        # SedonaDB returns GEOMETRYCOLLECTION EMPTY; PostGIS returns POLYGON 
EMPTY.
+        ("LINESTRING EMPTY", "GEOMETRYCOLLECTION EMPTY", "POLYGON EMPTY"),
+        ("MULTILINESTRING EMPTY", "GEOMETRYCOLLECTION EMPTY", "POLYGON EMPTY"),
+    ],
+)
+def test_st_buildarea_empty_linework(eng, geom, sedona_expected, 
postgis_expected):

Review Comment:
   Can we fix this so that we return a POLYGON EMPTY? This makes sense to me 
and should be possible.



##########
python/sedonadb/tests/functions/test_functions.py:
##########
@@ -750,6 +750,59 @@ def test_st_buffer_style_parameters(
     )
 
 
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "expected"),
+    [
+        (None, None),
+        ("LINESTRING (0 0, 1 0, 1 1, 0 0)", "POLYGON ((0 0, 1 1, 1 0, 0 0))"),
+        (
+            "MULTILINESTRING ((0 0, 1 0, 1 1, 0 0), (2 2, 3 2, 3 3, 2 2))",
+            "MULTIPOLYGON (((1 1, 1 0, 0 0, 1 1)), ((3 3, 3 2, 2 2, 3 3)))",
+        ),
+    ],
+)
+def test_st_buildarea(eng, geom, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(f"SELECT ST_BuildArea({geom_or_null(geom)})", 
expected)
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "sedona_expected", "postgis_expected"),
+    [
+        # Both engines return an empty geometry for empty linework, not NULL.
+        # SedonaDB returns GEOMETRYCOLLECTION EMPTY; PostGIS returns POLYGON 
EMPTY.
+        ("LINESTRING EMPTY", "GEOMETRYCOLLECTION EMPTY", "POLYGON EMPTY"),
+        ("MULTILINESTRING EMPTY", "GEOMETRYCOLLECTION EMPTY", "POLYGON EMPTY"),
+    ],
+)
+def test_st_buildarea_empty_linework(eng, geom, sedona_expected, 
postgis_expected):
+    is_postgis = eng is PostGIS
+    eng = eng.create_or_skip()
+    expected = postgis_expected if is_postgis else sedona_expected
+    eng.assert_query_result(f"SELECT ST_BuildArea({geom_or_null(geom)})", 
expected)
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "sedona_expected", "postgis_expected"),
+    [
+        ("POINT (0 0)", None, None),

Review Comment:
   Can we align our behaviour here? I think this is just checking geometry 
types.



##########
python/sedonadb/tests/functions/test_functions.py:
##########
@@ -1421,6 +1474,88 @@ def test_st_dump(eng):
             assert actual["geom"] == shapely.from_wkt(expected["geom"]).wkb
 
 
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "expected"),
+    [
+        (None, None),
+        ("LINESTRING EMPTY", "GEOMETRYCOLLECTION EMPTY"),
+        ("POLYGON EMPTY", "GEOMETRYCOLLECTION EMPTY"),
+        (
+            "LINESTRING (0 0, 1 0, 0.5 1)",
+            "GEOMETRYCOLLECTION (POLYGON ((0.5 1, 0 0, 1 0, 0.5 1)))",
+        ),
+        (
+            "POLYGON ((0 0, 1 0, 0.5 1, 0 0))",
+            "GEOMETRYCOLLECTION (POLYGON ((0.5 1, 0 0, 1 0, 0.5 1)))",
+        ),
+        (
+            "MULTIPOINT ((0 0), (1 0), (0.5 1))",
+            "GEOMETRYCOLLECTION (POLYGON ((0.5 1, 0 0, 1 0, 0.5 1)))",
+        ),
+    ],
+)
+def test_st_delaunaytriangles(eng, geom, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_DelaunayTriangles({geom_or_null(geom)})", expected
+    )
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom", "tolerance", "expected"),
+    [
+        (None, None, None),
+        (
+            "MULTIPOINT ((0 0), (1 0), (0.5 1))",
+            0.0,
+            "GEOMETRYCOLLECTION (POLYGON ((0.5 1, 0 0, 1 0, 0.5 1)))",
+        ),
+        (
+            "MULTIPOINT ((0 0), (0.001 0), (1 0), (0.5 1))",
+            1.0,
+            "GEOMETRYCOLLECTION (POLYGON ((0.5 1, 0 0, 1 0, 0.5 1)))",
+        ),
+    ],
+)
+def test_st_delaunaytriangles_tolerance(eng, geom, tolerance, expected):
+    eng = eng.create_or_skip()
+    if tolerance is None:
+        eng.assert_query_result(
+            f"SELECT ST_DelaunayTriangles({geom_or_null(geom)}, NULL)", 
expected
+        )
+    else:
+        eng.assert_query_result(
+            f"SELECT ST_DelaunayTriangles({geom_or_null(geom)}, {tolerance})", 
expected
+        )

Review Comment:
   You may have to import this from sedonadb.testing but we have a helper for 
this one:
   
   ```suggestion
       eng.assert_query_result(
           f"SELECT ST_DelaunayTriangles({geom_or_null(geom)}, 
{val_or_null(tolerance)})", expected
       )
   ```



##########
c/sedona-geos/src/st_pointonsurface.rs:
##########
@@ -0,0 +1,127 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::sync::Arc;
+
+use arrow_array::builder::BinaryBuilder;
+use datafusion_common::{error::Result, DataFusionError};
+use datafusion_expr::ColumnarValue;
+use geos::{Geom, Geometry};
+use sedona_expr::{
+    item_crs::ItemCrsKernel,
+    scalar_udf::{ScalarKernelRef, SedonaScalarKernel},
+};
+use sedona_geometry::wkb_factory::WKB_MIN_PROBABLE_BYTES;
+use sedona_schema::{
+    datatypes::{SedonaType, WKB_GEOMETRY},
+    matchers::ArgMatcher,
+};
+
+use crate::executor::GeosExecutor;
+use crate::geos_to_wkb::write_geos_geometry;
+
+/// ST_PointOnSurface() implementation using the geos crate
+pub fn st_point_on_surface_impl() -> Vec<ScalarKernelRef> {
+    ItemCrsKernel::wrap_impl(STPointOnSurface {
+        matcher: ArgMatcher::new(vec![ArgMatcher::is_geometry()], 
WKB_GEOMETRY),
+    })
+}
+
+#[derive(Debug)]
+struct STPointOnSurface {
+    matcher: ArgMatcher,
+}
+
+impl SedonaScalarKernel for STPointOnSurface {
+    fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+        self.matcher.match_args(args)
+    }
+
+    fn invoke_batch(
+        &self,
+        arg_types: &[SedonaType],
+        args: &[ColumnarValue],
+    ) -> Result<ColumnarValue> {
+        let executor = GeosExecutor::new(arg_types, args);
+        let mut builder = BinaryBuilder::with_capacity(
+            executor.num_iterations(),
+            WKB_MIN_PROBABLE_BYTES * executor.num_iterations(),
+        );
+        executor.execute_wkb_void(|maybe_geom| {
+            match maybe_geom {
+                Some(geom) => {
+                    invoke_scalar(&geom, &mut builder)?;
+                    builder.append_value([]);
+                }
+                _ => builder.append_null(),
+            }
+            Ok(())
+        })?;
+
+        executor.finish(Arc::new(builder.finish()))
+    }
+}
+
+fn invoke_scalar(geom: &Geometry, writer: &mut impl std::io::Write) -> 
Result<()> {
+    let result = geom
+        .point_on_surface()
+        .map_err(|e| DataFusionError::Execution(format!("ST_PointOnSurface 
failed: {e}")))?;

Review Comment:
   ```suggestion
           .map_err(|e| exec_datafusion_err!("ST_PointOnSurface failed: {e}"))?;
   ```



##########
c/sedona-geos/src/st_delaunaytriangles.rs:
##########
@@ -0,0 +1,288 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::sync::Arc;
+
+use arrow_array::builder::BinaryBuilder;
+use arrow_schema::DataType;
+use datafusion_common::{
+    cast::{as_float64_array, as_int64_array},
+    DataFusionError, Result,
+};
+use datafusion_expr::ColumnarValue;
+use geos::{Geom, Geometry};
+use sedona_expr::{
+    item_crs::ItemCrsKernel,
+    scalar_udf::{ScalarKernelRef, SedonaScalarKernel},
+};
+use sedona_geometry::wkb_factory::WKB_MIN_PROBABLE_BYTES;
+use sedona_schema::{
+    datatypes::{SedonaType, WKB_GEOMETRY},
+    matchers::ArgMatcher,
+};
+
+use crate::executor::GeosExecutor;
+use crate::geos_to_wkb::write_geos_geometry;
+
+fn invoke_scalar(
+    geom: &Geometry,
+    tolerance: f64,
+    only_edges: bool,
+    writer: &mut impl std::io::Write,
+) -> Result<()> {
+    let result = geom
+        .delaunay_triangulation(tolerance, only_edges)
+        .map_err(|e| DataFusionError::Execution(format!("ST_DelaunayTriangles 
failed: {e}")))?;

Review Comment:
   ```suggestion
           .map_err(|e| exec_datafusion_err!("ST_DelaunayTriangles failed: 
{e}"))?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to