- 
                Notifications
    You must be signed in to change notification settings 
- Fork 29
Description
There are a number of variants of ST_GeomFromText that are identical except they error if a specific data type was not passed. These functions are:
- ST_GeomCollFromText
- ST_MPointFromText
- ST_LineFromText
- ST_LineStringFromText
- ST_MLineFromText
- ST_MPointFromText
- ST_MPolyFromText
- ST_PointFromText
- ST_PolygonFromText
I believe these could all be implemented by adding an (optional) "expected geometry type" here:
sedona-db/rust/sedona-functions/src/st_geomfromwkt.rs
Lines 127 to 133 in 6d0b218
| fn invoke_scalar(wkt_bytes: &str, builder: &mut BinaryBuilder) -> Result<()> { | |
| let geometry: Wkt<f64> = Wkt::from_str(wkt_bytes) | |
| .map_err(|err| DataFusionError::Internal(format!("WKT parse error: {err}")))?; | |
| write_geometry(builder, &geometry, wkb::Endianness::LittleEndian) | |
| .map_err(|err| DataFusionError::Internal(format!("WKB write error: {err}"))) | |
| } | 
...and add an expected_geometry_type: Option<GeometryTypeId> here:
sedona-db/rust/sedona-functions/src/st_geomfromwkt.rs
Lines 87 to 90 in 6d0b218
| #[derive(Debug)] | |
| struct STGeoFromWKT { | |
| out_type: SedonaType, | |
| } | 
Then these functions can be constructed and declared here with their documentation:
sedona-db/rust/sedona-functions/src/st_geomfromwkt.rs
Lines 37 to 41 in 6d0b218
| /// ST_GeomFromWKT() UDF implementation | |
| /// | |
| /// An implementation of WKT reading using GeoRust's wkt crate. | |
| /// See [`st_geogfromwkt_udf`] for the corresponding geography function. | |
| pub fn st_geomfromwkt_udf() -> SedonaScalarUDF { | 
We should ensure that this doesn't slow down the general case, although I don't think that in the context of WKT parsing this will be measurable.
I don't think we need Geography constructors like this, because nobody else provides them either (these functions would be for OGC/PostGIS compatibility).