geoagro-smooth 0.1.0__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.
- geoagro_smooth-0.1.0/Cargo.lock +297 -0
- geoagro_smooth-0.1.0/Cargo.toml +14 -0
- geoagro_smooth-0.1.0/LICENSE +21 -0
- geoagro_smooth-0.1.0/PKG-INFO +160 -0
- geoagro_smooth-0.1.0/README.md +139 -0
- geoagro_smooth-0.1.0/core/Cargo.toml +14 -0
- geoagro_smooth-0.1.0/core/README.md +139 -0
- geoagro_smooth-0.1.0/core/src/geom.rs +214 -0
- geoagro_smooth-0.1.0/core/src/lib.rs +145 -0
- geoagro_smooth-0.1.0/core/src/topo.rs +1304 -0
- geoagro_smooth-0.1.0/core/src/wkb.rs +194 -0
- geoagro_smooth-0.1.0/pyproject.toml +32 -0
- geoagro_smooth-0.1.0/python/Cargo.toml +17 -0
- geoagro_smooth-0.1.0/python/LICENSE +21 -0
- geoagro_smooth-0.1.0/python/README.md +139 -0
- geoagro_smooth-0.1.0/python/geoagro_smooth/__init__.py +114 -0
- geoagro_smooth-0.1.0/python/src/lib.rs +50 -0
- geoagro_smooth-0.1.0/python/tests/test_smooth.py +112 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "bumpalo"
|
|
7
|
+
version = "3.20.4"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cfg-if"
|
|
13
|
+
version = "1.0.5"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "futures-core"
|
|
19
|
+
version = "0.3.34"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "futures-task"
|
|
25
|
+
version = "0.3.34"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "futures-util"
|
|
31
|
+
version = "0.3.34"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"futures-core",
|
|
36
|
+
"futures-task",
|
|
37
|
+
"pin-project-lite",
|
|
38
|
+
"slab",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "geoagro-smooth"
|
|
43
|
+
version = "0.1.0"
|
|
44
|
+
|
|
45
|
+
[[package]]
|
|
46
|
+
name = "geoagro-smooth-js"
|
|
47
|
+
version = "0.1.0"
|
|
48
|
+
dependencies = [
|
|
49
|
+
"geoagro-smooth",
|
|
50
|
+
"serde",
|
|
51
|
+
"serde-wasm-bindgen",
|
|
52
|
+
"wasm-bindgen",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "geoagro-smooth-py"
|
|
57
|
+
version = "0.1.0"
|
|
58
|
+
dependencies = [
|
|
59
|
+
"geoagro-smooth",
|
|
60
|
+
"pyo3",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[[package]]
|
|
64
|
+
name = "heck"
|
|
65
|
+
version = "0.5.0"
|
|
66
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
67
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
68
|
+
|
|
69
|
+
[[package]]
|
|
70
|
+
name = "js-sys"
|
|
71
|
+
version = "0.3.107"
|
|
72
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
73
|
+
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
|
|
74
|
+
dependencies = [
|
|
75
|
+
"cfg-if",
|
|
76
|
+
"futures-util",
|
|
77
|
+
"wasm-bindgen",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
[[package]]
|
|
81
|
+
name = "libc"
|
|
82
|
+
version = "0.2.191"
|
|
83
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
84
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
85
|
+
|
|
86
|
+
[[package]]
|
|
87
|
+
name = "once_cell"
|
|
88
|
+
version = "1.21.4"
|
|
89
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
90
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
91
|
+
|
|
92
|
+
[[package]]
|
|
93
|
+
name = "pin-project-lite"
|
|
94
|
+
version = "0.2.19"
|
|
95
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
96
|
+
checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe"
|
|
97
|
+
|
|
98
|
+
[[package]]
|
|
99
|
+
name = "portable-atomic"
|
|
100
|
+
version = "1.15.0"
|
|
101
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
102
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
103
|
+
|
|
104
|
+
[[package]]
|
|
105
|
+
name = "proc-macro2"
|
|
106
|
+
version = "1.0.107"
|
|
107
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
108
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
109
|
+
dependencies = [
|
|
110
|
+
"unicode-ident",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[[package]]
|
|
114
|
+
name = "pyo3"
|
|
115
|
+
version = "0.30.1"
|
|
116
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
+
checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"libc",
|
|
120
|
+
"once_cell",
|
|
121
|
+
"portable-atomic",
|
|
122
|
+
"pyo3-build-config",
|
|
123
|
+
"pyo3-ffi",
|
|
124
|
+
"pyo3-macros",
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
[[package]]
|
|
128
|
+
name = "pyo3-build-config"
|
|
129
|
+
version = "0.30.1"
|
|
130
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
|
+
checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
|
|
132
|
+
dependencies = [
|
|
133
|
+
"target-lexicon",
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
[[package]]
|
|
137
|
+
name = "pyo3-ffi"
|
|
138
|
+
version = "0.30.1"
|
|
139
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
140
|
+
checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
|
|
141
|
+
dependencies = [
|
|
142
|
+
"libc",
|
|
143
|
+
"pyo3-build-config",
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
[[package]]
|
|
147
|
+
name = "pyo3-macros"
|
|
148
|
+
version = "0.30.1"
|
|
149
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
150
|
+
checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
|
|
151
|
+
dependencies = [
|
|
152
|
+
"proc-macro2",
|
|
153
|
+
"pyo3-macros-backend",
|
|
154
|
+
"quote",
|
|
155
|
+
"syn",
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "pyo3-macros-backend"
|
|
160
|
+
version = "0.30.1"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
|
|
163
|
+
dependencies = [
|
|
164
|
+
"heck",
|
|
165
|
+
"proc-macro2",
|
|
166
|
+
"quote",
|
|
167
|
+
"syn",
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
[[package]]
|
|
171
|
+
name = "quote"
|
|
172
|
+
version = "1.0.47"
|
|
173
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
174
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
175
|
+
dependencies = [
|
|
176
|
+
"proc-macro2",
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
[[package]]
|
|
180
|
+
name = "rustversion"
|
|
181
|
+
version = "1.0.23"
|
|
182
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
183
|
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
184
|
+
|
|
185
|
+
[[package]]
|
|
186
|
+
name = "serde"
|
|
187
|
+
version = "1.0.229"
|
|
188
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
189
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
190
|
+
dependencies = [
|
|
191
|
+
"serde_core",
|
|
192
|
+
"serde_derive",
|
|
193
|
+
]
|
|
194
|
+
|
|
195
|
+
[[package]]
|
|
196
|
+
name = "serde-wasm-bindgen"
|
|
197
|
+
version = "0.6.5"
|
|
198
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
199
|
+
checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"
|
|
200
|
+
dependencies = [
|
|
201
|
+
"js-sys",
|
|
202
|
+
"serde",
|
|
203
|
+
"wasm-bindgen",
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
[[package]]
|
|
207
|
+
name = "serde_core"
|
|
208
|
+
version = "1.0.229"
|
|
209
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
210
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
211
|
+
dependencies = [
|
|
212
|
+
"serde_derive",
|
|
213
|
+
]
|
|
214
|
+
|
|
215
|
+
[[package]]
|
|
216
|
+
name = "serde_derive"
|
|
217
|
+
version = "1.0.229"
|
|
218
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
219
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
220
|
+
dependencies = [
|
|
221
|
+
"proc-macro2",
|
|
222
|
+
"quote",
|
|
223
|
+
"syn",
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
[[package]]
|
|
227
|
+
name = "slab"
|
|
228
|
+
version = "0.4.12"
|
|
229
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
230
|
+
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "syn"
|
|
234
|
+
version = "3.0.10"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
237
|
+
dependencies = [
|
|
238
|
+
"proc-macro2",
|
|
239
|
+
"quote",
|
|
240
|
+
"unicode-ident",
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
[[package]]
|
|
244
|
+
name = "target-lexicon"
|
|
245
|
+
version = "0.13.6"
|
|
246
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
247
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
248
|
+
|
|
249
|
+
[[package]]
|
|
250
|
+
name = "unicode-ident"
|
|
251
|
+
version = "1.0.27"
|
|
252
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
253
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
254
|
+
|
|
255
|
+
[[package]]
|
|
256
|
+
name = "wasm-bindgen"
|
|
257
|
+
version = "0.2.130"
|
|
258
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
+
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
|
|
260
|
+
dependencies = [
|
|
261
|
+
"cfg-if",
|
|
262
|
+
"rustversion",
|
|
263
|
+
"wasm-bindgen-macro",
|
|
264
|
+
"wasm-bindgen-shared",
|
|
265
|
+
]
|
|
266
|
+
|
|
267
|
+
[[package]]
|
|
268
|
+
name = "wasm-bindgen-macro"
|
|
269
|
+
version = "0.2.130"
|
|
270
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
271
|
+
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
|
|
272
|
+
dependencies = [
|
|
273
|
+
"quote",
|
|
274
|
+
"wasm-bindgen-macro-support",
|
|
275
|
+
]
|
|
276
|
+
|
|
277
|
+
[[package]]
|
|
278
|
+
name = "wasm-bindgen-macro-support"
|
|
279
|
+
version = "0.2.130"
|
|
280
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
281
|
+
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
|
|
282
|
+
dependencies = [
|
|
283
|
+
"bumpalo",
|
|
284
|
+
"proc-macro2",
|
|
285
|
+
"quote",
|
|
286
|
+
"syn",
|
|
287
|
+
"wasm-bindgen-shared",
|
|
288
|
+
]
|
|
289
|
+
|
|
290
|
+
[[package]]
|
|
291
|
+
name = "wasm-bindgen-shared"
|
|
292
|
+
version = "0.2.130"
|
|
293
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
294
|
+
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
|
|
295
|
+
dependencies = [
|
|
296
|
+
"unicode-ident",
|
|
297
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
members = ["core", "python"]
|
|
3
|
+
resolver = "2"
|
|
4
|
+
|
|
5
|
+
[workspace.package]
|
|
6
|
+
version = "0.1.0"
|
|
7
|
+
edition = "2021"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
repository = "https://github.com/GeoagrobyTEK/geoagro-smooth"
|
|
10
|
+
authors = ["GeoAgro"]
|
|
11
|
+
|
|
12
|
+
[profile.release]
|
|
13
|
+
lto = true
|
|
14
|
+
codegen-units = 1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GeoAgro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geoagro-smooth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
7
|
+
Requires-Dist: shapely>=2.0
|
|
8
|
+
Requires-Dist: geopandas>=0.14 ; extra == 'geopandas'
|
|
9
|
+
Requires-Dist: pytest ; extra == 'test'
|
|
10
|
+
Requires-Dist: geopandas>=0.14 ; extra == 'test'
|
|
11
|
+
Provides-Extra: geopandas
|
|
12
|
+
Provides-Extra: test
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Summary: Topology-preserving smoothing of polygon coverages from classified rasters (WGS84)
|
|
15
|
+
Keywords: gis,smoothing,polygon,topology,raster,geopandas
|
|
16
|
+
License-Expression: MIT
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
19
|
+
Project-URL: Repository, https://github.com/GeoagrobyTEK/geoagro-smooth
|
|
20
|
+
|
|
21
|
+
# geoagro-smooth
|
|
22
|
+
|
|
23
|
+
Topology-preserving smoothing of polygon coverages, such as the polygons you
|
|
24
|
+
get from polygonizing a classified raster (yield maps, NDVI zones,
|
|
25
|
+
prescriptions). One Rust engine with packages for **Python** and
|
|
26
|
+
**JavaScript**.
|
|
27
|
+
|
|
28
|
+
Smoothing each polygon on its own, as tools like
|
|
29
|
+
[Smoothify](https://github.com/DPIRD-DMA/Smoothify) do, works well for a single
|
|
30
|
+
class. With several classes, though, two neighbors rebuild their shared border
|
|
31
|
+
in different ways, which leaves gaps and overlaps between them.
|
|
32
|
+
`geoagro-smooth` smooths every border shared by two polygons **once** and gives
|
|
33
|
+
the same result to both, so the coverage keeps fitting together.
|
|
34
|
+
|
|
35
|
+
- Borders between polygons lose the pixel stairs. The curve runs through the
|
|
36
|
+
middle of the steps, so little area changes class.
|
|
37
|
+
- The outline of the coverage and uncovered holes are left as they are.
|
|
38
|
+
- Nodes, where three or more polygons meet, do not move.
|
|
39
|
+
- The output has no gaps, overlaps or self-intersections. When smoothing an
|
|
40
|
+
edge would break that, the edge is redone with a smaller scale, down to
|
|
41
|
+
leaving it as it was.
|
|
42
|
+
- Inputs with real-world defects are handled:
|
|
43
|
+
- coordinates rounded to ~1 cm;
|
|
44
|
+
- T-junctions, where one side has a vertex the neighbor lacks;
|
|
45
|
+
- dust-sized polygons left by the polygonization.
|
|
46
|
+
|
|
47
|
+
> **Coordinates:** only WGS84 (EPSG:4326, longitude/latitude) is supported for
|
|
48
|
+
> now. Reproject first (`gdf.to_crs(4326)`). Distances are in meters.
|
|
49
|
+
|
|
50
|
+
## Python
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "git+https://github.com/GeoagrobyTEK/geoagro-smooth#subdirectory=python"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Installing from git compiles the engine, so it needs a Rust toolchain. The
|
|
57
|
+
PyPI wheels will not.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import geopandas as gpd
|
|
61
|
+
import geoagro_smooth
|
|
62
|
+
|
|
63
|
+
zones = gpd.read_file("yield_zones.shp").to_crs(4326)
|
|
64
|
+
|
|
65
|
+
smoothed = geoagro_smooth.smooth(zones, scale=10) # GeoDataFrame, same columns
|
|
66
|
+
simple = geoagro_smooth.smooth(zones, scale=2, mode="simplify")
|
|
67
|
+
|
|
68
|
+
result = geoagro_smooth.smooth_with_stats(zones, scale=10)
|
|
69
|
+
print(result.swapped_area_m2 / 10_000, "ha changed class")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`smooth` accepts a GeoDataFrame, a GeoSeries, a sequence of shapely Polygon or
|
|
73
|
+
MultiPolygon (`None` allowed), or a single geometry. It returns a copy of the
|
|
74
|
+
same type.
|
|
75
|
+
|
|
76
|
+
## JavaScript (Node and browsers)
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install geoagro-smooth
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { ready, smooth, smoothWithStats } from "geoagro-smooth";
|
|
84
|
+
|
|
85
|
+
await ready; // loads the WebAssembly engine (immediate in Node)
|
|
86
|
+
const smoothed = smooth(featureCollection, { scale: 10 });
|
|
87
|
+
const { data, swappedAreaM2 } = smoothWithStats(featureCollection, { scale: 10 });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`smooth` accepts a FeatureCollection, a Feature, an array of Features, or
|
|
91
|
+
GeoJSON Polygon or MultiPolygon geometries. It returns a copy with the same
|
|
92
|
+
shape, and properties are kept. TypeScript types are included.
|
|
93
|
+
|
|
94
|
+
## Rust
|
|
95
|
+
|
|
96
|
+
```rust
|
|
97
|
+
use geoagro_smooth::{smooth_coverage, Mode};
|
|
98
|
+
|
|
99
|
+
let out = smooth_coverage(&zones, 10.0, Mode::Smooth)?; // zones: Vec<Vec<Polygon>>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Parameters
|
|
103
|
+
|
|
104
|
+
| | |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `scale` | Meters. In `smooth` mode it is the smoothing scale, and 3 to 5 times the pixel size works well. In `simplify` mode it is the Douglas-Peucker tolerance. `0` returns the input unchanged. |
|
|
107
|
+
| `mode` | `"smooth"` (default) gives curved borders without stairs. `"simplify"` gives fewer vertices and straight borders. |
|
|
108
|
+
|
|
109
|
+
Each input geometry is one *zone*: a class, a feature, or a single polygon.
|
|
110
|
+
Neighbors must share their border vertices, as they do when they come from the
|
|
111
|
+
same raster. The engine also adds the vertex that is missing at a T-junction.
|
|
112
|
+
|
|
113
|
+
## How it works
|
|
114
|
+
|
|
115
|
+
1. **Topology.**
|
|
116
|
+
- Rings are split into *edges* between nodes.
|
|
117
|
+
- An edge used by two different zones is shared; the others (the outline,
|
|
118
|
+
uncovered holes) are left untouched.
|
|
119
|
+
- Vertices within 5 cm of a neighbor's side are inserted into it.
|
|
120
|
+
- Rings under 0.01 m² are dropped.
|
|
121
|
+
2. **Smoothing.** Each shared edge is processed in a local metric projection,
|
|
122
|
+
with its end nodes fixed:
|
|
123
|
+
- it is resampled every `scale / 2`;
|
|
124
|
+
- it is smoothed with Taubin's λ|μ filter (20 passes). This low-pass filter
|
|
125
|
+
does not shrink shapes, unlike Chaikin's or plain Laplacian smoothing;
|
|
126
|
+
- extra vertices are removed with Douglas-Peucker at `scale / 10`.
|
|
127
|
+
3. **Checks.** The result is checked for:
|
|
128
|
+
- crossings between any edges;
|
|
129
|
+
- rings changing area by more than 20%;
|
|
130
|
+
- holes left outside their polygon.
|
|
131
|
+
|
|
132
|
+
Edges with problems get half the scale, and this repeats until nothing
|
|
133
|
+
conflicts.
|
|
134
|
+
4. **Assembly.** Every zone is rebuilt from the same reshaped edges.
|
|
135
|
+
|
|
136
|
+
The *swapped area* is the area between the original and the new borders, which
|
|
137
|
+
is the area that changed zone.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
cargo test -p geoagro-smooth # engine
|
|
143
|
+
|
|
144
|
+
cd python # Python package
|
|
145
|
+
python -m venv .venv && .venv/Scripts/pip install maturin pytest geopandas
|
|
146
|
+
.venv/Scripts/maturin develop --release && .venv/Scripts/python -m pytest
|
|
147
|
+
|
|
148
|
+
cd js # JS package (needs wasm-pack)
|
|
149
|
+
npm run build && npm test
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The real-layer tests are skipped unless you set `GEOAGRO_SMOOTH_FILE` (Python,
|
|
153
|
+
any file GeoPandas reads) or `GEOAGRO_SMOOTH_GEOJSON` (JS). To check the
|
|
154
|
+
browser build, serve `js/` and open `test/browser.html`.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT. The idea of smoothing raster-derived polygons comes from
|
|
159
|
+
[Smoothify](https://github.com/DPIRD-DMA/Smoothify) (MIT).
|
|
160
|
+
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# geoagro-smooth
|
|
2
|
+
|
|
3
|
+
Topology-preserving smoothing of polygon coverages, such as the polygons you
|
|
4
|
+
get from polygonizing a classified raster (yield maps, NDVI zones,
|
|
5
|
+
prescriptions). One Rust engine with packages for **Python** and
|
|
6
|
+
**JavaScript**.
|
|
7
|
+
|
|
8
|
+
Smoothing each polygon on its own, as tools like
|
|
9
|
+
[Smoothify](https://github.com/DPIRD-DMA/Smoothify) do, works well for a single
|
|
10
|
+
class. With several classes, though, two neighbors rebuild their shared border
|
|
11
|
+
in different ways, which leaves gaps and overlaps between them.
|
|
12
|
+
`geoagro-smooth` smooths every border shared by two polygons **once** and gives
|
|
13
|
+
the same result to both, so the coverage keeps fitting together.
|
|
14
|
+
|
|
15
|
+
- Borders between polygons lose the pixel stairs. The curve runs through the
|
|
16
|
+
middle of the steps, so little area changes class.
|
|
17
|
+
- The outline of the coverage and uncovered holes are left as they are.
|
|
18
|
+
- Nodes, where three or more polygons meet, do not move.
|
|
19
|
+
- The output has no gaps, overlaps or self-intersections. When smoothing an
|
|
20
|
+
edge would break that, the edge is redone with a smaller scale, down to
|
|
21
|
+
leaving it as it was.
|
|
22
|
+
- Inputs with real-world defects are handled:
|
|
23
|
+
- coordinates rounded to ~1 cm;
|
|
24
|
+
- T-junctions, where one side has a vertex the neighbor lacks;
|
|
25
|
+
- dust-sized polygons left by the polygonization.
|
|
26
|
+
|
|
27
|
+
> **Coordinates:** only WGS84 (EPSG:4326, longitude/latitude) is supported for
|
|
28
|
+
> now. Reproject first (`gdf.to_crs(4326)`). Distances are in meters.
|
|
29
|
+
|
|
30
|
+
## Python
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install "git+https://github.com/GeoagrobyTEK/geoagro-smooth#subdirectory=python"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Installing from git compiles the engine, so it needs a Rust toolchain. The
|
|
37
|
+
PyPI wheels will not.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import geopandas as gpd
|
|
41
|
+
import geoagro_smooth
|
|
42
|
+
|
|
43
|
+
zones = gpd.read_file("yield_zones.shp").to_crs(4326)
|
|
44
|
+
|
|
45
|
+
smoothed = geoagro_smooth.smooth(zones, scale=10) # GeoDataFrame, same columns
|
|
46
|
+
simple = geoagro_smooth.smooth(zones, scale=2, mode="simplify")
|
|
47
|
+
|
|
48
|
+
result = geoagro_smooth.smooth_with_stats(zones, scale=10)
|
|
49
|
+
print(result.swapped_area_m2 / 10_000, "ha changed class")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`smooth` accepts a GeoDataFrame, a GeoSeries, a sequence of shapely Polygon or
|
|
53
|
+
MultiPolygon (`None` allowed), or a single geometry. It returns a copy of the
|
|
54
|
+
same type.
|
|
55
|
+
|
|
56
|
+
## JavaScript (Node and browsers)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install geoagro-smooth
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { ready, smooth, smoothWithStats } from "geoagro-smooth";
|
|
64
|
+
|
|
65
|
+
await ready; // loads the WebAssembly engine (immediate in Node)
|
|
66
|
+
const smoothed = smooth(featureCollection, { scale: 10 });
|
|
67
|
+
const { data, swappedAreaM2 } = smoothWithStats(featureCollection, { scale: 10 });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`smooth` accepts a FeatureCollection, a Feature, an array of Features, or
|
|
71
|
+
GeoJSON Polygon or MultiPolygon geometries. It returns a copy with the same
|
|
72
|
+
shape, and properties are kept. TypeScript types are included.
|
|
73
|
+
|
|
74
|
+
## Rust
|
|
75
|
+
|
|
76
|
+
```rust
|
|
77
|
+
use geoagro_smooth::{smooth_coverage, Mode};
|
|
78
|
+
|
|
79
|
+
let out = smooth_coverage(&zones, 10.0, Mode::Smooth)?; // zones: Vec<Vec<Polygon>>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Parameters
|
|
83
|
+
|
|
84
|
+
| | |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `scale` | Meters. In `smooth` mode it is the smoothing scale, and 3 to 5 times the pixel size works well. In `simplify` mode it is the Douglas-Peucker tolerance. `0` returns the input unchanged. |
|
|
87
|
+
| `mode` | `"smooth"` (default) gives curved borders without stairs. `"simplify"` gives fewer vertices and straight borders. |
|
|
88
|
+
|
|
89
|
+
Each input geometry is one *zone*: a class, a feature, or a single polygon.
|
|
90
|
+
Neighbors must share their border vertices, as they do when they come from the
|
|
91
|
+
same raster. The engine also adds the vertex that is missing at a T-junction.
|
|
92
|
+
|
|
93
|
+
## How it works
|
|
94
|
+
|
|
95
|
+
1. **Topology.**
|
|
96
|
+
- Rings are split into *edges* between nodes.
|
|
97
|
+
- An edge used by two different zones is shared; the others (the outline,
|
|
98
|
+
uncovered holes) are left untouched.
|
|
99
|
+
- Vertices within 5 cm of a neighbor's side are inserted into it.
|
|
100
|
+
- Rings under 0.01 m² are dropped.
|
|
101
|
+
2. **Smoothing.** Each shared edge is processed in a local metric projection,
|
|
102
|
+
with its end nodes fixed:
|
|
103
|
+
- it is resampled every `scale / 2`;
|
|
104
|
+
- it is smoothed with Taubin's λ|μ filter (20 passes). This low-pass filter
|
|
105
|
+
does not shrink shapes, unlike Chaikin's or plain Laplacian smoothing;
|
|
106
|
+
- extra vertices are removed with Douglas-Peucker at `scale / 10`.
|
|
107
|
+
3. **Checks.** The result is checked for:
|
|
108
|
+
- crossings between any edges;
|
|
109
|
+
- rings changing area by more than 20%;
|
|
110
|
+
- holes left outside their polygon.
|
|
111
|
+
|
|
112
|
+
Edges with problems get half the scale, and this repeats until nothing
|
|
113
|
+
conflicts.
|
|
114
|
+
4. **Assembly.** Every zone is rebuilt from the same reshaped edges.
|
|
115
|
+
|
|
116
|
+
The *swapped area* is the area between the original and the new borders, which
|
|
117
|
+
is the area that changed zone.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
cargo test -p geoagro-smooth # engine
|
|
123
|
+
|
|
124
|
+
cd python # Python package
|
|
125
|
+
python -m venv .venv && .venv/Scripts/pip install maturin pytest geopandas
|
|
126
|
+
.venv/Scripts/maturin develop --release && .venv/Scripts/python -m pytest
|
|
127
|
+
|
|
128
|
+
cd js # JS package (needs wasm-pack)
|
|
129
|
+
npm run build && npm test
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The real-layer tests are skipped unless you set `GEOAGRO_SMOOTH_FILE` (Python,
|
|
133
|
+
any file GeoPandas reads) or `GEOAGRO_SMOOTH_GEOJSON` (JS). To check the
|
|
134
|
+
browser build, serve `js/` and open `test/browser.html`.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT. The idea of smoothing raster-derived polygons comes from
|
|
139
|
+
[Smoothify](https://github.com/DPIRD-DMA/Smoothify) (MIT).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "geoagro-smooth"
|
|
3
|
+
description = "Topology-preserving smoothing of polygon coverages from classified rasters"
|
|
4
|
+
readme = "README.md"
|
|
5
|
+
keywords = ["gis", "smoothing", "polygon", "topology", "raster"]
|
|
6
|
+
categories = ["science::geo", "algorithms"]
|
|
7
|
+
version.workspace = true
|
|
8
|
+
edition.workspace = true
|
|
9
|
+
license.workspace = true
|
|
10
|
+
repository.workspace = true
|
|
11
|
+
authors.workspace = true
|
|
12
|
+
|
|
13
|
+
[lib]
|
|
14
|
+
name = "geoagro_smooth"
|