rust-geo-python 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -209,9 +209,12 @@ checksum = "35e6d558e6d4c7b82bc51d9c771e7a927862a161a7d87bf2b0541450e0e20915"
209
209
 
210
210
  [[package]]
211
211
  name = "indoc"
212
- version = "2.0.6"
212
+ version = "2.0.7"
213
213
  source = "registry+https://github.com/rust-lang/crates.io-index"
214
- checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
214
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
215
+ dependencies = [
216
+ "rustversion",
217
+ ]
215
218
 
216
219
  [[package]]
217
220
  name = "itertools"
@@ -224,9 +227,9 @@ dependencies = [
224
227
 
225
228
  [[package]]
226
229
  name = "libc"
227
- version = "0.2.176"
230
+ version = "0.2.177"
228
231
  source = "registry+https://github.com/rust-lang/crates.io-index"
229
- checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
232
+ checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
230
233
 
231
234
  [[package]]
232
235
  name = "libm"
@@ -305,9 +308,9 @@ dependencies = [
305
308
 
306
309
  [[package]]
307
310
  name = "numpy"
308
- version = "0.26.0"
311
+ version = "0.27.0"
309
312
  source = "registry+https://github.com/rust-lang/crates.io-index"
310
- checksum = "9b2dba356160b54f5371b550575b78130a54718b4c6e46b3f33a6da74a27e78b"
313
+ checksum = "0fa24ffc88cf9d43f7269d6b6a0d0a00010924a8cc90604a21ef9c433b66998d"
311
314
  dependencies = [
312
315
  "libc",
313
316
  "ndarray",
@@ -342,18 +345,18 @@ dependencies = [
342
345
 
343
346
  [[package]]
344
347
  name = "proc-macro2"
345
- version = "1.0.101"
348
+ version = "1.0.103"
346
349
  source = "registry+https://github.com/rust-lang/crates.io-index"
347
- checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
350
+ checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
348
351
  dependencies = [
349
352
  "unicode-ident",
350
353
  ]
351
354
 
352
355
  [[package]]
353
356
  name = "pyo3"
354
- version = "0.26.0"
357
+ version = "0.27.1"
355
358
  source = "registry+https://github.com/rust-lang/crates.io-index"
356
- checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383"
359
+ checksum = "37a6df7eab65fc7bee654a421404947e10a0f7085b6951bf2ea395f4659fb0cf"
357
360
  dependencies = [
358
361
  "indoc",
359
362
  "libc",
@@ -368,18 +371,18 @@ dependencies = [
368
371
 
369
372
  [[package]]
370
373
  name = "pyo3-build-config"
371
- version = "0.26.0"
374
+ version = "0.27.1"
372
375
  source = "registry+https://github.com/rust-lang/crates.io-index"
373
- checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f"
376
+ checksum = "f77d387774f6f6eec64a004eac0ed525aab7fa1966d94b42f743797b3e395afb"
374
377
  dependencies = [
375
378
  "target-lexicon",
376
379
  ]
377
380
 
378
381
  [[package]]
379
382
  name = "pyo3-ffi"
380
- version = "0.26.0"
383
+ version = "0.27.1"
381
384
  source = "registry+https://github.com/rust-lang/crates.io-index"
382
- checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105"
385
+ checksum = "2dd13844a4242793e02df3e2ec093f540d948299a6a77ea9ce7afd8623f542be"
383
386
  dependencies = [
384
387
  "libc",
385
388
  "pyo3-build-config",
@@ -387,9 +390,9 @@ dependencies = [
387
390
 
388
391
  [[package]]
389
392
  name = "pyo3-macros"
390
- version = "0.26.0"
393
+ version = "0.27.1"
391
394
  source = "registry+https://github.com/rust-lang/crates.io-index"
392
- checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded"
395
+ checksum = "eaf8f9f1108270b90d3676b8679586385430e5c0bb78bb5f043f95499c821a71"
393
396
  dependencies = [
394
397
  "proc-macro2",
395
398
  "pyo3-macros-backend",
@@ -399,9 +402,9 @@ dependencies = [
399
402
 
400
403
  [[package]]
401
404
  name = "pyo3-macros-backend"
402
- version = "0.26.0"
405
+ version = "0.27.1"
403
406
  source = "registry+https://github.com/rust-lang/crates.io-index"
404
- checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf"
407
+ checksum = "70a3b2274450ba5288bc9b8c1b69ff569d1d61189d4bff38f8d22e03d17f932b"
405
408
  dependencies = [
406
409
  "heck",
407
410
  "proc-macro2",
@@ -412,9 +415,9 @@ dependencies = [
412
415
 
413
416
  [[package]]
414
417
  name = "quote"
415
- version = "1.0.41"
418
+ version = "1.0.42"
416
419
  source = "registry+https://github.com/rust-lang/crates.io-index"
417
- checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
420
+ checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
418
421
  dependencies = [
419
422
  "proc-macro2",
420
423
  ]
@@ -464,7 +467,7 @@ dependencies = [
464
467
 
465
468
  [[package]]
466
469
  name = "rust-geo-python"
467
- version = "0.1.1"
470
+ version = "0.1.2"
468
471
  dependencies = [
469
472
  "geo",
470
473
  "ndarray",
@@ -478,6 +481,12 @@ version = "2.1.1"
478
481
  source = "registry+https://github.com/rust-lang/crates.io-index"
479
482
  checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
480
483
 
484
+ [[package]]
485
+ name = "rustversion"
486
+ version = "1.0.22"
487
+ source = "registry+https://github.com/rust-lang/crates.io-index"
488
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
489
+
481
490
  [[package]]
482
491
  name = "serde"
483
492
  version = "1.0.228"
@@ -534,9 +543,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
534
543
 
535
544
  [[package]]
536
545
  name = "syn"
537
- version = "2.0.106"
546
+ version = "2.0.109"
538
547
  source = "registry+https://github.com/rust-lang/crates.io-index"
539
- checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
548
+ checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f"
540
549
  dependencies = [
541
550
  "proc-macro2",
542
551
  "quote",
@@ -551,9 +560,9 @@ checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c"
551
560
 
552
561
  [[package]]
553
562
  name = "unicode-ident"
554
- version = "1.0.19"
563
+ version = "1.0.22"
555
564
  source = "registry+https://github.com/rust-lang/crates.io-index"
556
- checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
565
+ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
557
566
 
558
567
  [[package]]
559
568
  name = "unindent"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rust-geo-python"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  authors = ["plooney"]
5
5
  edition = "2024"
6
6
  readme = "README.md"
@@ -10,9 +10,9 @@ name = "rust_geo_python"
10
10
  crate-type = ["cdylib"]
11
11
 
12
12
  [dependencies]
13
- pyo3 = { version = "0.26.0", features = ["extension-module", "abi3-py37"] }
13
+ pyo3 = { version = "0.27.1", features = ["extension-module", "abi3-py37"] }
14
14
  ndarray = {version="0.16", features = ["rayon"]}
15
- numpy = "0.26.0"
15
+ numpy = "0.27.0"
16
16
  geo = { version = "0.31.0" }
17
17
 
18
18
  [workspace]
@@ -22,3 +22,9 @@ MACOSX_DEPLOYMENT_TARGET = "10.12"
22
22
 
23
23
  [tool.cibuildwheel]
24
24
  skip = ["*-musllinux_i686"]
25
+
26
+ [target.x86_64-apple-darwin]
27
+ rustflags = [
28
+ "-C", "link-arg=-undefined",
29
+ "-C", "link-arg=dynamic_lookup",
30
+ ]
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Padraig Looney
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rust-geo-python
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Author: plooney
5
5
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
6
6
 
@@ -0,0 +1,174 @@
1
+ #[pyo3::pymodule]
2
+ mod rust_geo_python {
3
+ use ndarray::parallel::prelude::ParallelIterator;
4
+ use numpy::ndarray::{Array1, Array2, Axis};
5
+ use numpy::{IntoPyArray, PyArray1, PyArray2, PyReadonlyArray1, PyReadonlyArray2};
6
+
7
+ use geo::{BooleanOps, Distance, Euclidean, LineString, Point, Polygon, unary_union};
8
+ use ndarray::parallel::prelude::IntoParallelIterator;
9
+ use ndarray::{ArrayView1, ArrayView2};
10
+ use pyo3::prelude::*;
11
+ use pyo3::{Bound, PyResult, Python};
12
+
13
+ fn point_poly_distance(x: ArrayView1<f64>, y: ArrayView2<f64>) -> f64 {
14
+ let path = y
15
+ .axis_iter(Axis(0))
16
+ .map(|x| Point::new(x[0], x[1]))
17
+ .collect::<LineString>();
18
+ let point = Point::new(x[0], x[1]);
19
+ let distance = Euclidean.distance(&point, &path);
20
+ distance
21
+ }
22
+
23
+ #[pyfunction(name = "point_poly_distance")]
24
+ fn point_poly_distance_py<'py>(
25
+ x: PyReadonlyArray1<'py, f64>,
26
+ y: PyReadonlyArray2<'py, f64>,
27
+ ) -> PyResult<f64> {
28
+ let x = x.as_array();
29
+ let y = y.as_array();
30
+ let distance = point_poly_distance(x, y);
31
+ Ok(distance)
32
+ }
33
+
34
+ #[pyfunction(name = "points_polygon_distance")]
35
+ fn points_poly_distance_py<'py>(
36
+ py: Python<'py>,
37
+ x: PyReadonlyArray2<'py, f64>,
38
+ y: PyReadonlyArray2<'py, f64>,
39
+ ) -> Bound<'py, PyArray1<f64>> {
40
+ let x = x.as_array();
41
+ let y = y.as_array();
42
+ let distances = x
43
+ .axis_iter(Axis(0))
44
+ .map(|p| point_poly_distance(p, y))
45
+ .collect::<Array1<f64>>();
46
+ distances.into_pyarray(py)
47
+ }
48
+
49
+ #[pyfunction(name = "polygon_polygon_distance")]
50
+ fn poly_poly_distance_py<'py>(
51
+ x: PyReadonlyArray2<'py, f64>,
52
+ y: PyReadonlyArray2<'py, f64>,
53
+ ) -> f64 {
54
+ let path_x = x
55
+ .as_array()
56
+ .axis_iter(Axis(0))
57
+ .map(|x| Point::new(x[0], x[1]))
58
+ .collect::<LineString>();
59
+ let path_y = y
60
+ .as_array()
61
+ .axis_iter(Axis(0))
62
+ .map(|x| Point::new(x[0], x[1]))
63
+ .collect::<LineString>();
64
+ let distance = Euclidean.distance(&path_x, &path_y);
65
+ distance
66
+ }
67
+
68
+ #[pyfunction(name = "points_polygon_dist_mut")]
69
+ fn points_poly_distance_mut_py<'py>(
70
+ py: Python<'py>,
71
+ x: PyReadonlyArray2<'py, f64>,
72
+ y: PyReadonlyArray2<'py, f64>,
73
+ ) -> Bound<'py, PyArray1<f64>> {
74
+ let x = x.as_array();
75
+ let y = y.as_array();
76
+ let distances_vec = x
77
+ .axis_iter(Axis(0))
78
+ .into_par_iter()
79
+ .map(|p| point_poly_distance(p, y))
80
+ .collect::<Vec<f64>>();
81
+ distances_vec.into_pyarray(py)
82
+ }
83
+
84
+ fn array2_to_linestring<'py>(x: &PyReadonlyArray2<'py, f64>) -> LineString {
85
+ let path = x
86
+ .as_array()
87
+ .axis_iter(Axis(0))
88
+ .map(|y| Point::new(y[0], y[1]))
89
+ .collect::<LineString>();
90
+ path
91
+ }
92
+
93
+ fn array2_to_polygon<'py>(
94
+ x: &PyReadonlyArray2<'py, f64>,
95
+ ys: &Vec<PyReadonlyArray2<'py, f64>>,
96
+ ) -> Polygon {
97
+ let exterior = array2_to_linestring(&x);
98
+ let interiors = ys
99
+ .iter()
100
+ .map(|y| array2_to_linestring(y))
101
+ .collect::<Vec<LineString>>();
102
+ Polygon::new(exterior, interiors)
103
+ }
104
+
105
+ fn linestring_to_array2<'py>(py: Python<'py>, ls: &LineString) -> Bound<'py, PyArray2<f64>> {
106
+ let n_points = ls.points().len();
107
+ let mut arr = Array2::zeros((2, n_points));
108
+ let mut i = 0;
109
+ ls.points().for_each(|p| {
110
+ let (x, y) = p.x_y();
111
+ arr[[0, i]] = x;
112
+ arr[[1, i]] = y;
113
+ i += 1;
114
+ });
115
+ let pyarray = PyArray2::from_owned_array(py, arr);
116
+ pyarray
117
+ }
118
+
119
+ fn polygons_to_array2<'py>(
120
+ py: Python<'py>,
121
+ polygons: Vec<&Polygon>,
122
+ ) -> Vec<(Bound<'py, PyArray2<f64>>, Vec<Bound<'py, PyArray2<f64>>>)> {
123
+ polygons
124
+ .iter()
125
+ .map(|p| {
126
+ let ext = p.exterior();
127
+ let ext_array = linestring_to_array2(py, ext);
128
+ let int_arrays = p
129
+ .interiors()
130
+ .iter()
131
+ .map(|ls| linestring_to_array2(py, ls))
132
+ .collect::<Vec<Bound<'py, PyArray2<f64>>>>();
133
+ (ext_array, int_arrays)
134
+ })
135
+ .collect::<Vec<(Bound<'py, PyArray2<f64>>, Vec<Bound<'py, PyArray2<f64>>>)>>()
136
+ }
137
+
138
+ #[pyfunction]
139
+ fn union_set_shapes<'py>(
140
+ py: Python<'py>,
141
+ pyarrays: Vec<(PyReadonlyArray2<'py, f64>, Vec<PyReadonlyArray2<'py, f64>>)>,
142
+ ) -> Vec<(Bound<'py, PyArray2<f64>>, Vec<Bound<'py, PyArray2<f64>>>)> {
143
+ let polygons = pyarrays
144
+ .iter()
145
+ .map(|(x, ys)| array2_to_polygon(x, ys))
146
+ .collect::<Vec<Polygon>>();
147
+ let union = unary_union(&polygons);
148
+ polygons_to_array2(py, union.iter().collect::<Vec<&Polygon>>())
149
+ }
150
+
151
+ #[pyfunction]
152
+ fn intersection_shapes<'py>(
153
+ py: Python<'py>,
154
+ pyarray_x: (PyReadonlyArray2<'py, f64>, Vec<PyReadonlyArray2<'py, f64>>),
155
+ pyarray_y: (PyReadonlyArray2<'py, f64>, Vec<PyReadonlyArray2<'py, f64>>),
156
+ ) -> Vec<(Bound<'py, PyArray2<f64>>, Vec<Bound<'py, PyArray2<f64>>>)> {
157
+ let polygon_x = array2_to_polygon(&pyarray_x.0, &pyarray_x.1);
158
+ let polygon_y = array2_to_polygon(&pyarray_y.0, &pyarray_y.1);
159
+ let intersection = polygon_x.intersection(&polygon_y);
160
+ polygons_to_array2(py, intersection.iter().collect::<Vec<&Polygon>>())
161
+ }
162
+
163
+ #[pyfunction]
164
+ fn difference_shapes<'py>(
165
+ py: Python<'py>,
166
+ pyarray_x: (PyReadonlyArray2<'py, f64>, Vec<PyReadonlyArray2<'py, f64>>),
167
+ pyarray_y: (PyReadonlyArray2<'py, f64>, Vec<PyReadonlyArray2<'py, f64>>),
168
+ ) -> Vec<(Bound<'py, PyArray2<f64>>, Vec<Bound<'py, PyArray2<f64>>>)> {
169
+ let polygon_x = array2_to_polygon(&pyarray_x.0, &pyarray_x.1);
170
+ let polygon_y = array2_to_polygon(&pyarray_y.0, &pyarray_y.1);
171
+ let intersection = polygon_x.difference(&polygon_y);
172
+ polygons_to_array2(py, intersection.iter().collect::<Vec<&Polygon>>())
173
+ }
174
+ }
@@ -1,86 +0,0 @@
1
- use ndarray::parallel::prelude::ParallelIterator;
2
- use numpy::ndarray::{Axis, Array1};
3
- use numpy::{PyArray1, PyReadonlyArray1, PyReadonlyArray2, IntoPyArray};
4
-
5
- use geo::{Point, LineString, Distance, Euclidean};
6
- use ndarray::{ArrayView1, ArrayView2};
7
- use ndarray::parallel::prelude::IntoParallelIterator;
8
- use pyo3::{pymodule, types::{PyModule}, Bound, PyResult, Python};
9
-
10
- #[pymodule]
11
- #[pyo3(name = "rust_geo_python")]
12
- fn polygon<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
13
-
14
- fn point_poly_distance(x: ArrayView1<f64>, y: ArrayView2<f64>) -> f64 {
15
- let path = y.axis_iter(Axis(0))
16
- .map(|x| Point::new(x[0], x[1]))
17
- .collect::<LineString>();
18
- let point = Point::new(x[0], x[1]);
19
- let distance = Euclidean.distance(&point,&path);
20
- distance
21
-
22
- }
23
-
24
- #[pyfn(m)]
25
- #[pyo3(name = "point_polygon_distance")]
26
- fn point_poly_distance_py<'py>(
27
- x: PyReadonlyArray1<'py, f64>,
28
- y: PyReadonlyArray2<'py, f64>,
29
- ) -> PyResult<f64> {
30
- let x = x.as_array();
31
- let y = y.as_array();
32
- let distance = point_poly_distance(x, y);
33
- Ok(distance)
34
- }
35
-
36
- #[pyfn(m)]
37
- #[pyo3(name = "points_polygon_distance")]
38
- fn points_poly_distance_py<'py>(
39
- py: Python<'py>,
40
- x: PyReadonlyArray2<'py, f64>,
41
- y: PyReadonlyArray2<'py, f64>,
42
- ) -> Bound<'py, PyArray1<f64>> {
43
- let x = x.as_array();
44
- let y = y.as_array();
45
- let distances = x.axis_iter(Axis(0))
46
- .map(|p| point_poly_distance(p,y))
47
- .collect::<Array1<f64>>();
48
- distances.into_pyarray(py)
49
- }
50
- #[pyfn(m)]
51
- #[pyo3(name = "polygon_polygon_distance")]
52
- fn poly_poly_distance_py<'py>(
53
- x: PyReadonlyArray2<'py, f64>,
54
- y: PyReadonlyArray2<'py, f64>,
55
- ) -> f64 {
56
- let path_x = x
57
- .as_array()
58
- .axis_iter(Axis(0))
59
- .map(|x| Point::new(x[0], x[1]))
60
- .collect::<LineString>();
61
- let path_y = y
62
- .as_array()
63
- .axis_iter(Axis(0))
64
- .map(|x| Point::new(x[0], x[1]))
65
- .collect::<LineString>();
66
- let distance = Euclidean.distance(&path_x,&path_y);
67
- distance
68
- }
69
-
70
- #[pyfn(m)]
71
- #[pyo3(name = "points_polygon_dist_mut")]
72
- fn points_poly_distance_mut_py<'py>(
73
- py: Python<'py>,
74
- x: PyReadonlyArray2<'py, f64>,
75
- y: PyReadonlyArray2<'py, f64>,
76
- ) -> Bound<'py, PyArray1<f64>> {
77
- let x = x.as_array();
78
- let y = y.as_array();
79
- let distances_vec = x.axis_iter(Axis(0)).into_par_iter()
80
- .map(|p| point_poly_distance(p,y))
81
- .collect::<Vec<f64>>();
82
- distances_vec.into_pyarray(py)
83
- }
84
-
85
- Ok(())
86
- }