Skip to content

Commit 91f1b7e

Browse files
authored
feat: Add sedona-geo-generic-alg to sedona-db (#195)
This is part of the forked dependency elimination plan: #165. This PR depends on #194. This PR moves geo-generic-alg from wherobots/geo to sedona-db and renamed it to sedona-geo-generic-alg. Currently it is a standalone crate and can be compiled using `cd rust/sedona-geo-generic-alg && cargo build`. We'll update the Cargo.toml files in the final step to make it live. The code moved to sedona-db only contains the algorithms actually used by other parts of the project. There's a backup containing all ported algorithms here: https://github.com/Kontinuation/sedona-db/tree/full-migrate-generic-alg.
1 parent e6cd9c3 commit 91f1b7e

40 files changed

+14965
-0
lines changed

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ c/sedona-geoarrow-c/src/geoarrow (vendored from https://github.com/geoarrow/geoa
212212
c/sedona-geoarrow-c/src/nanoarrow (vendored from https://github.com/apache/arrow-nanoarrow)
213213
c/sedona-s2geography/s2geography (submodule from https://github.com/paleolimbot/s2geography)
214214
c/sedona-s2geography/s2geometry (submodule from https://github.com/google/s2geometry)
215+
rust/sedona-geo-generic-alg (ported and contains copied code from https://github.com/georust/geo)
215216

216217
MIT License
217218
--------------------------------------
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
[package]
18+
name = "sedona-geo-generic-alg"
19+
version = "0.2.0"
20+
authors = ["Apache Sedona <[email protected]>"]
21+
license = "Apache-2.0"
22+
homepage = "https://github.com/apache/sedona-db"
23+
repository = "https://github.com/apache/sedona-db"
24+
description = "geo algorithms refactored to work with sedona-geo-traits-ext"
25+
readme = "README.md"
26+
edition = "2021"
27+
28+
[workspace]
29+
30+
[dependencies]
31+
float_next_after = "1"
32+
geo-traits = { version = "0.3.0" }
33+
geo-types = { version = "0.7.17", features = ["approx", "use-rstar_0_12"] }
34+
sedona-geo-traits-ext = { path = "../sedona-geo-traits-ext" }
35+
log = "0.4.11"
36+
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
37+
robust = "1.1.0"
38+
rstar = "0.12.0"
39+
i_overlay = { version = "4.0.0, < 4.1.0", default-features = false }
40+
41+
[dev-dependencies]
42+
approx = "0.5"
43+
criterion = { version = "0.5", features = ["html_reports"] }
44+
pretty_env_logger = "0.4"
45+
rand = "0.8"
46+
rand_distr = "0.4.3"
47+
geo = "0.31.0"
48+
wkb = "0.9.1"
49+
wkt = "0.14.0"
50+
51+
[patch.crates-io]
52+
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }
53+
54+
[[bench]]
55+
name = "area"
56+
harness = false
57+
58+
[[bench]]
59+
name = "intersection"
60+
harness = false
61+
62+
[[bench]]
63+
name = "centroid"
64+
harness = false
65+
66+
[[bench]]
67+
name = "length"
68+
harness = false
69+
70+
[[bench]]
71+
name = "distance"
72+
harness = false
73+
74+
[[bench]]
75+
name = "perimeter"
76+
harness = false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License. -->
17+
18+
# Generic Algorithms for Geo-Traits
19+
20+
This crate contains algorithms ported from the [`geo` crate](https://github.com/georust/geo),
21+
but works with traits defined in `geo-traits-ext` instead of concrete geometry types defined in
22+
`geo-types`.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
use criterion::{criterion_group, criterion_main, Criterion};
18+
use geo_traits::to_geo::ToGeoGeometry;
19+
use sedona_geo_generic_alg::Area;
20+
use sedona_geo_generic_alg::Polygon;
21+
22+
#[path = "utils/wkb_util.rs"]
23+
mod wkb_util;
24+
25+
fn criterion_benchmark(c: &mut Criterion) {
26+
c.bench_function("area_generic_f32", |bencher| {
27+
let norway = sedona_testing::fixtures::norway_main::<f32>();
28+
let polygon = Polygon::new(norway, vec![]);
29+
30+
bencher.iter(|| {
31+
criterion::black_box(criterion::black_box(&polygon).signed_area());
32+
});
33+
});
34+
35+
c.bench_function("area_generic", |bencher| {
36+
let norway = sedona_testing::fixtures::norway_main::<f64>();
37+
let polygon = Polygon::new(norway, vec![]);
38+
39+
bencher.iter(|| {
40+
criterion::black_box(criterion::black_box(&polygon).signed_area());
41+
});
42+
});
43+
44+
c.bench_function("area_geo_f32", |bencher| {
45+
let norway = sedona_testing::fixtures::norway_main::<f32>();
46+
let polygon = Polygon::new(norway, vec![]);
47+
48+
bencher.iter(|| {
49+
criterion::black_box(geo::Area::signed_area(criterion::black_box(&polygon)));
50+
});
51+
});
52+
53+
c.bench_function("area_geo", |bencher| {
54+
let norway = sedona_testing::fixtures::norway_main::<f64>();
55+
let polygon = Polygon::new(norway, vec![]);
56+
57+
bencher.iter(|| {
58+
criterion::black_box(geo::Area::signed_area(criterion::black_box(&polygon)));
59+
});
60+
});
61+
62+
c.bench_function("area_wkb", |bencher| {
63+
let norway = sedona_testing::fixtures::norway_main::<f64>();
64+
let polygon = Polygon::new(norway, vec![]);
65+
let wkb_bytes = wkb_util::geo_to_wkb(polygon);
66+
67+
bencher.iter(|| {
68+
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
69+
criterion::black_box(wkb_geom.signed_area());
70+
});
71+
});
72+
73+
c.bench_function("area_wkb_convert", |bencher| {
74+
let norway = sedona_testing::fixtures::norway_main::<f64>();
75+
let polygon = Polygon::new(norway, vec![]);
76+
let wkb_bytes = wkb_util::geo_to_wkb(polygon);
77+
78+
bencher.iter(|| {
79+
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
80+
let geom = wkb_geom.to_geometry();
81+
criterion::black_box(geom.signed_area());
82+
});
83+
});
84+
}
85+
86+
criterion_group!(benches, criterion_benchmark);
87+
criterion_main!(benches);
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
use criterion::{criterion_group, criterion_main, Criterion};
18+
use geo_traits::to_geo::ToGeoGeometry;
19+
use sedona_geo_generic_alg::Centroid;
20+
use sedona_geo_generic_alg::Polygon;
21+
22+
#[path = "utils/wkb_util.rs"]
23+
mod wkb_util;
24+
25+
fn criterion_benchmark(c: &mut Criterion) {
26+
c.bench_function("centroid_generic_f32", |bencher| {
27+
let norway = sedona_testing::fixtures::norway_main::<f32>();
28+
let polygon = Polygon::new(norway, vec![]);
29+
30+
bencher.iter(|| {
31+
criterion::black_box(criterion::black_box(&polygon).centroid());
32+
});
33+
});
34+
35+
c.bench_function("centroid_generic", |bencher| {
36+
let norway = sedona_testing::fixtures::norway_main::<f64>();
37+
let polygon = Polygon::new(norway, vec![]);
38+
39+
bencher.iter(|| {
40+
criterion::black_box(criterion::black_box(&polygon).centroid());
41+
});
42+
});
43+
44+
c.bench_function("centroid_geo_f32", |bencher| {
45+
let norway = sedona_testing::fixtures::norway_main::<f32>();
46+
let polygon = Polygon::new(norway, vec![]);
47+
48+
bencher.iter(|| {
49+
criterion::black_box(geo::Centroid::centroid(criterion::black_box(&polygon)));
50+
});
51+
});
52+
53+
c.bench_function("centroid_geo", |bencher| {
54+
let norway = sedona_testing::fixtures::norway_main::<f64>();
55+
let polygon = Polygon::new(norway, vec![]);
56+
57+
bencher.iter(|| {
58+
criterion::black_box(geo::Centroid::centroid(criterion::black_box(&polygon)));
59+
});
60+
});
61+
62+
c.bench_function("centroid_wkb", |bencher| {
63+
let norway = sedona_testing::fixtures::norway_main::<f64>();
64+
let polygon = Polygon::new(norway, vec![]);
65+
let wkb_bytes = wkb_util::geo_to_wkb(polygon);
66+
67+
bencher.iter(|| {
68+
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
69+
criterion::black_box(wkb_geom.centroid());
70+
});
71+
});
72+
73+
c.bench_function("centroid_wkb_convert", |bencher| {
74+
let norway = sedona_testing::fixtures::norway_main::<f64>();
75+
let polygon = Polygon::new(norway, vec![]);
76+
let wkb_bytes = wkb_util::geo_to_wkb(polygon);
77+
78+
bencher.iter(|| {
79+
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
80+
let geom = wkb_geom.to_geometry();
81+
criterion::black_box(geom.centroid());
82+
});
83+
});
84+
}
85+
86+
criterion_group!(benches, criterion_benchmark);
87+
criterion_main!(benches);

0 commit comments

Comments
 (0)