Skip to content

Conversation

@zhangfengcdt
Copy link
Member

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)
----------------------------------------------------------------------------------------------------------------------------------------

@zhangfengcdt zhangfengcdt changed the title feat: Add ST_Perimeter implementation to sedona-geo and benchmarks feat: Add ST_Perimeter implementation based on georust/geo and benchmarks Sep 12, 2025
@zhangfengcdt zhangfengcdt marked this pull request as ready for review September 12, 2025 21:03
@jiayuasu
Copy link
Member

@zhangfengcdt CI failed

@zhangfengcdt
Copy link
Member Author

@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).

Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

}

fn invoke_scalar(wkb: &Wkb) -> Result<f64> {
Ok(wkb.perimeter_ext(&Euclidean))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jiayuasu jiayuasu requested a review from Copilot September 13, 2025 06:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new ST_Perimeter function to the sedona-geo crate, implementing perimeter calculation for geometric objects using the georust/geo library's Euclidean metric.

  • Implements ST_Perimeter function using LengthMeasurableExt::perimeter_ext trait with Euclidean distance calculation
  • Adds comprehensive test coverage for various geometry types including polygons, multi-polygons, polygons with holes, linestrings, and points
  • Includes both Rust and Python benchmarks to measure performance against other spatial databases

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/sedona-geo/src/st_perimeter.rs New implementation of ST_Perimeter function with comprehensive test suite
rust/sedona-geo/src/register.rs Registers the new st_perimeter function in the scalar kernel registry
rust/sedona-geo/src/lib.rs Adds st_perimeter module to the crate exports
rust/sedona-geo/benches/geo-functions.rs Adds Rust benchmarks for ST_Perimeter with 10 and 500 vertex polygons
benchmarks/test_functions.py Adds Python benchmarks for ST_Perimeter function testing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jiayuasu jiayuasu merged commit 434be5c into apache:main Sep 13, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants