Skip to content

Commit 3f317ba

Browse files
committed
Add sedona-geo-traits-ext to sedona-db
1 parent 0b59c90 commit 3f317ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+20605
-0
lines changed

rust/sedona-geo-generic-alg/Cargo.lock

Lines changed: 1194 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
[features]
31+
default = ["multithreading"]
32+
use-serde = ["serde", "geo-types/serde"]
33+
multithreading = ["i_overlay/allow_multithreading", "geo-types/multithreading"]
34+
35+
[dependencies]
36+
float_next_after = "1"
37+
geo-traits = { version = "0.3.0" }
38+
geo-types = { version = "0.7.17", features = ["approx", "use-rstar_0_12"] }
39+
sedona-geo-traits-ext = { path = "../sedona-geo-traits-ext" }
40+
log = "0.4.11"
41+
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
42+
robust = "1.1.0"
43+
rstar = "0.12.0"
44+
serde = { version = "1", features = ["derive"], optional = true }
45+
i_overlay = { version = "4.0.0, < 4.1.0", default-features = false }
46+
47+
[dev-dependencies]
48+
approx = "0.5"
49+
criterion = { version = "0.5", features = ["html_reports"] }
50+
pretty_env_logger = "0.4"
51+
rand = "0.8"
52+
rand_distr = "0.4.3"
53+
geo = "0.31.0"
54+
wkb = "0.9.1"
55+
wkt = "0.14.0"
56+
57+
[patch.crates-io]
58+
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }
59+
60+
[[bench]]
61+
name = "area"
62+
harness = false
63+
64+
[[bench]]
65+
name = "intersection"
66+
harness = false
67+
68+
[[bench]]
69+
name = "centroid"
70+
harness = false
71+
72+
[[bench]]
73+
name = "length"
74+
harness = false
75+
76+
[[bench]]
77+
name = "distance"
78+
harness = false
79+
80+
[[bench]]
81+
name = "perimeter"
82+
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)