riverjoin 0.1.11__tar.gz → 0.2.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.
- {riverjoin-0.1.11 → riverjoin-0.2.0}/PKG-INFO +2 -2
- {riverjoin-0.1.11 → riverjoin-0.2.0}/pyproject.toml +2 -2
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/combined_workflow.py +12 -1
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/attribute_transfer.py +2 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/flowlines_buffer.py +1 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/perpendicularlines.py +1 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/setup_hydrofabric.py +42 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/traced_downstream_trace_bifurcation.py +43 -2
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin.egg-info/PKG-INFO +2 -2
- {riverjoin-0.1.11 → riverjoin-0.2.0}/README.md +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/setup.cfg +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/__init__.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/__init__.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/bifurcation_detector.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/compare_linelength.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/interactive_map.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/project_initialization.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/situation_checker.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/traced_downstream.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/utilis.py +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin.egg-info/SOURCES.txt +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin.egg-info/dependency_links.txt +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin.egg-info/requires.txt +0 -0
- {riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin.egg-info/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: riverjoin
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Spatially join two hydrographic datasets (e.g., SWORD, GEOGLOWS, MERIT, GRIT) based on flowlines, and transfer attributes between them.
|
|
5
5
|
Author-email: Supath Dhital <sdhital@ua.edu>, Yixian Chen <ychen223@ua.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/sdmlua/riverjoin_py
|
|
7
7
|
Requires-Python: >=3.10
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "riverjoin"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Spatially join two hydrographic datasets (e.g., SWORD, GEOGLOWS, MERIT, GRIT) based on flowlines, and transfer attributes between them."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Supath Dhital", email = "sdhital@ua.edu" },
|
|
7
7
|
{ name = "Yixian Chen", email = "ychen223@ua.edu" }
|
|
@@ -57,7 +57,9 @@ class run_riverjoin:
|
|
|
57
57
|
unique_id: str,
|
|
58
58
|
unique_id_nextDown: str,
|
|
59
59
|
target_reach_unique_id_field: str,
|
|
60
|
-
|
|
60
|
+
# Downstream-reach field of target_fl (e.g. "rch_id_dn" in SWORD), used by the
|
|
61
|
+
# bifurcation pass. Can be None (default) for targets without one, e.g. GEOGLOWS.
|
|
62
|
+
target_nextdown_field: Optional[str] = None,
|
|
61
63
|
join_fl_reach_width_field: Optional[
|
|
62
64
|
str
|
|
63
65
|
] = None, # Required if run_bifurcation_pass=True
|
|
@@ -80,6 +82,12 @@ class run_riverjoin:
|
|
|
80
82
|
run_bifurcation_pass: bool = True,
|
|
81
83
|
width_preview_hops: int = 3,
|
|
82
84
|
width_ratio_threshold: float = 0.5,
|
|
85
|
+
|
|
86
|
+
# When False (default), the bifurcation pass applies the original
|
|
87
|
+
# skip rule. Set to True to keep every unextracted sibling even if its
|
|
88
|
+
# counterpart was already extracted (skip rule bypassed).
|
|
89
|
+
keep_extracted_siblings: bool = False,
|
|
90
|
+
|
|
83
91
|
identifier: Optional[str] = None,
|
|
84
92
|
):
|
|
85
93
|
self.join_fl = join_fl
|
|
@@ -109,6 +117,7 @@ class run_riverjoin:
|
|
|
109
117
|
self.run_bifurcation_pass = run_bifurcation_pass
|
|
110
118
|
self.width_preview_hops = width_preview_hops
|
|
111
119
|
self.width_ratio_threshold = width_ratio_threshold
|
|
120
|
+
self.keep_extracted_siblings = keep_extracted_siblings
|
|
112
121
|
|
|
113
122
|
self.identifier = identifier
|
|
114
123
|
|
|
@@ -126,6 +135,7 @@ class run_riverjoin:
|
|
|
126
135
|
boundary=self.boundary,
|
|
127
136
|
boundary_layer=self.boundary_layer,
|
|
128
137
|
output_clip_layer=self.output_clip_layer,
|
|
138
|
+
target_nextdown_field=self.target_nextdown_field, # only used to warn if the field is missing
|
|
129
139
|
)
|
|
130
140
|
|
|
131
141
|
# Buffer intersection
|
|
@@ -282,6 +292,7 @@ class run_riverjoin:
|
|
|
282
292
|
join_fl_reach_width_field=self.join_fl_reach_width_field, # can be None if user doesn't want to use width-based pruning, or if the field is not available in the dataset.
|
|
283
293
|
width_preview_hops=self.width_preview_hops,
|
|
284
294
|
width_ratio_threshold=self.width_ratio_threshold,
|
|
295
|
+
keep_extracted_siblings=self.keep_extracted_siblings, # False (default): apply the target-based skip rule; True: keep every unextracted sibling.
|
|
285
296
|
join_fl_layer=self.join_fl_layer,
|
|
286
297
|
identifier=self.identifier,
|
|
287
298
|
# width_preview_hops and width_ratio_threshold will use defaults (3, 0.5)
|
|
@@ -172,6 +172,7 @@ class NodeExtractor:
|
|
|
172
172
|
"""
|
|
173
173
|
minx, miny, maxx, maxy = bounds
|
|
174
174
|
midx, midy = (minx + maxx) / 2.0, (miny + maxy) / 2.0
|
|
175
|
+
midx = ((midx + 180) % 360) - 180 # normalize 0-360 / >180 to -180..180
|
|
175
176
|
zone = int((midx + 180) // 6) + 1
|
|
176
177
|
return 32600 + zone if midy >= 0 else 32700 + zone
|
|
177
178
|
|
|
@@ -532,6 +533,7 @@ class JoinNearestFlowLineAttributes:
|
|
|
532
533
|
def guess_utm_epsg(gdf: gpd.GeoDataFrame) -> int:
|
|
533
534
|
minx, miny, maxx, maxy = gdf.total_bounds
|
|
534
535
|
midx, midy = (minx + maxx) / 2.0, (miny + maxy) / 2.0
|
|
536
|
+
midx = ((midx + 180) % 360) - 180 # normalize 0-360 / >180 to -180..180
|
|
535
537
|
zone = int((midx + 180) // 6) + 1
|
|
536
538
|
return (32600 if midy >= 0 else 32700) + zone
|
|
537
539
|
|
|
@@ -68,6 +68,7 @@ class StreamNetworkExtractor:
|
|
|
68
68
|
if not self.clipped_fl_gdf.crs or not self.clipped_fl_gdf.crs.is_projected:
|
|
69
69
|
minx, miny, maxx, maxy = self.clipped_fl_gdf.total_bounds
|
|
70
70
|
midx, midy = (minx + maxx) / 2, (miny + maxy) / 2
|
|
71
|
+
midx = ((midx + 180) % 360) - 180 # normalize 0-360 / >180 to -180..180
|
|
71
72
|
zone = int((midx + 180) // 6) + 1
|
|
72
73
|
epsg_utm = 32600 + zone if midy >= 0 else 32700 + zone
|
|
73
74
|
self.clipped_fl_gdf = self.clipped_fl_gdf.to_crs(epsg=epsg_utm)
|
|
@@ -70,6 +70,7 @@ class create_nodes:
|
|
|
70
70
|
if orig_crs.is_geographic:
|
|
71
71
|
minx, miny, maxx, maxy = gdf.total_bounds
|
|
72
72
|
midx, midy = (minx + maxx) / 2, (miny + maxy) / 2
|
|
73
|
+
midx = ((midx + 180) % 360) - 180 # normalize 0-360 / >180 to -180..180
|
|
73
74
|
zone = int((midx + 180) // 6) + 1
|
|
74
75
|
epsg_utm = 32600 + zone if midy >= 0 else 32700 + zone
|
|
75
76
|
return gdf.to_crs(epsg=epsg_utm)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import difflib
|
|
2
3
|
import geopandas as gpd
|
|
3
4
|
from typing import Optional
|
|
4
5
|
|
|
@@ -28,6 +29,10 @@ class clip_flowlines:
|
|
|
28
29
|
Layer name inside boundary (if GPKG or GDB).
|
|
29
30
|
output_clip_layer : Optional[str]
|
|
30
31
|
Layer name to use in output clipped file (required for GPKG).
|
|
32
|
+
target_nextdown_field : Optional[str]
|
|
33
|
+
Downstream-reach field of target_fl used by the bifurcation pass
|
|
34
|
+
(e.g. "rch_id_dn" in SWORD). Only checked here: a warning is printed
|
|
35
|
+
if it is set but not a column of target_fl.
|
|
31
36
|
"""
|
|
32
37
|
|
|
33
38
|
def __init__(
|
|
@@ -39,6 +44,7 @@ class clip_flowlines:
|
|
|
39
44
|
boundary: Optional[str] = None,
|
|
40
45
|
boundary_layer: Optional[str] = None,
|
|
41
46
|
output_clip_layer: Optional[str] = None,
|
|
47
|
+
target_nextdown_field: Optional[str] = None,
|
|
42
48
|
):
|
|
43
49
|
self.join_fl = join_fl
|
|
44
50
|
self.target_fl = target_fl
|
|
@@ -49,6 +55,7 @@ class clip_flowlines:
|
|
|
49
55
|
self.output_clip_layer = (
|
|
50
56
|
output_clip_layer if output_clip_layer else "ClippedFlowlines"
|
|
51
57
|
)
|
|
58
|
+
self.target_nextdown_field = target_nextdown_field
|
|
52
59
|
|
|
53
60
|
# get the output_clip path
|
|
54
61
|
self.project_paths = setup_project()
|
|
@@ -69,6 +76,35 @@ class clip_flowlines:
|
|
|
69
76
|
return gpd.read_file(path, layer=layer)
|
|
70
77
|
else:
|
|
71
78
|
raise ValueError(f"Unsupported file format: {ext} for file {path}")
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def _check_lon_convention(join_gdf, target_gdf):
|
|
82
|
+
"""Warn if the two inputs appear to use different longitude conventions."""
|
|
83
|
+
def conv(gdf):
|
|
84
|
+
if gdf.crs is None or not gdf.crs.is_geographic:
|
|
85
|
+
return None
|
|
86
|
+
return "0-360" if gdf.total_bounds[2] > 180 else "-180..180"
|
|
87
|
+
|
|
88
|
+
j, t = conv(join_gdf), conv(target_gdf)
|
|
89
|
+
if j and t and j != t:
|
|
90
|
+
print(
|
|
91
|
+
f"WARNING: longitude convention mismatch — join_fl uses {j}, "
|
|
92
|
+
f"target_fl uses {t}. Near the antimeridian these are 360 apart, "
|
|
93
|
+
f"so the clip and all downstream joins will be wrong. "
|
|
94
|
+
f"Convert both to the same convention before running."
|
|
95
|
+
) # added on 07/16/2026
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def _check_target_nextdown_field(target_gdf, field):
|
|
99
|
+
"""Warn if target_nextdown_field is set but is not a column of target_fl."""
|
|
100
|
+
if not field or field in target_gdf.columns:
|
|
101
|
+
return
|
|
102
|
+
close = difflib.get_close_matches(field, [str(c) for c in target_gdf.columns], n=3)
|
|
103
|
+
hint = f" Did you mean: {', '.join(repr(c) for c in close)}?" if close else ""
|
|
104
|
+
print(
|
|
105
|
+
f"WARNING: target_nextdown_field '{field}' is not a column of target_fl.{hint} "
|
|
106
|
+
f"The bifurcation pass will treat every target reach as NOT bifurcated."
|
|
107
|
+
) # added on 12/05/2026
|
|
72
108
|
|
|
73
109
|
def clip(self) -> gpd.GeoDataFrame:
|
|
74
110
|
"""
|
|
@@ -94,6 +130,12 @@ class clip_flowlines:
|
|
|
94
130
|
# Read target flowlines
|
|
95
131
|
target_gdf = self._read_data(self.target_fl, self.target_fl_layer)
|
|
96
132
|
|
|
133
|
+
# --- Longitude convention check ---
|
|
134
|
+
self._check_lon_convention(join_gdf, target_gdf) # added on 07/16/2026
|
|
135
|
+
|
|
136
|
+
# --- target_nextdown_field check (catches typos before the long run) ---
|
|
137
|
+
self._check_target_nextdown_field(target_gdf, self.target_nextdown_field)
|
|
138
|
+
|
|
97
139
|
# Reproject if needed
|
|
98
140
|
if target_gdf.crs != boundary_gdf.crs:
|
|
99
141
|
target_gdf = target_gdf.to_crs(boundary_gdf.crs)
|
{riverjoin-0.1.11 → riverjoin-0.2.0}/src/riverjoin/modules/traced_downstream_trace_bifurcation.py
RENAMED
|
@@ -18,10 +18,24 @@ class ReconstructDisconnectedBifurcation:
|
|
|
18
18
|
"""
|
|
19
19
|
- Reads the initially extracted network (extract_gdf) and the full join flowline network (join_fl).
|
|
20
20
|
- Finds NextDownIDs (unique_id_nextDown) that do not appear as HydroIDs in the extracted set.
|
|
21
|
-
- Traces
|
|
21
|
+
- Traces downstream from each “disconnected end,” adding any missing reaches until hitting a node that is already in the extracted set or a dead-end.
|
|
22
22
|
- Exports those “missing_reaches” to output_reach_gpkg/missing_reaches_{identifier}.
|
|
23
23
|
- Merges them back into the extracted network, writing the final reconstructed network to output_final_reach_gpkg/output_final_reach_gpkg_{identifier}.
|
|
24
24
|
|
|
25
|
+
target_nextdown_field (default None):
|
|
26
|
+
Downstream-reach field of the target flowlines (e.g. "rch_id_dn" in SWORD),
|
|
27
|
+
used by the skip rule below. None, or a field that is not found, means every
|
|
28
|
+
target reach is treated as not bifurcated (a warning is printed if not found).
|
|
29
|
+
|
|
30
|
+
keep_extracted_siblings (default False):
|
|
31
|
+
Controls the sibling skip rule in find_disconnected_segments().
|
|
32
|
+
- True: keep every unextracted sibling, even when its counterpart was
|
|
33
|
+
already extracted (skip rule bypassed). Combine with
|
|
34
|
+
join_fl_reach_width_field=None to keep all siblings regardless of width.
|
|
35
|
+
- False (default): original behavior — a disconnected end is skipped when the
|
|
36
|
+
parent's target_nextdown_field is not bifurcated (<= 1 token) and a
|
|
37
|
+
sibling is already extracted; genuinely bifurcated parents are kept.
|
|
38
|
+
|
|
25
39
|
Returns:
|
|
26
40
|
Path to the final reconstructed feature class GeoPackage.
|
|
27
41
|
"""
|
|
@@ -31,10 +45,19 @@ class ReconstructDisconnectedBifurcation:
|
|
|
31
45
|
unique_id: str,
|
|
32
46
|
unique_id_nextDown: str,
|
|
33
47
|
join_fl: str,
|
|
34
|
-
|
|
48
|
+
# Downstream-reach field of the target flowlines (e.g. "rch_id_dn" in SWORD).
|
|
49
|
+
# None (default): every target reach is treated as not bifurcated.
|
|
50
|
+
target_nextdown_field: Optional[str] = None,
|
|
35
51
|
join_fl_reach_width_field: Optional[str] = None,
|
|
36
52
|
width_preview_hops: int = 3,
|
|
37
53
|
width_ratio_threshold: float = 0.5,
|
|
54
|
+
# When False (default), the original skip behavior applies: a
|
|
55
|
+
# disconnected end is dropped when the parent's target_nextdown_field
|
|
56
|
+
# is NOT bifurcated (<= 1 token) AND a sibling is already extracted.
|
|
57
|
+
# Set to True to keep every unextracted sibling even if its
|
|
58
|
+
# counterpart was already extracted: the target-based skip rule in
|
|
59
|
+
# find_disconnected_segments() is bypassed entirely.
|
|
60
|
+
keep_extracted_siblings: bool = False,
|
|
38
61
|
join_fl_layer: Optional[str] = None,
|
|
39
62
|
identifier: Optional[str] = None,
|
|
40
63
|
):
|
|
@@ -45,6 +68,7 @@ class ReconstructDisconnectedBifurcation:
|
|
|
45
68
|
self.join_fl_reach_width_field = join_fl_reach_width_field
|
|
46
69
|
self.width_preview_hops = width_preview_hops
|
|
47
70
|
self.width_ratio_threshold = width_ratio_threshold
|
|
71
|
+
self.keep_extracted_siblings = keep_extracted_siblings
|
|
48
72
|
self.join_fl_layer = join_fl_layer
|
|
49
73
|
self.identifier = identifier
|
|
50
74
|
|
|
@@ -205,11 +229,28 @@ class ReconstructDisconnectedBifurcation:
|
|
|
205
229
|
tgt_next_tokens_per_row = self._series_tokens(tgt_next_series)
|
|
206
230
|
else:
|
|
207
231
|
# if field not present, treat as empty
|
|
232
|
+
if self.target_nextdown_field and not self.keep_extracted_siblings:
|
|
233
|
+
print(
|
|
234
|
+
f"WARNING: target_nextdown_field '{self.target_nextdown_field}' not found in "
|
|
235
|
+
f"layer '{self.joined_extracted_layer}'; every target reach is treated as "
|
|
236
|
+
f"NOT bifurcated, so a disconnected end is skipped whenever a sibling "
|
|
237
|
+
f"is already extracted."
|
|
238
|
+
) # added on 12/05/2026
|
|
208
239
|
tgt_next_tokens_per_row = pd.Series(
|
|
209
240
|
[[]] * len(self.extract_gdf), index=self.extract_gdf.index
|
|
210
241
|
)
|
|
211
242
|
|
|
212
243
|
for end in disconnected:
|
|
244
|
+
# If configured to keep every unextracted sibling, bypass the skip
|
|
245
|
+
# rule entirely: a disconnected end is always kept, regardless of
|
|
246
|
+
# whether a sibling was already extracted or whether the parent's
|
|
247
|
+
# target reach is bifurcated. This guarantees sibling branches are
|
|
248
|
+
# never dropped at this stage. (Width-based pruning may still apply
|
|
249
|
+
# later in trace_missing_segments() if a width field is provided.)
|
|
250
|
+
if self.keep_extracted_siblings:
|
|
251
|
+
self.disconnected_ends.append(end)
|
|
252
|
+
continue
|
|
253
|
+
|
|
213
254
|
# locate parent rows where this 'end' is among the row's nextDown tokens
|
|
214
255
|
parent_rows = self.nextdown_tokens_per_row.apply(lambda toks: end in toks)
|
|
215
256
|
if not parent_rows.any():
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: riverjoin
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Spatially join two hydrographic datasets (e.g., SWORD, GEOGLOWS, MERIT, GRIT) based on flowlines, and transfer attributes between them.
|
|
5
5
|
Author-email: Supath Dhital <sdhital@ua.edu>, Yixian Chen <ychen223@ua.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/sdmlua/riverjoin_py
|
|
7
7
|
Requires-Python: >=3.10
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|