Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ c/sedona-geoarrow-c/src/geoarrow (vendored from https://github.com/geoarrow/geoa
c/sedona-geoarrow-c/src/nanoarrow (vendored from https://github.com/apache/arrow-nanoarrow)
c/sedona-s2geography/s2geography (submodule from https://github.com/paleolimbot/s2geography)
c/sedona-s2geography/s2geometry (submodule from https://github.com/google/s2geometry)
rust/sedona-geo-generic-alg (ported and contains copied code from https://github.com/georust/geo)

MIT License
--------------------------------------
Expand Down
82 changes: 82 additions & 0 deletions rust/sedona-geo-generic-alg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
[package]
name = "sedona-geo-generic-alg"
version = "0.2.0"
authors = ["Apache Sedona <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/apache/sedona-db"
repository = "https://github.com/apache/sedona-db"
description = "geo algorithms refactored to work with sedona-geo-traits-ext"
readme = "README.md"
edition = "2021"
Comment on lines +19 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can probably use { workspace = true} to avoid keeping them up to date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Currently sedona-geo-generic-alg is in its standalone workspace, not in the workspace of sedona-db. Adding it to the workspace of sedona-db will result in the most terrible dependency conflict. We'll add it to sedona-db's workspace and update this to inherit from workspace in the final step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it!


[workspace]

[features]
default = ["multithreading"]
use-serde = ["serde", "geo-types/serde"]
multithreading = ["i_overlay/allow_multithreading", "geo-types/multithreading"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's worth it or not, but I was able to remove these (plus rstar and serde) without affecting the build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These features are not needed for now. I'll remove them.


[dependencies]
float_next_after = "1"
geo-traits = { version = "0.3.0" }
geo-types = { version = "0.7.17", features = ["approx", "use-rstar_0_12"] }
sedona-geo-traits-ext = { path = "../sedona-geo-traits-ext" }
log = "0.4.11"
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
robust = "1.1.0"
rstar = "0.12.0"
serde = { version = "1", features = ["derive"], optional = true }
i_overlay = { version = "4.0.0, < 4.1.0", default-features = false }

[dev-dependencies]
approx = "0.5"
criterion = { version = "0.5", features = ["html_reports"] }
pretty_env_logger = "0.4"
rand = "0.8"
rand_distr = "0.4.3"
geo = "0.31.0"
wkb = "0.9.1"
wkt = "0.14.0"

[patch.crates-io]
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }

[[bench]]
name = "area"
harness = false

[[bench]]
name = "intersection"
harness = false

[[bench]]
name = "centroid"
harness = false

[[bench]]
name = "length"
harness = false

[[bench]]
name = "distance"
harness = false

[[bench]]
name = "perimeter"
harness = false
22 changes: 22 additions & 0 deletions rust/sedona-geo-generic-alg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License. -->

# Generic Algorithms for Geo-Traits

This crate contains algorithms ported from the [`geo` crate](https://github.com/georust/geo),
but works with traits defined in `geo-traits-ext` instead of concrete geometry types defined in
`geo-types`.
87 changes: 87 additions & 0 deletions rust/sedona-geo-generic-alg/benches/area.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use criterion::{criterion_group, criterion_main, Criterion};
use geo_traits::to_geo::ToGeoGeometry;
use sedona_geo_generic_alg::Area;
use sedona_geo_generic_alg::Polygon;

#[path = "utils/wkb_util.rs"]
mod wkb_util;

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("area_generic_f32", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f32>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(criterion::black_box(&polygon).signed_area());
});
});

c.bench_function("area_generic", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(criterion::black_box(&polygon).signed_area());
});
});

c.bench_function("area_geo_f32", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f32>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(geo::Area::signed_area(criterion::black_box(&polygon)));
});
});

c.bench_function("area_geo", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(geo::Area::signed_area(criterion::black_box(&polygon)));
});
});

c.bench_function("area_wkb", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);
let wkb_bytes = wkb_util::geo_to_wkb(polygon);

bencher.iter(|| {
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
criterion::black_box(wkb_geom.signed_area());
});
});

c.bench_function("area_wkb_convert", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);
let wkb_bytes = wkb_util::geo_to_wkb(polygon);

bencher.iter(|| {
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
let geom = wkb_geom.to_geometry();
criterion::black_box(geom.signed_area());
});
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
87 changes: 87 additions & 0 deletions rust/sedona-geo-generic-alg/benches/centroid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use criterion::{criterion_group, criterion_main, Criterion};
use geo_traits::to_geo::ToGeoGeometry;
use sedona_geo_generic_alg::Centroid;
use sedona_geo_generic_alg::Polygon;

#[path = "utils/wkb_util.rs"]
mod wkb_util;

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("centroid_generic_f32", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f32>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(criterion::black_box(&polygon).centroid());
});
});

c.bench_function("centroid_generic", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(criterion::black_box(&polygon).centroid());
});
});

c.bench_function("centroid_geo_f32", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f32>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(geo::Centroid::centroid(criterion::black_box(&polygon)));
});
});

c.bench_function("centroid_geo", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);

bencher.iter(|| {
criterion::black_box(geo::Centroid::centroid(criterion::black_box(&polygon)));
});
});

c.bench_function("centroid_wkb", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);
let wkb_bytes = wkb_util::geo_to_wkb(polygon);

bencher.iter(|| {
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
criterion::black_box(wkb_geom.centroid());
});
});

c.bench_function("centroid_wkb_convert", |bencher| {
let norway = sedona_testing::fixtures::norway_main::<f64>();
let polygon = Polygon::new(norway, vec![]);
let wkb_bytes = wkb_util::geo_to_wkb(polygon);

bencher.iter(|| {
let wkb_geom = wkb::reader::read_wkb(&wkb_bytes).unwrap();
let geom = wkb_geom.to_geometry();
criterion::black_box(geom.centroid());
});
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading