You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "zhangfengcdt (via GitHub)" <gi...@apache.org> on 2025/09/12 20:52:51 UTC

[PR] feat: Add ST_Perimeter implementation to sedona-geo and benchmarks [sedona-db]

zhangfengcdt opened a new pull request, #76:
URL: https://github.com/apache/sedona-db/pull/76

   This PR adds ST_Perimeter function to sedona-geo crate.
   
     - **Implementation**: Added `rust/sedona-geo/src/st_perimeter.rs` using `LengthMeasurableExt::perimeter_ext` trait from
     geo-generic-alg with Euclidean metric
     - **Registration**: Added st_perimeter to module exports and scalar kernel registry
     - **Testing**: Added comprehensive unit tests covering:
       - Basic polygon perimeter calculation
       - Multi-polygon support
       - Polygons with holes
       - LineString geometries (perimeter equals length)
       - Point geometries (returns 0)
       - Null handling
     - **Benchmarks**: Added Rust benchmarks for 10-vertex and 500-vertex polygons, plus Python benchmarks
     
   Benchmark results:
   ```
   ------------------------------------------------ benchmark 'table=polygons_complex': 3 tests -------------------------------------------------
   Name (time in ms)                                 Median               Mean             StdDev                Min                Max
   ----------------------------------------------------------------------------------------------------------------------------------------------
   test_st_perimeter[polygons_complex-SedonaDB]      1.7382 (1.0)       1.7597 (1.0)       0.0912 (1.0)       1.6231 (1.0)       2.2656 (1.0)
   test_st_perimeter[polygons_complex-DuckDB]        4.3690 (2.51)      4.7802 (2.72)      0.7686 (8.43)      3.9360 (2.43)      6.7490 (2.98)
   test_st_perimeter[polygons_complex-PostGIS]      60.0717 (34.56)    63.7713 (36.24)    11.3609 (124.56)   54.9842 (33.88)    83.1649 (36.71)
   ----------------------------------------------------------------------------------------------------------------------------------------------
   
   ---------------------------------------------- benchmark 'table=polygons_simple': 3 tests ----------------------------------------------
   Name (time in ms)                               Median              Mean            StdDev               Min               Max
   ----------------------------------------------------------------------------------------------------------------------------------------
   test_st_perimeter[polygons_simple-SedonaDB]     0.2666 (1.0)      0.3579 (1.02)     0.4895 (14.41)    0.2342 (1.0)      4.5126 (7.68)
   test_st_perimeter[polygons_simple-DuckDB]       0.3434 (1.29)     0.3499 (1.0)      0.0340 (1.0)      0.3089 (1.32)     0.5879 (1.0)
   test_st_perimeter[polygons_simple-PostGIS]      3.1510 (11.82)    3.2089 (9.17)     0.2462 (7.25)     2.9126 (12.43)    4.1143 (7.00)
   ----------------------------------------------------------------------------------------------------------------------------------------
   
   ```
   
   
   


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add ST_Perimeter implementation based on georust/geo and benchmarks [sedona-db]

Posted by "zhangfengcdt (via GitHub)" <gi...@apache.org>.
zhangfengcdt commented on PR #76:
URL: https://github.com/apache/sedona-db/pull/76#issuecomment-3287145401

   > @zhangfengcdt CI failed
   
   It looks like there are some issues in calculating the perimeter for line types. I will need to fix it in geo repo and then these tests should be fixed then. 
   
   According to the PostGIS documentation and OGC standards, ST_Perimeter should return the perimeter of 2D geometries only (Polygon, MultiPolygon).
   


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add ST_Perimeter implementation based on georust/geo and benchmarks [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #76:
URL: https://github.com/apache/sedona-db/pull/76#discussion_r2345796853


##########
rust/sedona-geo/src/st_perimeter.rs:
##########
@@ -0,0 +1,142 @@
+// 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::Float64Builder;
+use arrow_schema::DataType;
+use datafusion_common::error::Result;
+use datafusion_expr::ColumnarValue;
+use geo_generic_alg::algorithm::{line_measures::Euclidean, LengthMeasurableExt};
+use sedona_expr::scalar_udf::{ScalarKernelRef, SedonaScalarKernel};
+use sedona_functions::executor::WkbExecutor;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+use wkb::reader::Wkb;
+
+/// ST_Perimeter() implementation using [LengthMeasurableExt::perimeter_ext] with Euclidean metric
+pub fn st_perimeter_impl() -> ScalarKernelRef {
+    Arc::new(STPerimeter {})
+}
+
+#[derive(Debug)]
+struct STPerimeter {}
+
+impl SedonaScalarKernel for STPerimeter {
+    fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+        let matcher = ArgMatcher::new(
+            vec![ArgMatcher::is_geometry()],
+            SedonaType::Arrow(DataType::Float64),
+        );
+
+        matcher.match_args(args)
+    }
+
+    fn invoke_batch(
+        &self,
+        arg_types: &[SedonaType],
+        args: &[ColumnarValue],
+    ) -> Result<ColumnarValue> {
+        let executor = WkbExecutor::new(arg_types, args);
+        let mut builder = Float64Builder::with_capacity(executor.num_iterations());
+        executor.execute_wkb_void(|maybe_wkb| {
+            match maybe_wkb {
+                Some(wkb) => {
+                    builder.append_value(invoke_scalar(&wkb)?);
+                }
+                _ => builder.append_null(),
+            }
+
+            Ok(())
+        })?;
+
+        executor.finish(Arc::new(builder.finish()))
+    }
+}
+
+fn invoke_scalar(wkb: &Wkb) -> Result<f64> {
+    Ok(wkb.perimeter_ext(&Euclidean))

Review Comment:
   In the GEOS version I believe peter handled the 0.0 output for non-polygon inputs here. (This works too, though!)



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add ST_Perimeter implementation based on georust/geo and benchmarks [sedona-db]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #76:
URL: https://github.com/apache/sedona-db/pull/76


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add ST_Perimeter implementation based on georust/geo and benchmarks [sedona-db]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on PR #76:
URL: https://github.com/apache/sedona-db/pull/76#issuecomment-3287010298

   @zhangfengcdt CI failed


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org