terraproof 0.0.0-stage → 0.4.0
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.
- package/LICENSE +21 -0
- package/README.md +356 -2
- package/bin/terraproof.js +4 -0
- package/dist/router/apply.js +147 -0
- package/dist/router/classify.js +111 -0
- package/dist/router/explain.js +9 -0
- package/dist/router/index.js +272 -0
- package/dist/router/resolve.js +239 -0
- package/dist/router/score.js +60 -0
- package/dist/router/types.js +1 -0
- package/dist/router/validate.js +81 -0
- package/instructions/engineering.md +14 -0
- package/instructions/security.md +14 -0
- package/instructions/simplicity.md +13 -0
- package/package.json +65 -4
- package/routing/DOMAIN_ROUTING.md +161 -0
- package/routing/ROUTER_DESIGN.md +173 -0
- package/routing/SKILL_MANIFEST.md +86 -0
- package/routing/checks.json +121 -0
- package/routing/collections.json +47 -0
- package/routing/registry.json +2211 -0
- package/routing/rules.json +64 -0
- package/skills/accuracy-assessment/SKILL.md +213 -0
- package/skills/accuracy-assessment/UPSTREAM.md +7 -0
- package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
- package/skills/accuracy-assessment/skill.json +103 -0
- package/skills/brainstorming/SKILL.md +250 -0
- package/skills/brainstorming/UPSTREAM.md +29 -0
- package/skills/brainstorming/scripts/frame-template.html +213 -0
- package/skills/brainstorming/scripts/helper.js +167 -0
- package/skills/brainstorming/scripts/server.cjs +723 -0
- package/skills/brainstorming/scripts/start-server.sh +209 -0
- package/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/skills/brainstorming/skill.json +73 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +299 -0
- package/skills/crs-and-units/SKILL.md +200 -0
- package/skills/crs-and-units/UPSTREAM.md +7 -0
- package/skills/crs-and-units/skill.json +74 -0
- package/skills/design-postgis-tables/SKILL.md +494 -0
- package/skills/design-postgis-tables/UPSTREAM.md +21 -0
- package/skills/design-postgis-tables/skill.json +90 -0
- package/skills/gdal/SKILL.md +125 -0
- package/skills/gdal/UPSTREAM.md +22 -0
- package/skills/gdal/references/gdal-recipes.md +103 -0
- package/skills/gdal/skill.json +66 -0
- package/skills/geomaster/README.md +105 -0
- package/skills/geomaster/SKILL.md +366 -0
- package/skills/geomaster/UPSTREAM.md +21 -0
- package/skills/geomaster/references/advanced-gis.md +376 -0
- package/skills/geomaster/references/big-data.md +363 -0
- package/skills/geomaster/references/code-examples.md +531 -0
- package/skills/geomaster/references/coordinate-systems.md +364 -0
- package/skills/geomaster/references/core-libraries.md +273 -0
- package/skills/geomaster/references/data-sources.md +330 -0
- package/skills/geomaster/references/gis-software.md +369 -0
- package/skills/geomaster/references/industry-applications.md +420 -0
- package/skills/geomaster/references/machine-learning.md +462 -0
- package/skills/geomaster/references/programming-languages.md +456 -0
- package/skills/geomaster/references/remote-sensing.md +370 -0
- package/skills/geomaster/references/scientific-domains.md +416 -0
- package/skills/geomaster/references/specialized-topics.md +428 -0
- package/skills/geomaster/references/troubleshooting.md +439 -0
- package/skills/geomaster/skill.json +157 -0
- package/skills/geopandas/SKILL.md +250 -0
- package/skills/geopandas/UPSTREAM.md +22 -0
- package/skills/geopandas/references/crs-management.md +231 -0
- package/skills/geopandas/references/data-io.md +323 -0
- package/skills/geopandas/references/data-structures.md +207 -0
- package/skills/geopandas/references/geometric-operations.md +262 -0
- package/skills/geopandas/references/spatial-analysis.md +294 -0
- package/skills/geopandas/references/visualization.md +230 -0
- package/skills/geopandas/scripts/_common.py +605 -0
- package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
- package/skills/geopandas/scripts/export_plan.py +305 -0
- package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
- package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
- package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
- package/skills/geopandas/scripts/vector_inventory.py +140 -0
- package/skills/geopandas/skill.json +116 -0
- package/skills/geoparquet-validation/SKILL.md +125 -0
- package/skills/geoparquet-validation/UPSTREAM.md +24 -0
- package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
- package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
- package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
- package/skills/geoparquet-validation/skill.json +71 -0
- package/skills/geospatial-data-discovery/SKILL.md +49 -0
- package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
- package/skills/geospatial-data-discovery/skill.json +51 -0
- package/skills/geospatial-frontend/SKILL.md +86 -0
- package/skills/geospatial-frontend/UPSTREAM.md +23 -0
- package/skills/geospatial-frontend/references/design-system.md +283 -0
- package/skills/geospatial-frontend/references/user-preferences.md +96 -0
- package/skills/geospatial-frontend/skill.json +87 -0
- package/skills/geozarr/SKILL.md +244 -0
- package/skills/geozarr/UPSTREAM.md +21 -0
- package/skills/geozarr/skill.json +97 -0
- package/skills/networkx/SKILL.md +440 -0
- package/skills/networkx/UPSTREAM.md +22 -0
- package/skills/networkx/references/algorithms.md +384 -0
- package/skills/networkx/references/generators.md +385 -0
- package/skills/networkx/references/graph-basics.md +284 -0
- package/skills/networkx/references/io.md +457 -0
- package/skills/networkx/references/visualization.md +531 -0
- package/skills/networkx/skill.json +93 -0
- package/skills/raster-processing/SKILL.md +222 -0
- package/skills/raster-processing/UPSTREAM.md +7 -0
- package/skills/raster-processing/skill.json +81 -0
- package/skills/sar-basics/SKILL.md +202 -0
- package/skills/sar-basics/UPSTREAM.md +7 -0
- package/skills/sar-basics/references/calibration-lut.md +98 -0
- package/skills/sar-basics/skill.json +97 -0
- package/skills/satellite-preprocessing/SKILL.md +241 -0
- package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
- package/skills/satellite-preprocessing/skill.json +84 -0
- package/skills/scientific-visualization/SKILL.md +285 -0
- package/skills/scientific-visualization/UPSTREAM.md +25 -0
- package/skills/scientific-visualization/assets/color_palettes.py +263 -0
- package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
- package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
- package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
- package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
- package/skills/scientific-visualization/references/color_palettes.md +227 -0
- package/skills/scientific-visualization/references/journal_requirements.md +169 -0
- package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
- package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
- package/skills/scientific-visualization/references/sources.md +76 -0
- package/skills/scientific-visualization/scripts/_common.py +136 -0
- package/skills/scientific-visualization/scripts/export_plan.py +493 -0
- package/skills/scientific-visualization/scripts/figure_export.py +642 -0
- package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
- package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
- package/skills/scientific-visualization/scripts/style_presets.py +501 -0
- package/skills/scientific-visualization/scripts/style_preview.py +232 -0
- package/skills/scientific-visualization/skill.json +95 -0
- package/skills/spectral-indices/SKILL.md +235 -0
- package/skills/spectral-indices/UPSTREAM.md +7 -0
- package/skills/spectral-indices/skill.json +88 -0
- package/skills/stac-and-cloud-access/SKILL.md +209 -0
- package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
- package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
- package/skills/stac-and-cloud-access/skill.json +98 -0
- package/skills/statistical-analysis/SKILL.md +446 -0
- package/skills/statistical-analysis/UPSTREAM.md +24 -0
- package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
- package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
- package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
- package/skills/statistical-analysis/references/reporting_standards.md +482 -0
- package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
- package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
- package/skills/statistical-analysis/skill.json +127 -0
- package/skills/systematic-debugging/SKILL.md +283 -0
- package/skills/systematic-debugging/UPSTREAM.md +28 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +72 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/skill.json +88 -0
- package/skills/time-series-and-change/SKILL.md +217 -0
- package/skills/time-series-and-change/UPSTREAM.md +7 -0
- package/skills/time-series-and-change/references/change-methods.md +42 -0
- package/skills/time-series-and-change/skill.json +116 -0
- package/skills/vector-quality/SKILL.md +204 -0
- package/skills/vector-quality/UPSTREAM.md +7 -0
- package/skills/vector-quality/skill.json +82 -0
- package/skills/verification/SKILL.md +120 -0
- package/skills/verification/UPSTREAM.md +31 -0
- package/skills/verification/skill.json +67 -0
- package/skills/writing-plans/SKILL.md +171 -0
- package/skills/writing-plans/UPSTREAM.md +23 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/skills/writing-plans/skill.json +80 -0
- package/sources/SOURCES.md +374 -0
- package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
- package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
- package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
- package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
- package/third_party/superpowers/LICENSE +21 -0
- package/third_party/superpowers/NOTICE.md +17 -0
- package/third_party/timescale-pg-aiguide/LICENSE +176 -0
- package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Run a bounded local spatial join and emit only aggregate cardinality."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from _common import (
|
|
12
|
+
ABSOLUTE_MAX_FEATURES,
|
|
13
|
+
DEFAULT_MAX_FEATURES,
|
|
14
|
+
DEFAULT_MAX_INPUT_BYTES,
|
|
15
|
+
CliError,
|
|
16
|
+
bounded_limit,
|
|
17
|
+
checked_input_file,
|
|
18
|
+
crs_summary,
|
|
19
|
+
duplicate_column_state,
|
|
20
|
+
emit_json,
|
|
21
|
+
fail_json,
|
|
22
|
+
finite_number,
|
|
23
|
+
geometry_state,
|
|
24
|
+
load_geodataframe,
|
|
25
|
+
native_versions,
|
|
26
|
+
package_versions,
|
|
27
|
+
positive_int,
|
|
28
|
+
sha256_file,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
TOOL = "spatial_join_audit"
|
|
32
|
+
DEFAULT_MAX_PAIRS = 1_000_000
|
|
33
|
+
ABSOLUTE_MAX_PAIRS = 10_000_000
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
37
|
+
parser = argparse.ArgumentParser(
|
|
38
|
+
description=(
|
|
39
|
+
"Audit a bounded local binary-predicate or nearest spatial join. "
|
|
40
|
+
"Only aggregate multiplicity is emitted; no pairs, IDs, or coordinates."
|
|
41
|
+
),
|
|
42
|
+
epilog=(
|
|
43
|
+
"Both inputs must be local allowlisted files under --root. Invalid or "
|
|
44
|
+
"CRS-incompatible inputs block execution. All operations are planar."
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument("left", help="Local left vector file")
|
|
48
|
+
parser.add_argument("right", help="Local right vector file")
|
|
49
|
+
parser.add_argument("--root", default=".", help="Existing local I/O root")
|
|
50
|
+
parser.add_argument("--left-layer", help="Exact left layer name")
|
|
51
|
+
parser.add_argument("--right-layer", help="Exact right layer name")
|
|
52
|
+
parser.add_argument("--left-id", help="Optional left stable ID column to audit")
|
|
53
|
+
parser.add_argument("--right-id", help="Optional right stable ID column to audit")
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
"--mode",
|
|
56
|
+
choices=("predicate", "nearest"),
|
|
57
|
+
default="predicate",
|
|
58
|
+
help="Join mode (default: predicate)",
|
|
59
|
+
)
|
|
60
|
+
parser.add_argument(
|
|
61
|
+
"--predicate",
|
|
62
|
+
default="intersects",
|
|
63
|
+
help="Spatial-index predicate for predicate mode (default: intersects)",
|
|
64
|
+
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--distance",
|
|
67
|
+
help="Positive CRS-unit scalar required for predicate=dwithin",
|
|
68
|
+
)
|
|
69
|
+
parser.add_argument(
|
|
70
|
+
"--max-distance",
|
|
71
|
+
help="Optional positive CRS-unit search limit for nearest mode",
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--exclusive",
|
|
75
|
+
action="store_true",
|
|
76
|
+
help="Nearest mode: exclude geometrically equal candidates",
|
|
77
|
+
)
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"--on-attribute",
|
|
80
|
+
action="append",
|
|
81
|
+
default=[],
|
|
82
|
+
help="Additional equality column present on both sides; repeat as needed",
|
|
83
|
+
)
|
|
84
|
+
parser.add_argument(
|
|
85
|
+
"--max-input-bytes",
|
|
86
|
+
type=positive_int,
|
|
87
|
+
default=DEFAULT_MAX_INPUT_BYTES,
|
|
88
|
+
help="Maximum bytes for each primary input file",
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"--max-features",
|
|
92
|
+
type=positive_int,
|
|
93
|
+
default=DEFAULT_MAX_FEATURES,
|
|
94
|
+
help=f"Maximum features per input (default: {DEFAULT_MAX_FEATURES})",
|
|
95
|
+
)
|
|
96
|
+
parser.add_argument(
|
|
97
|
+
"--max-pairs",
|
|
98
|
+
type=positive_int,
|
|
99
|
+
default=DEFAULT_MAX_PAIRS,
|
|
100
|
+
help=f"Maximum joined pairs before failing closed (default: {DEFAULT_MAX_PAIRS})",
|
|
101
|
+
)
|
|
102
|
+
return parser
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _work_frame(frame: Any, row_column: str, attributes: list[str]) -> Any:
|
|
106
|
+
active = frame.geometry.name
|
|
107
|
+
columns = [active, *attributes]
|
|
108
|
+
work = frame.loc[:, columns].copy()
|
|
109
|
+
if active != "_audit_geometry":
|
|
110
|
+
work = work.rename_geometry("_audit_geometry")
|
|
111
|
+
work[row_column] = range(len(work))
|
|
112
|
+
return work
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _counter_summary(counter: Counter[int], total_features: int) -> dict[str, int]:
|
|
116
|
+
matched = len(counter)
|
|
117
|
+
return {
|
|
118
|
+
"matched_features": matched,
|
|
119
|
+
"unmatched_features": total_features - matched,
|
|
120
|
+
"features_with_one_match": sum(count == 1 for count in counter.values()),
|
|
121
|
+
"features_with_multiple_matches": sum(
|
|
122
|
+
count > 1 for count in counter.values()
|
|
123
|
+
),
|
|
124
|
+
"maximum_matches_for_one_feature": max(counter.values(), default=0),
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _run_chunked_join(
|
|
129
|
+
left: Any,
|
|
130
|
+
right: Any,
|
|
131
|
+
*,
|
|
132
|
+
mode: str,
|
|
133
|
+
predicate: str,
|
|
134
|
+
distance: float | None,
|
|
135
|
+
max_distance: float | None,
|
|
136
|
+
exclusive: bool,
|
|
137
|
+
attributes: list[str],
|
|
138
|
+
max_pairs: int,
|
|
139
|
+
) -> dict[str, Any]:
|
|
140
|
+
try:
|
|
141
|
+
import geopandas as gpd
|
|
142
|
+
except ImportError as exc:
|
|
143
|
+
raise CliError("GeoPandas is required for join analysis") from exc
|
|
144
|
+
|
|
145
|
+
left_work = _work_frame(left, "_audit_left_row", attributes)
|
|
146
|
+
right_work = _work_frame(right, "_audit_right_row", attributes)
|
|
147
|
+
if len(right_work) > max_pairs:
|
|
148
|
+
raise CliError(
|
|
149
|
+
"right feature count exceeds max_pairs; one left feature could match all"
|
|
150
|
+
)
|
|
151
|
+
left_counts: Counter[int] = Counter()
|
|
152
|
+
right_counts: Counter[int] = Counter()
|
|
153
|
+
pair_count = 0
|
|
154
|
+
right_size = max(len(right_work), 1)
|
|
155
|
+
chunk_size = max(1, min(512, max_pairs // right_size or 1))
|
|
156
|
+
|
|
157
|
+
for start in range(0, len(left_work), chunk_size):
|
|
158
|
+
chunk = left_work.iloc[start : start + chunk_size]
|
|
159
|
+
if mode == "nearest":
|
|
160
|
+
joined = gpd.sjoin_nearest(
|
|
161
|
+
chunk,
|
|
162
|
+
right_work,
|
|
163
|
+
how="inner",
|
|
164
|
+
max_distance=max_distance,
|
|
165
|
+
exclusive=exclusive,
|
|
166
|
+
)
|
|
167
|
+
else:
|
|
168
|
+
joined = gpd.sjoin(
|
|
169
|
+
chunk,
|
|
170
|
+
right_work,
|
|
171
|
+
how="inner",
|
|
172
|
+
predicate=predicate,
|
|
173
|
+
distance=distance,
|
|
174
|
+
on_attribute=attributes or None,
|
|
175
|
+
)
|
|
176
|
+
pair_count += len(joined)
|
|
177
|
+
if pair_count > max_pairs:
|
|
178
|
+
raise CliError(
|
|
179
|
+
f"joined pair count exceeds the configured {max_pairs}-pair limit"
|
|
180
|
+
)
|
|
181
|
+
left_counts.update(int(value) for value in joined["_audit_left_row"])
|
|
182
|
+
right_counts.update(int(value) for value in joined["_audit_right_row"])
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
"pair_count": pair_count,
|
|
186
|
+
"left": _counter_summary(left_counts, len(left)),
|
|
187
|
+
"right": _counter_summary(right_counts, len(right)),
|
|
188
|
+
"many_to_many_observed": bool(
|
|
189
|
+
any(count > 1 for count in left_counts.values())
|
|
190
|
+
and any(count > 1 for count in right_counts.values())
|
|
191
|
+
),
|
|
192
|
+
"pairs_emitted": False,
|
|
193
|
+
"chunked": True,
|
|
194
|
+
"chunk_size": chunk_size,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def audit(args: argparse.Namespace) -> dict[str, Any]:
|
|
199
|
+
max_features = bounded_limit(
|
|
200
|
+
args.max_features,
|
|
201
|
+
name="max_features",
|
|
202
|
+
maximum=ABSOLUTE_MAX_FEATURES,
|
|
203
|
+
)
|
|
204
|
+
max_pairs = bounded_limit(
|
|
205
|
+
args.max_pairs,
|
|
206
|
+
name="max_pairs",
|
|
207
|
+
maximum=ABSOLUTE_MAX_PAIRS,
|
|
208
|
+
)
|
|
209
|
+
left_path = checked_input_file(
|
|
210
|
+
args.left,
|
|
211
|
+
root=args.root,
|
|
212
|
+
max_bytes=args.max_input_bytes,
|
|
213
|
+
)
|
|
214
|
+
right_path = checked_input_file(
|
|
215
|
+
args.right,
|
|
216
|
+
root=args.root,
|
|
217
|
+
max_bytes=args.max_input_bytes,
|
|
218
|
+
)
|
|
219
|
+
if left_path == right_path and args.left_layer == args.right_layer:
|
|
220
|
+
raise CliError("left and right inputs resolve to the same layer")
|
|
221
|
+
|
|
222
|
+
left = load_geodataframe(
|
|
223
|
+
left_path,
|
|
224
|
+
layer=args.left_layer,
|
|
225
|
+
max_features=max_features,
|
|
226
|
+
)
|
|
227
|
+
right = load_geodataframe(
|
|
228
|
+
right_path,
|
|
229
|
+
layer=args.right_layer,
|
|
230
|
+
max_features=max_features,
|
|
231
|
+
)
|
|
232
|
+
left_state = geometry_state(left)
|
|
233
|
+
right_state = geometry_state(right)
|
|
234
|
+
left_id = duplicate_column_state(left, args.left_id)
|
|
235
|
+
right_id = duplicate_column_state(right, args.right_id)
|
|
236
|
+
|
|
237
|
+
try:
|
|
238
|
+
from pyproj import CRS
|
|
239
|
+
except ImportError as exc:
|
|
240
|
+
raise CliError("pyproj is required for CRS comparison") from exc
|
|
241
|
+
blockers: list[str] = []
|
|
242
|
+
same_crs = False
|
|
243
|
+
if left.crs is None or right.crs is None:
|
|
244
|
+
blockers.append("both inputs require explicit CRS metadata")
|
|
245
|
+
else:
|
|
246
|
+
same_crs = CRS.from_user_input(left.crs).equals(CRS.from_user_input(right.crs))
|
|
247
|
+
if not same_crs:
|
|
248
|
+
blockers.append("input CRS values are not equivalent")
|
|
249
|
+
if left_state["invalid"] or right_state["invalid"]:
|
|
250
|
+
blockers.append("invalid input geometries require separate repair review")
|
|
251
|
+
for attribute in args.on_attribute:
|
|
252
|
+
if attribute not in left.columns or attribute not in right.columns:
|
|
253
|
+
blockers.append("an on_attribute column is absent from one input")
|
|
254
|
+
break
|
|
255
|
+
|
|
256
|
+
distance: float | None = None
|
|
257
|
+
max_distance: float | None = None
|
|
258
|
+
if args.mode == "predicate":
|
|
259
|
+
if args.exclusive or args.max_distance is not None:
|
|
260
|
+
blockers.append("--exclusive/--max-distance apply only to nearest mode")
|
|
261
|
+
if args.predicate == "dwithin":
|
|
262
|
+
if args.distance is None:
|
|
263
|
+
blockers.append("predicate dwithin requires --distance")
|
|
264
|
+
else:
|
|
265
|
+
distance = finite_number(args.distance, name="distance")
|
|
266
|
+
if distance <= 0:
|
|
267
|
+
blockers.append("distance must be greater than zero")
|
|
268
|
+
elif args.distance is not None:
|
|
269
|
+
blockers.append("--distance is valid only for predicate dwithin")
|
|
270
|
+
if not blockers:
|
|
271
|
+
valid = set(left.sindex.valid_query_predicates) & set(
|
|
272
|
+
right.sindex.valid_query_predicates
|
|
273
|
+
)
|
|
274
|
+
if args.predicate not in valid:
|
|
275
|
+
blockers.append("predicate is not supported by both spatial indexes")
|
|
276
|
+
else:
|
|
277
|
+
if args.distance is not None or args.on_attribute:
|
|
278
|
+
blockers.append("--distance/--on-attribute apply only to predicate mode")
|
|
279
|
+
if args.max_distance is not None:
|
|
280
|
+
max_distance = finite_number(args.max_distance, name="max_distance")
|
|
281
|
+
if max_distance <= 0:
|
|
282
|
+
blockers.append("max_distance must be greater than zero")
|
|
283
|
+
|
|
284
|
+
geographic = bool(left.crs is not None and left.crs.is_geographic)
|
|
285
|
+
if args.mode == "nearest" and geographic:
|
|
286
|
+
blockers.append("nearest joins are inaccurate in a geographic CRS")
|
|
287
|
+
if args.predicate == "dwithin" and geographic:
|
|
288
|
+
blockers.append("dwithin distance is angular in a geographic CRS")
|
|
289
|
+
|
|
290
|
+
pair_audit = None
|
|
291
|
+
if not blockers:
|
|
292
|
+
pair_audit = _run_chunked_join(
|
|
293
|
+
left,
|
|
294
|
+
right,
|
|
295
|
+
mode=args.mode,
|
|
296
|
+
predicate=args.predicate,
|
|
297
|
+
distance=distance,
|
|
298
|
+
max_distance=max_distance,
|
|
299
|
+
exclusive=args.exclusive,
|
|
300
|
+
attributes=args.on_attribute,
|
|
301
|
+
max_pairs=max_pairs,
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
warnings = [
|
|
305
|
+
"intersects includes boundary contact; contains/within and covers/covered_by differ at boundaries.",
|
|
306
|
+
"All GeoPandas joins are planar and ignore Z.",
|
|
307
|
+
"Declare expected cardinality separately and compare it with this aggregate audit.",
|
|
308
|
+
]
|
|
309
|
+
if args.mode == "nearest":
|
|
310
|
+
warnings.append(
|
|
311
|
+
"Nearest returns every equidistant match and has no k parameter."
|
|
312
|
+
)
|
|
313
|
+
if left_state["missing"] or left_state["empty"]:
|
|
314
|
+
warnings.append("Missing/empty left geometries remain unmatched.")
|
|
315
|
+
if right_state["missing"] or right_state["empty"]:
|
|
316
|
+
warnings.append("Missing/empty right geometries remain unmatched.")
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
"ok": not blockers,
|
|
320
|
+
"tool": TOOL,
|
|
321
|
+
"mode": args.mode,
|
|
322
|
+
"predicate": args.predicate if args.mode == "predicate" else None,
|
|
323
|
+
"distance_provided": distance is not None,
|
|
324
|
+
"max_distance_provided": max_distance is not None,
|
|
325
|
+
"exclusive": bool(args.exclusive),
|
|
326
|
+
"on_attribute_column_count": len(args.on_attribute),
|
|
327
|
+
"crs": {
|
|
328
|
+
"left": crs_summary(left.crs),
|
|
329
|
+
"right": crs_summary(right.crs),
|
|
330
|
+
"equivalent": same_crs,
|
|
331
|
+
},
|
|
332
|
+
"left": {
|
|
333
|
+
"source_sha256": sha256_file(left_path),
|
|
334
|
+
"geometry_state": left_state,
|
|
335
|
+
"stable_id_audit": left_id,
|
|
336
|
+
},
|
|
337
|
+
"right": {
|
|
338
|
+
"source_sha256": sha256_file(right_path),
|
|
339
|
+
"geometry_state": right_state,
|
|
340
|
+
"stable_id_audit": right_id,
|
|
341
|
+
},
|
|
342
|
+
"pair_audit": pair_audit,
|
|
343
|
+
"blockers": blockers,
|
|
344
|
+
"resource_limits": {
|
|
345
|
+
"max_input_bytes_each": args.max_input_bytes,
|
|
346
|
+
"max_features_each": max_features,
|
|
347
|
+
"max_pairs": max_pairs,
|
|
348
|
+
},
|
|
349
|
+
"network_accessed": False,
|
|
350
|
+
"coordinates_emitted": False,
|
|
351
|
+
"identifiers_emitted": False,
|
|
352
|
+
"stack": {"packages": package_versions(), "native": native_versions()},
|
|
353
|
+
"warnings": warnings,
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def main(argv: list[str] | None = None) -> int:
|
|
358
|
+
args = build_parser().parse_args(argv)
|
|
359
|
+
try:
|
|
360
|
+
report = audit(args)
|
|
361
|
+
emit_json(report)
|
|
362
|
+
return 0 if report["ok"] else 2
|
|
363
|
+
except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
|
|
364
|
+
return fail_json(TOOL, exc)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
if __name__ == "__main__":
|
|
368
|
+
sys.exit(main())
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Create a redacted, metadata-only inventory of one local vector dataset."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import hashlib
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from _common import (
|
|
11
|
+
ABSOLUTE_MAX_FEATURES,
|
|
12
|
+
DEFAULT_MAX_FEATURES,
|
|
13
|
+
DEFAULT_MAX_INPUT_BYTES,
|
|
14
|
+
PINNED_STACK,
|
|
15
|
+
bounded_limit,
|
|
16
|
+
checked_input_file,
|
|
17
|
+
emit_json,
|
|
18
|
+
fail_json,
|
|
19
|
+
inspect_local_vector,
|
|
20
|
+
native_versions,
|
|
21
|
+
package_versions,
|
|
22
|
+
positive_int,
|
|
23
|
+
sha256_file,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
TOOL = "vector_inventory"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
30
|
+
parser = argparse.ArgumentParser(
|
|
31
|
+
description=(
|
|
32
|
+
"Inventory one allowlisted local vector file without loading feature "
|
|
33
|
+
"coordinates or emitting paths, layer names, fields, IDs, or bounds."
|
|
34
|
+
),
|
|
35
|
+
epilog=(
|
|
36
|
+
"URLs, GDAL VSI paths, archives, compression, symlinks, traversal, "
|
|
37
|
+
"and non-allowlisted extensions are rejected. Native GDAL/GEOS/PROJ "
|
|
38
|
+
"parsers remain a trust boundary; inspect only vetted local files."
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument("input", help="Local vector or GeoParquet file")
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--root",
|
|
44
|
+
default=".",
|
|
45
|
+
help="Existing local root that must contain the input (default: .)",
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--layer",
|
|
49
|
+
help="Exact local layer name; required for multi-layer GDAL datasets",
|
|
50
|
+
)
|
|
51
|
+
parser.add_argument(
|
|
52
|
+
"--max-input-bytes",
|
|
53
|
+
type=positive_int,
|
|
54
|
+
default=DEFAULT_MAX_INPUT_BYTES,
|
|
55
|
+
help=f"Maximum primary-file bytes (default: {DEFAULT_MAX_INPUT_BYTES})",
|
|
56
|
+
)
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"--max-features",
|
|
59
|
+
type=positive_int,
|
|
60
|
+
default=DEFAULT_MAX_FEATURES,
|
|
61
|
+
help=(
|
|
62
|
+
"Downstream feature-load threshold to compare with declared count "
|
|
63
|
+
f"(default: {DEFAULT_MAX_FEATURES}; no features are loaded)"
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
return parser
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def inventory(args: argparse.Namespace) -> dict:
|
|
70
|
+
max_features = bounded_limit(
|
|
71
|
+
args.max_features,
|
|
72
|
+
name="max_features",
|
|
73
|
+
maximum=ABSOLUTE_MAX_FEATURES,
|
|
74
|
+
)
|
|
75
|
+
path = checked_input_file(
|
|
76
|
+
args.input,
|
|
77
|
+
root=args.root,
|
|
78
|
+
max_bytes=args.max_input_bytes,
|
|
79
|
+
)
|
|
80
|
+
technical = inspect_local_vector(path, layer=args.layer)
|
|
81
|
+
installed = package_versions()
|
|
82
|
+
declared = technical.get("declared_features")
|
|
83
|
+
warnings = [
|
|
84
|
+
"No feature values, coordinates, bounds, paths, layer names, or field names were emitted.",
|
|
85
|
+
"GDAL/GEOS/PROJ and binary wheels are native-code trust boundaries.",
|
|
86
|
+
"Driver metadata is not proof that every feature or field will parse safely.",
|
|
87
|
+
]
|
|
88
|
+
if path.suffix.casefold() == ".shp":
|
|
89
|
+
warnings.append(
|
|
90
|
+
"The hash covers only the .shp primary file, not required sidecars."
|
|
91
|
+
)
|
|
92
|
+
if declared is None:
|
|
93
|
+
warnings.append(
|
|
94
|
+
"The driver did not provide a cheap feature count; downstream reads must enforce limit+1."
|
|
95
|
+
)
|
|
96
|
+
return {
|
|
97
|
+
"ok": True,
|
|
98
|
+
"tool": TOOL,
|
|
99
|
+
"source": {
|
|
100
|
+
"basename_sha256": hashlib.sha256(path.name.encode("utf-8")).hexdigest(),
|
|
101
|
+
"suffix": path.suffix.casefold(),
|
|
102
|
+
"primary_file_bytes": path.stat().st_size,
|
|
103
|
+
"primary_file_sha256": sha256_file(path),
|
|
104
|
+
"path_emitted": False,
|
|
105
|
+
},
|
|
106
|
+
"technical_inventory": technical,
|
|
107
|
+
"resource_limits": {
|
|
108
|
+
"max_input_bytes": args.max_input_bytes,
|
|
109
|
+
"max_features_for_downstream_load": max_features,
|
|
110
|
+
"declared_within_feature_limit": (
|
|
111
|
+
None if declared is None else declared <= max_features
|
|
112
|
+
),
|
|
113
|
+
"feature_data_loaded": False,
|
|
114
|
+
},
|
|
115
|
+
"stack": {
|
|
116
|
+
"packages": installed,
|
|
117
|
+
"native": native_versions(),
|
|
118
|
+
"matches_pinned_snapshot": {
|
|
119
|
+
name: installed.get(name) == expected
|
|
120
|
+
for name, expected in PINNED_STACK.items()
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
"network_accessed": False,
|
|
124
|
+
"coordinates_emitted": False,
|
|
125
|
+
"identifiers_emitted": False,
|
|
126
|
+
"warnings": warnings,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def main(argv: list[str] | None = None) -> int:
|
|
131
|
+
args = build_parser().parse_args(argv)
|
|
132
|
+
try:
|
|
133
|
+
emit_json(inventory(args))
|
|
134
|
+
return 0
|
|
135
|
+
except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
|
|
136
|
+
return fail_json(TOOL, exc)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
sys.exit(main())
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "geopandas",
|
|
3
|
+
"layer": "domain",
|
|
4
|
+
"domains": [
|
|
5
|
+
"geospatial",
|
|
6
|
+
"data"
|
|
7
|
+
],
|
|
8
|
+
"capabilities": [
|
|
9
|
+
"vector-analysis",
|
|
10
|
+
"spatial-join",
|
|
11
|
+
"geometry-overlay",
|
|
12
|
+
"geodataframe",
|
|
13
|
+
"buffer"
|
|
14
|
+
],
|
|
15
|
+
"triggers": [
|
|
16
|
+
"geopandas",
|
|
17
|
+
"geodataframe",
|
|
18
|
+
"shapefile",
|
|
19
|
+
"geojson",
|
|
20
|
+
"geopackage",
|
|
21
|
+
"spatial join",
|
|
22
|
+
"buffer",
|
|
23
|
+
"polygon intersection",
|
|
24
|
+
"vector spatial"
|
|
25
|
+
],
|
|
26
|
+
"recommended": [
|
|
27
|
+
"verification"
|
|
28
|
+
],
|
|
29
|
+
"requires": [],
|
|
30
|
+
"conflicts": [],
|
|
31
|
+
"explanation": "Processes vector spatial data, spatial joins, overlays, and coordinate transforms.",
|
|
32
|
+
"sections": [
|
|
33
|
+
{
|
|
34
|
+
"id": "reproducible-environment",
|
|
35
|
+
"title": "Reproducible environment",
|
|
36
|
+
"source": "SKILL.md#reproducible-environment"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "safety-and-privacy-contract",
|
|
40
|
+
"title": "Safety and privacy contract",
|
|
41
|
+
"source": "SKILL.md#safety-and-privacy-contract"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "correctness-gates",
|
|
45
|
+
"title": "Correctness gates",
|
|
46
|
+
"source": "SKILL.md#correctness-gates"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "crs-and-antimeridian-rules",
|
|
50
|
+
"title": "CRS and antimeridian rules",
|
|
51
|
+
"source": "SKILL.md#crs-and-antimeridian-rules"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "core-api-decisions",
|
|
55
|
+
"title": "Core API decisions",
|
|
56
|
+
"source": "SKILL.md#core-api-decisions"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "migration-checklist",
|
|
60
|
+
"title": "Migration checklist",
|
|
61
|
+
"source": "SKILL.md#migration-checklist"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "bundled-local-clis",
|
|
65
|
+
"title": "Bundled local CLIs",
|
|
66
|
+
"source": "SKILL.md#bundled-local-clis"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "reference-index",
|
|
70
|
+
"title": "Reference index",
|
|
71
|
+
"source": "SKILL.md#reference-index"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"id": "sources-verified-2026-07-23",
|
|
75
|
+
"title": "Sources (verified 2026-07-23)",
|
|
76
|
+
"source": "SKILL.md#sources-verified-2026-07-23"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"id": "crs-management",
|
|
80
|
+
"title": "CRS, units, and reprojection",
|
|
81
|
+
"source": "references/crs-management.md"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "data-io",
|
|
85
|
+
"title": "Vector I/O, GeoParquet, Arrow, and PostGIS",
|
|
86
|
+
"source": "references/data-io.md"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "data-structures",
|
|
90
|
+
"title": "GeoPandas data structures",
|
|
91
|
+
"source": "references/data-structures.md"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "geometric-operations",
|
|
95
|
+
"title": "Geometric operations, validity, and precision",
|
|
96
|
+
"source": "references/geometric-operations.md"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "spatial-analysis",
|
|
100
|
+
"title": "Spatial joins, overlay, clip, and dissolve",
|
|
101
|
+
"source": "references/spatial-analysis.md"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "visualization",
|
|
105
|
+
"title": "Static and interactive visualization",
|
|
106
|
+
"source": "references/visualization.md"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"checks": [
|
|
110
|
+
"crs.defined",
|
|
111
|
+
"crs.consistent",
|
|
112
|
+
"crs.metric_operation",
|
|
113
|
+
"geometry.valid",
|
|
114
|
+
"geometry.type_consistent"
|
|
115
|
+
]
|
|
116
|
+
}
|