rust-geo-python 0.1.7__tar.gz → 0.1.8__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.
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/.gitignore +6 -0
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/Cargo.lock +31 -29
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/Cargo.toml +3 -1
- rust_geo_python-0.1.8/PKG-INFO +149 -0
- rust_geo_python-0.1.8/README.md +142 -0
- {rust_geo_python-0.1.7/src → rust_geo_python-0.1.8/src/core}/functions.rs +10 -8
- rust_geo_python-0.1.8/src/core/mod.rs +2 -0
- rust_geo_python-0.1.8/src/core/tiling.rs +169 -0
- rust_geo_python-0.1.8/src/error.rs +23 -0
- rust_geo_python-0.1.8/src/lib.rs +24 -0
- rust_geo_python-0.1.8/src/macros.rs +342 -0
- rust_geo_python-0.1.8/src/py/enums.rs +1155 -0
- rust_geo_python-0.1.8/src/py/mod.rs +2 -0
- {rust_geo_python-0.1.7/src → rust_geo_python-0.1.8/src/py}/pyfunctions.rs +55 -22
- rust_geo_python-0.1.8/tests/test_geometry_creation.py +53 -0
- rust_geo_python-0.1.8/tests/test_measurements.py +47 -0
- rust_geo_python-0.1.8/tests/test_predicates.py +51 -0
- rust_geo_python-0.1.8/tests/test_set_operations.py +52 -0
- rust_geo_python-0.1.8/tests/test_stand-alone_functions.py +45 -0
- rust_geo_python-0.1.8/tests/test_wkt_and_collections.py +45 -0
- rust_geo_python-0.1.7/PKG-INFO +0 -8
- rust_geo_python-0.1.7/README.md +0 -1
- rust_geo_python-0.1.7/src/enums.rs +0 -732
- rust_geo_python-0.1.7/src/lib.rs +0 -22
- rust_geo_python-0.1.7/src/macros.rs +0 -128
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/.github/workflows/CI.yml +0 -0
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/LICENSE.txt +0 -0
- {rust_geo_python-0.1.7 → rust_geo_python-0.1.8}/pyproject.toml +0 -0
|
@@ -31,9 +31,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|
|
31
31
|
|
|
32
32
|
[[package]]
|
|
33
33
|
name = "cc"
|
|
34
|
-
version = "1.2.
|
|
34
|
+
version = "1.2.55"
|
|
35
35
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
-
checksum = "
|
|
36
|
+
checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29"
|
|
37
37
|
dependencies = [
|
|
38
38
|
"find-msvc-tools",
|
|
39
39
|
"shlex",
|
|
@@ -94,9 +94,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
|
94
94
|
|
|
95
95
|
[[package]]
|
|
96
96
|
name = "find-msvc-tools"
|
|
97
|
-
version = "0.1.
|
|
97
|
+
version = "0.1.9"
|
|
98
98
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
99
|
-
checksum = "
|
|
99
|
+
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
|
100
100
|
|
|
101
101
|
[[package]]
|
|
102
102
|
name = "float_next_after"
|
|
@@ -154,9 +154,9 @@ dependencies = [
|
|
|
154
154
|
|
|
155
155
|
[[package]]
|
|
156
156
|
name = "geographiclib-rs"
|
|
157
|
-
version = "0.2.
|
|
157
|
+
version = "0.2.6"
|
|
158
158
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
159
|
-
checksum = "
|
|
159
|
+
checksum = "bc8f647bd562db28a15e0dce4a77d89e3a78f6f85943e782418ebdbb420ea3c4"
|
|
160
160
|
dependencies = [
|
|
161
161
|
"libm",
|
|
162
162
|
]
|
|
@@ -231,9 +231,9 @@ checksum = "9190f86706ca38ac8add223b2aed8b1330002b5cdbbce28fb58b10914d38fc27"
|
|
|
231
231
|
|
|
232
232
|
[[package]]
|
|
233
233
|
name = "i_overlay"
|
|
234
|
-
version = "4.0.
|
|
234
|
+
version = "4.0.7"
|
|
235
235
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
-
checksum = "
|
|
236
|
+
checksum = "413183068e6e0289e18d7d0a1f661b81546e6918d5453a44570b9ab30cbed1b3"
|
|
237
237
|
dependencies = [
|
|
238
238
|
"i_float",
|
|
239
239
|
"i_key_sort",
|
|
@@ -287,15 +287,15 @@ dependencies = [
|
|
|
287
287
|
|
|
288
288
|
[[package]]
|
|
289
289
|
name = "libc"
|
|
290
|
-
version = "0.2.
|
|
290
|
+
version = "0.2.181"
|
|
291
291
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
292
|
-
checksum = "
|
|
292
|
+
checksum = "459427e2af2b9c839b132acb702a1c654d95e10f8c326bfc2ad11310e458b1c5"
|
|
293
293
|
|
|
294
294
|
[[package]]
|
|
295
295
|
name = "libm"
|
|
296
|
-
version = "0.2.
|
|
296
|
+
version = "0.2.16"
|
|
297
297
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
298
|
-
checksum = "
|
|
298
|
+
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
|
299
299
|
|
|
300
300
|
[[package]]
|
|
301
301
|
name = "log"
|
|
@@ -315,9 +315,9 @@ dependencies = [
|
|
|
315
315
|
|
|
316
316
|
[[package]]
|
|
317
317
|
name = "memchr"
|
|
318
|
-
version = "2.
|
|
318
|
+
version = "2.8.0"
|
|
319
319
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
320
|
-
checksum = "
|
|
320
|
+
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
|
321
321
|
|
|
322
322
|
[[package]]
|
|
323
323
|
name = "memoffset"
|
|
@@ -418,15 +418,15 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
|
418
418
|
|
|
419
419
|
[[package]]
|
|
420
420
|
name = "portable-atomic"
|
|
421
|
-
version = "1.13.
|
|
421
|
+
version = "1.13.1"
|
|
422
422
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
423
|
-
checksum = "
|
|
423
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
424
424
|
|
|
425
425
|
[[package]]
|
|
426
426
|
name = "portable-atomic-util"
|
|
427
|
-
version = "0.2.
|
|
427
|
+
version = "0.2.5"
|
|
428
428
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
429
|
-
checksum = "
|
|
429
|
+
checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5"
|
|
430
430
|
dependencies = [
|
|
431
431
|
"portable-atomic",
|
|
432
432
|
]
|
|
@@ -451,9 +451,9 @@ dependencies = [
|
|
|
451
451
|
|
|
452
452
|
[[package]]
|
|
453
453
|
name = "proc-macro2"
|
|
454
|
-
version = "1.0.
|
|
454
|
+
version = "1.0.106"
|
|
455
455
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
456
|
-
checksum = "
|
|
456
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
457
457
|
dependencies = [
|
|
458
458
|
"unicode-ident",
|
|
459
459
|
]
|
|
@@ -531,9 +531,9 @@ dependencies = [
|
|
|
531
531
|
|
|
532
532
|
[[package]]
|
|
533
533
|
name = "quote"
|
|
534
|
-
version = "1.0.
|
|
534
|
+
version = "1.0.44"
|
|
535
535
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
536
|
-
checksum = "
|
|
536
|
+
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
|
537
537
|
dependencies = [
|
|
538
538
|
"proc-macro2",
|
|
539
539
|
]
|
|
@@ -613,10 +613,12 @@ dependencies = [
|
|
|
613
613
|
|
|
614
614
|
[[package]]
|
|
615
615
|
name = "rust-geo-python"
|
|
616
|
-
version = "0.1.
|
|
616
|
+
version = "0.1.8"
|
|
617
617
|
dependencies = [
|
|
618
618
|
"geo",
|
|
619
|
+
"i_overlay",
|
|
619
620
|
"ndarray",
|
|
621
|
+
"num-traits",
|
|
620
622
|
"numpy",
|
|
621
623
|
"pyo3",
|
|
622
624
|
"wkb",
|
|
@@ -770,9 +772,9 @@ dependencies = [
|
|
|
770
772
|
|
|
771
773
|
[[package]]
|
|
772
774
|
name = "unicode-ident"
|
|
773
|
-
version = "1.0.
|
|
775
|
+
version = "1.0.23"
|
|
774
776
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
775
|
-
checksum = "
|
|
777
|
+
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
|
|
776
778
|
|
|
777
779
|
[[package]]
|
|
778
780
|
name = "unindent"
|
|
@@ -822,18 +824,18 @@ dependencies = [
|
|
|
822
824
|
|
|
823
825
|
[[package]]
|
|
824
826
|
name = "zerocopy"
|
|
825
|
-
version = "0.8.
|
|
827
|
+
version = "0.8.39"
|
|
826
828
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
827
|
-
checksum = "
|
|
829
|
+
checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a"
|
|
828
830
|
dependencies = [
|
|
829
831
|
"zerocopy-derive",
|
|
830
832
|
]
|
|
831
833
|
|
|
832
834
|
[[package]]
|
|
833
835
|
name = "zerocopy-derive"
|
|
834
|
-
version = "0.8.
|
|
836
|
+
version = "0.8.39"
|
|
835
837
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
836
|
-
checksum = "
|
|
838
|
+
checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517"
|
|
837
839
|
dependencies = [
|
|
838
840
|
"proc-macro2",
|
|
839
841
|
"quote",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rust-geo-python"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.8"
|
|
4
4
|
authors = ["plooney"]
|
|
5
5
|
edition = "2024"
|
|
6
6
|
readme = "README.md"
|
|
@@ -14,8 +14,10 @@ pyo3 = { version = "0.27.2", features = ["extension-module", "abi3-py37", "gener
|
|
|
14
14
|
ndarray = {version="0.17.2", features = ["rayon"]}
|
|
15
15
|
numpy = "0.27.1"
|
|
16
16
|
geo = { version = "0.32.0" }
|
|
17
|
+
i_overlay = "4.0.7"
|
|
17
18
|
wkt = "0.14.0"
|
|
18
19
|
wkb = "0.9.2"
|
|
20
|
+
num-traits = "0.2.19"
|
|
19
21
|
|
|
20
22
|
[profile.release]
|
|
21
23
|
lto = true
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rust-geo-python
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Author: plooney
|
|
5
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
6
|
+
|
|
7
|
+
# rust-geo-python
|
|
8
|
+
|
|
9
|
+
Fast 2D geometry for Python implemented in Rust. This project exposes `geo`-powered operations (distance, relations, boolean ops, buffering, etc.) to Python via PyO3 and NumPy arrays, with optional robust overlay helpers powered by `i_overlay`.
|
|
10
|
+
|
|
11
|
+
**Status:** early, API may change.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
- Python classes for core shapes: point, line, line string, polygon, multipolygon, rect, triangle, and geometry collections.
|
|
15
|
+
- Geometry operations: distance, containment, intersection/union/difference, buffer, area, validity checks, and relations.
|
|
16
|
+
- Vectorized distance helpers that operate on NumPy arrays.
|
|
17
|
+
- Optional robust overlay utilities for tiling workflows.
|
|
18
|
+
|
|
19
|
+
## Install (from source)
|
|
20
|
+
This repo builds a Python extension with `maturin`.
|
|
21
|
+
|
|
22
|
+
Requirements:
|
|
23
|
+
- Rust toolchain (edition 2024)
|
|
24
|
+
- Python 3.7+ (uses `abi3-py37`)
|
|
25
|
+
- `maturin`
|
|
26
|
+
|
|
27
|
+
Build and install into the current Python environment:
|
|
28
|
+
```bash
|
|
29
|
+
pip install maturin
|
|
30
|
+
maturin develop --release
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Build a wheel:
|
|
34
|
+
```bash
|
|
35
|
+
maturin build --release
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
```python
|
|
40
|
+
import numpy as np
|
|
41
|
+
import rust_geo_python as rg
|
|
42
|
+
|
|
43
|
+
# Points / lines
|
|
44
|
+
p = rg.RustPoint(1.0, 2.0)
|
|
45
|
+
line = rg.RustLine(0.0, 0.0, 3.0, 4.0)
|
|
46
|
+
|
|
47
|
+
# Polygons are defined by an exterior ring and optional interior rings
|
|
48
|
+
outer = np.array([[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0], [0.0, 0.0]])
|
|
49
|
+
hole = np.array([[1.0, 1.0], [2.0, 1.0], [2.0, 2.0], [1.0, 2.0], [1.0, 1.0]])
|
|
50
|
+
poly = rg.RustPolygon(outer, [hole])
|
|
51
|
+
|
|
52
|
+
print(poly.area())
|
|
53
|
+
print(poly.contains(p))
|
|
54
|
+
print(poly.to_wkt())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Vectorized distance helpers:
|
|
58
|
+
```python
|
|
59
|
+
points = np.array([[0.0, 0.0], [5.0, 5.0], [2.0, 3.0]])
|
|
60
|
+
polygon = np.array([[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0], [0.0, 0.0]])
|
|
61
|
+
|
|
62
|
+
dist = rg.points_polygon_distance(points, polygon)
|
|
63
|
+
print(dist)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API overview
|
|
67
|
+
Python module: `rust_geo_python`
|
|
68
|
+
|
|
69
|
+
### Classes
|
|
70
|
+
- `RustShape` (base class)
|
|
71
|
+
- `RustPoint`
|
|
72
|
+
- `RustLine`
|
|
73
|
+
- `RustLineString`
|
|
74
|
+
- `RustMultiPoint`
|
|
75
|
+
- `RustMultiLineString`
|
|
76
|
+
- `RustPolygon`
|
|
77
|
+
- `RustMultiPolygon`
|
|
78
|
+
- `RustTriangle`
|
|
79
|
+
- `RustRect`
|
|
80
|
+
- `RustGeometryCollection`
|
|
81
|
+
- `RustGeomVecCollection`
|
|
82
|
+
- `RustIntersectionMatrix`
|
|
83
|
+
|
|
84
|
+
### Selected methods
|
|
85
|
+
`RustShape` provides:
|
|
86
|
+
- `distance(other)`
|
|
87
|
+
- `unsigned_area()`
|
|
88
|
+
- `hausdorff_distance(other)`
|
|
89
|
+
- `bounding_rect()`
|
|
90
|
+
- `contains(other)`
|
|
91
|
+
- `contains_properly(other)`
|
|
92
|
+
- `intersects(other)`
|
|
93
|
+
- `relate(other)` → `RustIntersectionMatrix`
|
|
94
|
+
- `is_valid()`
|
|
95
|
+
- `to_wkt()`
|
|
96
|
+
- `buffer(radius)`
|
|
97
|
+
- `intersection(other)`
|
|
98
|
+
- `union(other)`
|
|
99
|
+
- `difference(other)`
|
|
100
|
+
- `boundary()`
|
|
101
|
+
|
|
102
|
+
`RustPolygon` / `RustMultiPolygon`:
|
|
103
|
+
- `xy()` (NumPy arrays)
|
|
104
|
+
- `simplify(epsilon)`
|
|
105
|
+
- `area()`
|
|
106
|
+
|
|
107
|
+
`RustRect`:
|
|
108
|
+
- `xy()`
|
|
109
|
+
- `to_polygon()`
|
|
110
|
+
|
|
111
|
+
`RustGeomVecCollection`:
|
|
112
|
+
- `distance(other)` (pairwise distance matrix)
|
|
113
|
+
|
|
114
|
+
`RustGeometryCollection`:
|
|
115
|
+
- `len()`
|
|
116
|
+
|
|
117
|
+
### Functions
|
|
118
|
+
- `point_polygon_distance(point_xy, polygon_xy)`
|
|
119
|
+
- `points_polygon_distance(points_xy, polygon_xy)`
|
|
120
|
+
- `points_polygon_dist_mut(points_xy, polygon_xy)` (parallelized)
|
|
121
|
+
- `polygon_polygon_distance(polygon_xy, polygon_xy)`
|
|
122
|
+
- `from_wkt(wkt_string)`
|
|
123
|
+
- `union(polygons)`
|
|
124
|
+
- `union_with_adapter(polygons, rect)`
|
|
125
|
+
- `intersection(polygon, polygon)`
|
|
126
|
+
- `intersect_tile(multipolygon, tile_polygon, rect)`
|
|
127
|
+
- `point_in_polygon(point, polygon)`
|
|
128
|
+
- `union_set_shapes(...)`
|
|
129
|
+
- `intersection_shapes(...)`
|
|
130
|
+
- `difference_shapes(...)`
|
|
131
|
+
|
|
132
|
+
## Notes
|
|
133
|
+
- Coordinates are `float64`.
|
|
134
|
+
- Polygon rings are expected to be closed (first point == last point).
|
|
135
|
+
- Boolean ops on shapes currently support polygon and multipolygon combinations.
|
|
136
|
+
- `from_wkt` returns the most specific class (e.g., `RustPoint`, `RustPolygon`, `RustGeometryCollection`).
|
|
137
|
+
- `buffer()` is not supported for `RustGeometryCollection`.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
Run tests:
|
|
141
|
+
```bash
|
|
142
|
+
cargo test
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Build the Python extension in dev mode:
|
|
146
|
+
```bash
|
|
147
|
+
maturin develop
|
|
148
|
+
```
|
|
149
|
+
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# rust-geo-python
|
|
2
|
+
|
|
3
|
+
Fast 2D geometry for Python implemented in Rust. This project exposes `geo`-powered operations (distance, relations, boolean ops, buffering, etc.) to Python via PyO3 and NumPy arrays, with optional robust overlay helpers powered by `i_overlay`.
|
|
4
|
+
|
|
5
|
+
**Status:** early, API may change.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
- Python classes for core shapes: point, line, line string, polygon, multipolygon, rect, triangle, and geometry collections.
|
|
9
|
+
- Geometry operations: distance, containment, intersection/union/difference, buffer, area, validity checks, and relations.
|
|
10
|
+
- Vectorized distance helpers that operate on NumPy arrays.
|
|
11
|
+
- Optional robust overlay utilities for tiling workflows.
|
|
12
|
+
|
|
13
|
+
## Install (from source)
|
|
14
|
+
This repo builds a Python extension with `maturin`.
|
|
15
|
+
|
|
16
|
+
Requirements:
|
|
17
|
+
- Rust toolchain (edition 2024)
|
|
18
|
+
- Python 3.7+ (uses `abi3-py37`)
|
|
19
|
+
- `maturin`
|
|
20
|
+
|
|
21
|
+
Build and install into the current Python environment:
|
|
22
|
+
```bash
|
|
23
|
+
pip install maturin
|
|
24
|
+
maturin develop --release
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Build a wheel:
|
|
28
|
+
```bash
|
|
29
|
+
maturin build --release
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
```python
|
|
34
|
+
import numpy as np
|
|
35
|
+
import rust_geo_python as rg
|
|
36
|
+
|
|
37
|
+
# Points / lines
|
|
38
|
+
p = rg.RustPoint(1.0, 2.0)
|
|
39
|
+
line = rg.RustLine(0.0, 0.0, 3.0, 4.0)
|
|
40
|
+
|
|
41
|
+
# Polygons are defined by an exterior ring and optional interior rings
|
|
42
|
+
outer = np.array([[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0], [0.0, 0.0]])
|
|
43
|
+
hole = np.array([[1.0, 1.0], [2.0, 1.0], [2.0, 2.0], [1.0, 2.0], [1.0, 1.0]])
|
|
44
|
+
poly = rg.RustPolygon(outer, [hole])
|
|
45
|
+
|
|
46
|
+
print(poly.area())
|
|
47
|
+
print(poly.contains(p))
|
|
48
|
+
print(poly.to_wkt())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Vectorized distance helpers:
|
|
52
|
+
```python
|
|
53
|
+
points = np.array([[0.0, 0.0], [5.0, 5.0], [2.0, 3.0]])
|
|
54
|
+
polygon = np.array([[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0], [0.0, 0.0]])
|
|
55
|
+
|
|
56
|
+
dist = rg.points_polygon_distance(points, polygon)
|
|
57
|
+
print(dist)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## API overview
|
|
61
|
+
Python module: `rust_geo_python`
|
|
62
|
+
|
|
63
|
+
### Classes
|
|
64
|
+
- `RustShape` (base class)
|
|
65
|
+
- `RustPoint`
|
|
66
|
+
- `RustLine`
|
|
67
|
+
- `RustLineString`
|
|
68
|
+
- `RustMultiPoint`
|
|
69
|
+
- `RustMultiLineString`
|
|
70
|
+
- `RustPolygon`
|
|
71
|
+
- `RustMultiPolygon`
|
|
72
|
+
- `RustTriangle`
|
|
73
|
+
- `RustRect`
|
|
74
|
+
- `RustGeometryCollection`
|
|
75
|
+
- `RustGeomVecCollection`
|
|
76
|
+
- `RustIntersectionMatrix`
|
|
77
|
+
|
|
78
|
+
### Selected methods
|
|
79
|
+
`RustShape` provides:
|
|
80
|
+
- `distance(other)`
|
|
81
|
+
- `unsigned_area()`
|
|
82
|
+
- `hausdorff_distance(other)`
|
|
83
|
+
- `bounding_rect()`
|
|
84
|
+
- `contains(other)`
|
|
85
|
+
- `contains_properly(other)`
|
|
86
|
+
- `intersects(other)`
|
|
87
|
+
- `relate(other)` → `RustIntersectionMatrix`
|
|
88
|
+
- `is_valid()`
|
|
89
|
+
- `to_wkt()`
|
|
90
|
+
- `buffer(radius)`
|
|
91
|
+
- `intersection(other)`
|
|
92
|
+
- `union(other)`
|
|
93
|
+
- `difference(other)`
|
|
94
|
+
- `boundary()`
|
|
95
|
+
|
|
96
|
+
`RustPolygon` / `RustMultiPolygon`:
|
|
97
|
+
- `xy()` (NumPy arrays)
|
|
98
|
+
- `simplify(epsilon)`
|
|
99
|
+
- `area()`
|
|
100
|
+
|
|
101
|
+
`RustRect`:
|
|
102
|
+
- `xy()`
|
|
103
|
+
- `to_polygon()`
|
|
104
|
+
|
|
105
|
+
`RustGeomVecCollection`:
|
|
106
|
+
- `distance(other)` (pairwise distance matrix)
|
|
107
|
+
|
|
108
|
+
`RustGeometryCollection`:
|
|
109
|
+
- `len()`
|
|
110
|
+
|
|
111
|
+
### Functions
|
|
112
|
+
- `point_polygon_distance(point_xy, polygon_xy)`
|
|
113
|
+
- `points_polygon_distance(points_xy, polygon_xy)`
|
|
114
|
+
- `points_polygon_dist_mut(points_xy, polygon_xy)` (parallelized)
|
|
115
|
+
- `polygon_polygon_distance(polygon_xy, polygon_xy)`
|
|
116
|
+
- `from_wkt(wkt_string)`
|
|
117
|
+
- `union(polygons)`
|
|
118
|
+
- `union_with_adapter(polygons, rect)`
|
|
119
|
+
- `intersection(polygon, polygon)`
|
|
120
|
+
- `intersect_tile(multipolygon, tile_polygon, rect)`
|
|
121
|
+
- `point_in_polygon(point, polygon)`
|
|
122
|
+
- `union_set_shapes(...)`
|
|
123
|
+
- `intersection_shapes(...)`
|
|
124
|
+
- `difference_shapes(...)`
|
|
125
|
+
|
|
126
|
+
## Notes
|
|
127
|
+
- Coordinates are `float64`.
|
|
128
|
+
- Polygon rings are expected to be closed (first point == last point).
|
|
129
|
+
- Boolean ops on shapes currently support polygon and multipolygon combinations.
|
|
130
|
+
- `from_wkt` returns the most specific class (e.g., `RustPoint`, `RustPolygon`, `RustGeometryCollection`).
|
|
131
|
+
- `buffer()` is not supported for `RustGeometryCollection`.
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
Run tests:
|
|
135
|
+
```bash
|
|
136
|
+
cargo test
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Build the Python extension in dev mode:
|
|
140
|
+
```bash
|
|
141
|
+
maturin develop
|
|
142
|
+
```
|
|
@@ -3,7 +3,8 @@ use ndarray::{ArrayView1, ArrayView2};
|
|
|
3
3
|
use numpy::ndarray::{Array2, Axis};
|
|
4
4
|
use numpy::{PyArray2, PyReadonlyArray2, PyUntypedArrayMethods};
|
|
5
5
|
|
|
6
|
-
use
|
|
6
|
+
use crate::error::{validate_non_empty, validate_xy_dimensions};
|
|
7
|
+
use pyo3::{Bound, PyResult, Python};
|
|
7
8
|
|
|
8
9
|
pub fn point_poly_distance(x: ArrayView1<f64>, y: ArrayView2<f64>) -> f64 {
|
|
9
10
|
let path = y
|
|
@@ -15,26 +16,27 @@ pub fn point_poly_distance(x: ArrayView1<f64>, y: ArrayView2<f64>) -> f64 {
|
|
|
15
16
|
distance
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
fn array2_to_linestring<'py>(x: &PyReadonlyArray2<'py, f64>) -> LineString {
|
|
19
|
-
|
|
19
|
+
fn array2_to_linestring<'py>(x: &PyReadonlyArray2<'py, f64>) -> PyResult<LineString> {
|
|
20
|
+
validate_xy_dimensions(x.shape())?;
|
|
21
|
+
validate_non_empty(x.shape(), "line string array")?;
|
|
20
22
|
let path = x
|
|
21
23
|
.as_array()
|
|
22
24
|
.axis_iter(Axis(0))
|
|
23
25
|
.map(|y| Point::new(y[0], y[1]))
|
|
24
26
|
.collect::<LineString>();
|
|
25
|
-
path
|
|
27
|
+
Ok(path)
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
pub fn array2_to_polygon<'py>(
|
|
29
31
|
x: &PyReadonlyArray2<'py, f64>,
|
|
30
32
|
ys: &Vec<PyReadonlyArray2<'py, f64>>,
|
|
31
|
-
) -> Polygon {
|
|
32
|
-
let exterior = array2_to_linestring(&x)
|
|
33
|
+
) -> PyResult<Polygon> {
|
|
34
|
+
let exterior = array2_to_linestring(&x)?;
|
|
33
35
|
let interiors = ys
|
|
34
36
|
.iter()
|
|
35
37
|
.map(|y| array2_to_linestring(y))
|
|
36
|
-
.collect::<Vec<LineString
|
|
37
|
-
Polygon::new(exterior, interiors)
|
|
38
|
+
.collect::<PyResult<Vec<LineString>>>()?;
|
|
39
|
+
Ok(Polygon::new(exterior, interiors))
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
fn linestring_to_pyarray2<'py>(py: Python<'py>, ls: &LineString) -> Bound<'py, PyArray2<f64>> {
|