Skip to content

Commit 9e3365f

Browse files
feat(c/sedona-geos): Implement ST_IsValidReason using geos library (#230)
Co-authored-by: Dewey Dunnington <[email protected]>
1 parent 04aff75 commit 9e3365f

File tree

5 files changed

+205
-45
lines changed

5 files changed

+205
-45
lines changed

c/sedona-geos/benches/geos-functions.rs

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,65 +46,65 @@ fn criterion_benchmark(c: &mut Criterion) {
4646
benchmark::scalar(c, &f, "geos", "st_centroid", Polygon(10));
4747
benchmark::scalar(c, &f, "geos", "st_centroid", Polygon(500));
4848

49-
benchmark::scalar(c, &f, "geos", "st_convexhull", MultiPoint(10));
50-
5149
benchmark::scalar(
5250
c,
5351
&f,
5452
"geos",
55-
"st_distance",
53+
"st_contains",
5654
ArrayScalar(Polygon(10), Polygon(10)),
5755
);
5856
benchmark::scalar(
5957
c,
6058
&f,
6159
"geos",
62-
"st_distance",
60+
"st_contains",
6361
ArrayScalar(Polygon(10), Polygon(500)),
6462
);
6563

64+
benchmark::scalar(c, &f, "geos", "st_convexhull", MultiPoint(10));
65+
6666
benchmark::scalar(
6767
c,
6868
&f,
6969
"geos",
70-
"st_contains",
70+
"st_coveredby",
7171
ArrayScalar(Polygon(10), Polygon(10)),
7272
);
7373
benchmark::scalar(
7474
c,
7575
&f,
7676
"geos",
77-
"st_contains",
77+
"st_coveredby",
7878
ArrayScalar(Polygon(10), Polygon(500)),
7979
);
8080

8181
benchmark::scalar(
8282
c,
8383
&f,
8484
"geos",
85-
"st_coveredby",
85+
"st_covers",
8686
ArrayScalar(Polygon(10), Polygon(10)),
8787
);
8888
benchmark::scalar(
8989
c,
9090
&f,
9191
"geos",
92-
"st_coveredby",
92+
"st_covers",
9393
ArrayScalar(Polygon(10), Polygon(500)),
9494
);
9595

9696
benchmark::scalar(
9797
c,
9898
&f,
9999
"geos",
100-
"st_covers",
100+
"st_crosses",
101101
ArrayScalar(Polygon(10), Polygon(10)),
102102
);
103103
benchmark::scalar(
104104
c,
105105
&f,
106106
"geos",
107-
"st_covers",
107+
"st_crosses",
108108
ArrayScalar(Polygon(10), Polygon(500)),
109109
);
110110

@@ -115,7 +115,6 @@ fn criterion_benchmark(c: &mut Criterion) {
115115
"st_difference",
116116
ArrayScalar(Polygon(10), Polygon(10)),
117117
);
118-
119118
benchmark::scalar(
120119
c,
121120
&f,
@@ -139,14 +138,28 @@ fn criterion_benchmark(c: &mut Criterion) {
139138
ArrayScalar(Polygon(10), Polygon(500)),
140139
);
141140

141+
benchmark::scalar(
142+
c,
143+
&f,
144+
"geos",
145+
"st_distance",
146+
ArrayScalar(Polygon(10), Polygon(10)),
147+
);
148+
benchmark::scalar(
149+
c,
150+
&f,
151+
"geos",
152+
"st_distance",
153+
ArrayScalar(Polygon(10), Polygon(500)),
154+
);
155+
142156
benchmark::scalar(
143157
c,
144158
&f,
145159
"geos",
146160
"st_dwithin",
147161
ArrayArrayScalar(Polygon(10), Polygon(10), Float64(1.0, 2.0)),
148162
);
149-
150163
benchmark::scalar(
151164
c,
152165
&f,
@@ -200,103 +213,92 @@ fn criterion_benchmark(c: &mut Criterion) {
200213
ArrayScalar(Polygon(10), Polygon(500)),
201214
);
202215

216+
benchmark::scalar(c, &f, "geos", "st_isvalid", Polygon(10));
217+
benchmark::scalar(c, &f, "geos", "st_isvalid", Polygon(500));
218+
219+
benchmark::scalar(c, &f, "geos", "st_isvalidreason", Polygon(10));
220+
benchmark::scalar(c, &f, "geos", "st_isvalidreason", Polygon(500));
221+
203222
benchmark::scalar(c, &f, "geos", "st_length", LineString(10));
204223
benchmark::scalar(c, &f, "geos", "st_length", LineString(500));
205224

206-
benchmark::scalar(c, &f, "geos", "st_perimeter", Polygon(10));
207-
benchmark::scalar(c, &f, "geos", "st_perimeter", Polygon(500));
208-
209225
benchmark::scalar(
210226
c,
211227
&f,
212228
"geos",
213-
"st_symdifference",
229+
"st_overlaps",
214230
ArrayScalar(Polygon(10), Polygon(10)),
215231
);
216-
217232
benchmark::scalar(
218233
c,
219234
&f,
220235
"geos",
221-
"st_symdifference",
236+
"st_overlaps",
222237
ArrayScalar(Polygon(10), Polygon(500)),
223238
);
224239

225-
benchmark::scalar(
226-
c,
227-
&f,
228-
"geos",
229-
"st_touches",
230-
ArrayScalar(Polygon(10), Polygon(10)),
231-
);
232-
benchmark::scalar(
233-
c,
234-
&f,
235-
"geos",
236-
"st_touches",
237-
ArrayScalar(Polygon(10), Polygon(500)),
238-
);
240+
benchmark::scalar(c, &f, "geos", "st_perimeter", Polygon(10));
241+
benchmark::scalar(c, &f, "geos", "st_perimeter", Polygon(500));
239242

240243
benchmark::scalar(
241244
c,
242245
&f,
243246
"geos",
244-
"st_union",
247+
"st_symdifference",
245248
ArrayScalar(Polygon(10), Polygon(10)),
246249
);
247-
248250
benchmark::scalar(
249251
c,
250252
&f,
251253
"geos",
252-
"st_union",
254+
"st_symdifference",
253255
ArrayScalar(Polygon(10), Polygon(500)),
254256
);
255257

256258
benchmark::scalar(
257259
c,
258260
&f,
259261
"geos",
260-
"st_within",
262+
"st_touches",
261263
ArrayScalar(Polygon(10), Polygon(10)),
262264
);
263265
benchmark::scalar(
264266
c,
265267
&f,
266268
"geos",
267-
"st_within",
269+
"st_touches",
268270
ArrayScalar(Polygon(10), Polygon(500)),
269271
);
272+
270273
benchmark::scalar(
271274
c,
272275
&f,
273276
"geos",
274-
"st_crosses",
277+
"st_union",
275278
ArrayScalar(Polygon(10), Polygon(10)),
276279
);
277280
benchmark::scalar(
278281
c,
279282
&f,
280283
"geos",
281-
"st_crosses",
284+
"st_union",
282285
ArrayScalar(Polygon(10), Polygon(500)),
283286
);
287+
284288
benchmark::scalar(
285289
c,
286290
&f,
287291
"geos",
288-
"st_overlaps",
292+
"st_within",
289293
ArrayScalar(Polygon(10), Polygon(10)),
290294
);
291295
benchmark::scalar(
292296
c,
293297
&f,
294298
"geos",
295-
"st_overlaps",
299+
"st_within",
296300
ArrayScalar(Polygon(10), Polygon(500)),
297301
);
298-
benchmark::scalar(c, &f, "geos", "st_isvalid", Polygon(10));
299-
benchmark::scalar(c, &f, "geos", "st_isvalid", Polygon(500));
300302
}
301303

302304
criterion_group!(benches, criterion_benchmark);

c/sedona-geos/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod st_convexhull;
2727
mod st_dwithin;
2828
mod st_isring;
2929
mod st_isvalid;
30+
mod st_isvalidreason;
3031
mod st_length;
3132
mod st_perimeter;
3233
pub mod wkb_to_geos;

c/sedona-geos/src/register.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use sedona_expr::scalar_udf::ScalarKernelRef;
1919
use crate::{
2020
distance::st_distance_impl, st_area::st_area_impl, st_buffer::st_buffer_impl,
2121
st_centroid::st_centroid_impl, st_convexhull::st_convex_hull_impl, st_dwithin::st_dwithin_impl,
22-
st_isring::st_is_ring_impl, st_isvalid::st_is_valid_impl, st_length::st_length_impl,
22+
st_isring::st_is_ring_impl, st_isvalid::st_is_valid_impl,
23+
st_isvalidreason::st_is_valid_reason_impl, st_length::st_length_impl,
2324
st_perimeter::st_perimeter_impl,
2425
};
2526

@@ -50,6 +51,8 @@ pub fn scalar_kernels() -> Vec<(&'static str, ScalarKernelRef)> {
5051
("st_intersection", st_intersection_impl()),
5152
("st_intersects", st_intersects_impl()),
5253
("st_isring", st_is_ring_impl()),
54+
("st_isvalid", st_is_valid_impl()),
55+
("st_isvalidreason", st_is_valid_reason_impl()),
5356
("st_length", st_length_impl()),
5457
("st_overlaps", st_overlaps_impl()),
5558
("st_perimeter", st_perimeter_impl()),
@@ -59,6 +62,5 @@ pub fn scalar_kernels() -> Vec<(&'static str, ScalarKernelRef)> {
5962
("st_within", st_within_impl()),
6063
("st_crosses", st_crosses_impl()),
6164
("st_overlaps", st_overlaps_impl()),
62-
("st_isvalid", st_is_valid_impl()),
6365
]
6466
}

0 commit comments

Comments
 (0)