feat(rust/sedona-functions): implement ST_XxxFromText typed geometry constructors (issue #205)#993
Conversation
…che#205) Add ST_GeomCollFromText, ST_LineFromText, ST_LineStringFromText (alias), ST_MLineFromText, ST_MPointFromText, ST_MPolyFromText, ST_PointFromText, and ST_PolygonFromText. Each function parses WKT and errors if the result does not match the expected geometry type, providing OGC/PostGIS compatibility. Implemented by adding an optional ExpectedGeomType to STGeoFromWKT, sharing all parsing and SRID logic with ST_GeomFromWKT.
paleolimbot
left a comment
There was a problem hiding this comment.
Thank you!
Can you add Python tests to confirm parity with PostGIS here?
Can you also confirm the behaviour for EMPTY types? (i.e., is LINESTRING EMTPY rejected by ST_GeomCollFromText()`)?
|
|
||
| Parses a WKT string and returns a geometry. Raises an error if the WKT does not represent a LineString. | ||
|
|
||
| This function also has the alias `ST_LineStringFromText`. |
There was a problem hiding this comment.
| This function also has the alias `ST_LineStringFromText`. | |
| Aliases: `ST_LineStringFromText`. |
| SELECT ST_PolygonFromText('POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))'); | ||
| ``` | ||
|
|
||
| With an SRID: |
There was a problem hiding this comment.
| With an SRID: | |
| With an SRID or CRS: |
(For the others as well)
| /// Geometry type constraint used by ST_XxxFromText functions. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| enum ExpectedGeomType { |
There was a problem hiding this comment.
Can you use sedona_geometry::...::GeometryTypeId for this to avoid the duplicated enum?
| #[test] | ||
| fn typed_constructors_accept_correct_type() { | ||
| let cases: &[(&str, SedonaScalarUDF)] = &[ |
There was a problem hiding this comment.
Can you use rstest parameterized tests for consistency here?
…, fix docs - Replace custom ExpectedGeomType enum with sedona_geometry::types::GeometryTypeId to avoid duplication; use .geojson_id() for error messages - Convert typed_constructors_accept_correct_type, accept_srid, and reject_wrong_type Rust tests to rstest #[case] parametrize covering all 7 constructors - Add Python integration tests: accept correct type, reject wrong type, accept SRID, accept matching EMPTY, reject wrong EMPTY (all 7), null input, ST_LineStringFromText alias - Fix ST_LineFromText doc: 'This function also has the alias' -> 'Aliases:' - Fix all 7 typed constructor docs: 'With an SRID:' -> 'With an SRID or CRS:'
|
Hi @paleolimbot , I've addressed all the feedback: ExpectedGeomType → GeometryTypeId: Replaced the custom enum with sedona_geometry::types::GeometryTypeId and switched error messages to use .geojson_id(). |
…or tests - ST_MPointFromText: use geoarrow-c canonical form (no per-point parens) - reject_wrong_type: SedonaDB-only; PostGIS typed constructors are aliases for ST_GeomFromText and do not validate geometry type - accept_matching_empty: POINT EMPTY renders as POINT (nan nan) via geoarrow-c - ST_LineStringFromText alias: SedonaDB-only; function does not exist in PostGIS - reject_wrong_empty: SedonaDB-only; same reason as reject_wrong_type
Summary
Closes #205.
Implements the typed WKT constructor functions listed in the issue:
ST_GeomCollFromText— errors if input is not a GeometryCollectionST_LineFromText— errors if input is not a LineString (alias:ST_LineStringFromText)ST_MLineFromText— errors if input is not a MultiLineStringST_MPointFromText— errors if input is not a MultiPointST_MPolyFromText— errors if input is not a MultiPolygonST_PointFromText— errors if input is not a PointST_PolygonFromText— errors if input is not a PolygonImplementation
Added
ExpectedGeomTypeenum and anexpected_geom_type: Option<ExpectedGeomType>field to the existingSTGeoFromWKTstruct. All parsing, SRID, and CRS propagation logic is shared withST_GeomFromWKT— no duplication.A
make_typed_geom_udfhelper constructs each function with one line.Tests
typed_constructors_accept_correct_type— all 7 functions accept their matching WKT typetyped_constructors_reject_wrong_type— error message includes expected type nametyped_constructors_accept_srid— all 7 functions work with the optional SRID argumentDocs
Reference
.qmdadded for each function including SRID examples. CI doc check passes (Missing docs: 0, Missing alias mentions: 0).