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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env python3
2
+ """Plan CRS and datum transformation semantics without transforming coordinates."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import sys
8
+ from typing import Any
9
+
10
+ from _common import (
11
+ CliError,
12
+ crs_summary,
13
+ disable_proj_network,
14
+ emit_json,
15
+ fail_json,
16
+ finite_number,
17
+ native_versions,
18
+ package_versions,
19
+ )
20
+
21
+ TOOL = "crs_reprojection_plan"
22
+ METRIC_OPERATIONS = {"area", "buffer", "distance", "nearest", "precision"}
23
+
24
+
25
+ def build_parser() -> argparse.ArgumentParser:
26
+ parser = argparse.ArgumentParser(
27
+ description=(
28
+ "Inspect CRS axes, units, datum-operation candidates, grid availability, "
29
+ "and antimeridian risk without reading data or transforming coordinates."
30
+ ),
31
+ epilog=(
32
+ "PROJ network access is forcibly disabled. Optional bbox values are used "
33
+ "only as a protected area-of-interest hint and are never emitted."
34
+ ),
35
+ )
36
+ parser.add_argument("--source-crs", required=True, help="Authoritative source CRS")
37
+ parser.add_argument("--target-crs", required=True, help="Proposed target CRS")
38
+ parser.add_argument(
39
+ "--operation",
40
+ choices=(
41
+ "reproject",
42
+ "area",
43
+ "buffer",
44
+ "distance",
45
+ "nearest",
46
+ "precision",
47
+ "display",
48
+ ),
49
+ default="reproject",
50
+ help="Purpose used for unit-readiness checks (default: reproject)",
51
+ )
52
+ parser.add_argument(
53
+ "--bbox",
54
+ nargs=4,
55
+ metavar=("WEST_X", "SOUTH_Y", "EAST_X", "NORTH_Y"),
56
+ help=(
57
+ "Optional source-CRS bbox/area-of-interest. For geographic x/y input, "
58
+ "east < west marks an antimeridian crossing. Values are not emitted."
59
+ ),
60
+ )
61
+ parser.add_argument(
62
+ "--allow-ballpark",
63
+ action="store_true",
64
+ help="Include ballpark candidates in this plan (not recommended for accuracy work)",
65
+ )
66
+ return parser
67
+
68
+
69
+ def _dynamic(crs: Any) -> bool:
70
+ datum = getattr(crs, "datum", None)
71
+ type_name = str(getattr(datum, "type_name", "")).casefold()
72
+ return "dynamic" in type_name
73
+
74
+
75
+ def _candidate_summary(transformer: Any) -> dict[str, Any]:
76
+ accuracy = float(transformer.accuracy)
77
+ area = transformer.area_of_use
78
+ return {
79
+ "description": str(transformer.description)[:300],
80
+ "accuracy_metres": accuracy if accuracy >= 0 else None,
81
+ "accuracy_known": accuracy >= 0,
82
+ "area_of_use_name": str(area.name)[:200] if area else None,
83
+ }
84
+
85
+
86
+ def plan(args: argparse.Namespace) -> dict[str, Any]:
87
+ try:
88
+ from pyproj import CRS
89
+ from pyproj.aoi import AreaOfInterest
90
+ from pyproj.transformer import TransformerGroup
91
+ except ImportError as exc:
92
+ raise CliError("pyproj is required for CRS planning") from exc
93
+
94
+ disable_proj_network()
95
+ try:
96
+ source = CRS.from_user_input(args.source_crs)
97
+ target = CRS.from_user_input(args.target_crs)
98
+ except (TypeError, ValueError) as exc:
99
+ raise CliError("source or target CRS cannot be parsed") from exc
100
+
101
+ bbox_values: list[float] | None = None
102
+ crosses_antimeridian = False
103
+ area_of_interest = None
104
+ if args.bbox is not None:
105
+ bbox_values = [
106
+ finite_number(item, name=f"bbox[{index}]")
107
+ for index, item in enumerate(args.bbox)
108
+ ]
109
+ west, south, east, north = bbox_values
110
+ if south > north:
111
+ raise CliError("bbox south must not exceed north")
112
+ crosses_antimeridian = bool(source.is_geographic and east < west)
113
+ if not crosses_antimeridian:
114
+ try:
115
+ area_of_interest = AreaOfInterest(west, south, east, north)
116
+ except (TypeError, ValueError) as exc:
117
+ raise CliError("bbox is not a valid area of interest") from exc
118
+
119
+ try:
120
+ group = TransformerGroup(
121
+ source,
122
+ target,
123
+ always_xy=True,
124
+ area_of_interest=area_of_interest,
125
+ allow_ballpark=args.allow_ballpark,
126
+ )
127
+ except (TypeError, ValueError) as exc:
128
+ raise CliError("PROJ could not construct transformation candidates") from exc
129
+
130
+ candidates = [_candidate_summary(item) for item in group.transformers[:5]]
131
+ source_info = crs_summary(source)
132
+ target_info = crs_summary(target)
133
+ linear_target = bool(
134
+ target.is_projected
135
+ and target.axis_info
136
+ and all(
137
+ "degree" not in str(axis.unit_name).casefold() for axis in target.axis_info[:2]
138
+ )
139
+ )
140
+ metric_ready = args.operation not in METRIC_OPERATIONS or linear_target
141
+ warnings: list[str] = []
142
+ if source.is_geographic:
143
+ warnings.append(
144
+ "Source coordinates are angular; GeoPandas segment transforms are vertex-wise, not geodesic."
145
+ )
146
+ if args.operation in METRIC_OPERATIONS and not linear_target:
147
+ warnings.append(
148
+ "Target CRS does not provide projected linear axes for the requested planar operation."
149
+ )
150
+ if crosses_antimeridian:
151
+ warnings.append(
152
+ "The bbox crosses the antimeridian; split/unwrap and densify as justified before to_crs."
153
+ )
154
+ if not group.best_available:
155
+ warnings.append(
156
+ "The best known operation is unavailable, commonly because a transformation grid is absent."
157
+ )
158
+ if not candidates:
159
+ warnings.append("No available transformation candidate satisfies this policy.")
160
+ if _dynamic(source) or _dynamic(target):
161
+ warnings.append(
162
+ "A dynamic CRS is involved; record and validate the coordinate epoch separately."
163
+ )
164
+
165
+ return {
166
+ "ok": bool(candidates) and metric_ready and bool(group.best_available),
167
+ "tool": TOOL,
168
+ "source_crs": source_info,
169
+ "target_crs": target_info,
170
+ "purpose": args.operation,
171
+ "coordinate_array_order": "x_y_via_always_xy",
172
+ "source_dynamic_crs": _dynamic(source),
173
+ "target_dynamic_crs": _dynamic(target),
174
+ "bbox": {
175
+ "provided": bbox_values is not None,
176
+ "values_emitted": False,
177
+ "used_as_area_of_interest": area_of_interest is not None,
178
+ "crosses_antimeridian": crosses_antimeridian,
179
+ },
180
+ "operation_policy": {
181
+ "allow_ballpark": bool(args.allow_ballpark),
182
+ "only_best_recommended_for_execution": True,
183
+ "proj_network_enabled": False,
184
+ "metric_operation_ready": metric_ready,
185
+ },
186
+ "candidate_count": len(group.transformers),
187
+ "candidate_summaries_first_five": candidates,
188
+ "best_available": bool(group.best_available),
189
+ "unavailable_operation_count": len(group.unavailable_operations),
190
+ "coordinates_transformed": False,
191
+ "network_accessed": False,
192
+ "coordinates_emitted": False,
193
+ "identifiers_emitted": False,
194
+ "stack": {"packages": package_versions(), "native": native_versions()},
195
+ "warnings": warnings,
196
+ }
197
+
198
+
199
+ def main(argv: list[str] | None = None) -> int:
200
+ args = build_parser().parse_args(argv)
201
+ try:
202
+ report = plan(args)
203
+ emit_json(report)
204
+ return 0 if report["ok"] else 2
205
+ except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
206
+ return fail_json(TOOL, exc)
207
+
208
+
209
+ if __name__ == "__main__":
210
+ sys.exit(main())
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env python3
2
+ """Create a non-executing, redacted vector export and GeoParquet plan."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import sys
8
+ from typing import Any
9
+
10
+ from _common import (
11
+ ABSOLUTE_MAX_FEATURES,
12
+ DEFAULT_MAX_FEATURES,
13
+ DEFAULT_MAX_INPUT_BYTES,
14
+ CliError,
15
+ bounded_limit,
16
+ checked_input_file,
17
+ checked_output_file,
18
+ emit_json,
19
+ fail_json,
20
+ inspect_local_vector,
21
+ native_versions,
22
+ package_versions,
23
+ positive_int,
24
+ sha256_file,
25
+ )
26
+
27
+ TOOL = "export_plan"
28
+ FORMAT_SUFFIXES = {
29
+ "flatgeobuf": {".fgb"},
30
+ "geopackage": {".gpkg"},
31
+ "geojson": {".geojson", ".json"},
32
+ "geoparquet": {".geoparquet", ".parquet"},
33
+ "shapefile": {".shp"},
34
+ }
35
+ SUFFIX_FORMAT = {
36
+ suffix: format_name
37
+ for format_name, suffixes in FORMAT_SUFFIXES.items()
38
+ for suffix in suffixes
39
+ }
40
+
41
+
42
+ def build_parser() -> argparse.ArgumentParser:
43
+ parser = argparse.ArgumentParser(
44
+ description=(
45
+ "Plan—but do not execute—a local vector export. Inspect only metadata, "
46
+ "validate a new output path, and emit format/privacy/provenance gates."
47
+ ),
48
+ epilog=(
49
+ "No feature data or coordinates are loaded. URLs, archives, symlinks, "
50
+ "path traversal, and existing output paths are rejected."
51
+ ),
52
+ )
53
+ parser.add_argument("input", help="Allowlisted local vector/GeoParquet input")
54
+ parser.add_argument("output", help="Proposed new local output path")
55
+ parser.add_argument("--root", default=".", help="Existing local I/O root")
56
+ parser.add_argument("--layer", help="Exact input layer name")
57
+ parser.add_argument(
58
+ "--format",
59
+ choices=tuple(sorted(FORMAT_SUFFIXES)),
60
+ help="Target format; default infers from output suffix",
61
+ )
62
+ parser.add_argument(
63
+ "--stable-id-column",
64
+ help="Declared stable feature-ID column (name is not emitted)",
65
+ )
66
+ parser.add_argument(
67
+ "--id-unique-verified",
68
+ action="store_true",
69
+ help="Attest that stable ID is non-null and unique in the planned export",
70
+ )
71
+ parser.add_argument(
72
+ "--index-policy",
73
+ choices=("omit", "include"),
74
+ default="omit",
75
+ help="Whether to serialize the pandas index (default: omit)",
76
+ )
77
+ parser.add_argument(
78
+ "--geometry-encoding",
79
+ choices=("WKB", "geoarrow"),
80
+ default="WKB",
81
+ help="GeoParquet geometry encoding (default: WKB)",
82
+ )
83
+ parser.add_argument(
84
+ "--schema-version",
85
+ choices=("1.0.0", "1.1.0"),
86
+ default="1.0.0",
87
+ help="GeoParquet schema version (default: stable 1.0.0)",
88
+ )
89
+ parser.add_argument(
90
+ "--write-covering-bbox",
91
+ action="store_true",
92
+ help="Plan a GeoParquet 1.1 per-row bbox covering column",
93
+ )
94
+ parser.add_argument(
95
+ "--public-output",
96
+ action="store_true",
97
+ help="Mark the proposed output as intended for public release",
98
+ )
99
+ parser.add_argument(
100
+ "--sensitive-coordinates",
101
+ action="store_true",
102
+ help="Mark input as containing sensitive exact locations",
103
+ )
104
+ parser.add_argument(
105
+ "--generalized-and-reviewed",
106
+ action="store_true",
107
+ help="Attest that coordinates/attributes were generalized and reviewed",
108
+ )
109
+ parser.add_argument(
110
+ "--max-input-bytes",
111
+ type=positive_int,
112
+ default=DEFAULT_MAX_INPUT_BYTES,
113
+ )
114
+ parser.add_argument(
115
+ "--max-features",
116
+ type=positive_int,
117
+ default=DEFAULT_MAX_FEATURES,
118
+ help="Declared-feature threshold for the downstream export",
119
+ )
120
+ return parser
121
+
122
+
123
+ def _format_risks(format_name: str) -> list[str]:
124
+ risks = {
125
+ "geopackage": [
126
+ "One geometry column per layer; additional geometry columns need separate layers or explicit encoding.",
127
+ "Append/overwrite behavior is driver-specific; this plan requires a new file.",
128
+ ],
129
+ "geojson": [
130
+ "Text output exposes exact coordinates and attributes directly.",
131
+ "CRS/type/datetime/large-integer fidelity is limited; RFC 7946 interoperability normally expects WGS84 longitude/latitude.",
132
+ ],
133
+ "shapefile": [
134
+ "Legacy multi-file output has field-name, null, type, encoding, geometry, and size limitations.",
135
+ "A single hash does not cover the complete sidecar set.",
136
+ ],
137
+ "flatgeobuf": [
138
+ "Driver/version interoperability and field-type support must be roundtrip-tested.",
139
+ ],
140
+ "geoparquet": [
141
+ "GeoParquet readers vary in support for schema 1.1 native encodings and bbox covering.",
142
+ "Stable feature IDs require an explicit project column/metadata contract.",
143
+ ],
144
+ }
145
+ return risks[format_name]
146
+
147
+
148
+ def plan(args: argparse.Namespace) -> dict[str, Any]:
149
+ max_features = bounded_limit(
150
+ args.max_features,
151
+ name="max_features",
152
+ maximum=ABSOLUTE_MAX_FEATURES,
153
+ )
154
+ source = checked_input_file(
155
+ args.input,
156
+ root=args.root,
157
+ max_bytes=args.max_input_bytes,
158
+ )
159
+ suffix = str(args.output).casefold().strip()
160
+ suffix = "." + suffix.rsplit(".", 1)[-1] if "." in suffix else ""
161
+ inferred = SUFFIX_FORMAT.get(suffix)
162
+ format_name = args.format or inferred
163
+ if format_name is None:
164
+ raise CliError("target format cannot be inferred from output suffix")
165
+ destination = checked_output_file(
166
+ args.output,
167
+ root=args.root,
168
+ allowed_suffixes=FORMAT_SUFFIXES[format_name],
169
+ )
170
+ if inferred is not None and inferred != format_name:
171
+ raise CliError("target format conflicts with output suffix")
172
+
173
+ technical = inspect_local_vector(source, layer=args.layer)
174
+ declared = technical.get("declared_features")
175
+ blockers: list[str] = []
176
+ warnings = _format_risks(format_name)
177
+
178
+ if args.stable_id_column is None:
179
+ blockers.append("declare a stable feature-ID column")
180
+ elif not args.id_unique_verified:
181
+ blockers.append("verify the stable ID is non-null and unique")
182
+ if declared is not None and declared > max_features:
183
+ blockers.append("declared feature count exceeds the downstream limit")
184
+ if (
185
+ args.public_output
186
+ and args.sensitive_coordinates
187
+ and not args.generalized_and_reviewed
188
+ ):
189
+ blockers.append(
190
+ "public sensitive-coordinate output requires generalization and review"
191
+ )
192
+ if args.generalized_and_reviewed and not args.sensitive_coordinates:
193
+ warnings.append(
194
+ "Generalization attestation was supplied without marking coordinates sensitive."
195
+ )
196
+
197
+ geoparquet_options_used = (
198
+ args.geometry_encoding != "WKB"
199
+ or args.schema_version != "1.0.0"
200
+ or args.write_covering_bbox
201
+ )
202
+ if format_name != "geoparquet" and geoparquet_options_used:
203
+ blockers.append("GeoParquet options are valid only for geoparquet output")
204
+ if format_name == "geoparquet":
205
+ if args.geometry_encoding == "geoarrow" and args.schema_version != "1.1.0":
206
+ blockers.append("native geoarrow encoding requires schema 1.1.0")
207
+ if args.write_covering_bbox and args.schema_version != "1.1.0":
208
+ blockers.append("bbox covering requires schema 1.1.0")
209
+ if args.write_covering_bbox and args.sensitive_coordinates:
210
+ blockers.append(
211
+ "per-row bbox covering is not approved for sensitive coordinates"
212
+ )
213
+ if args.schema_version == "1.1.0":
214
+ warnings.append(
215
+ "GeoPandas describes native encoding and bbox covering as experimental/interoperability-limited."
216
+ )
217
+
218
+ if technical["kind"] == "gdal_vector":
219
+ if not technical["crs"]["present"]:
220
+ blockers.append("source CRS metadata is missing")
221
+ elif technical["kind"] == "geoparquet":
222
+ states = technical["crs_metadata_states"]
223
+ if states["null"]:
224
+ blockers.append("one or more GeoParquet geometry columns have unknown CRS")
225
+ if states["missing"]:
226
+ warnings.append(
227
+ "A missing GeoParquet CRS key means OGC:CRS84, not unknown CRS."
228
+ )
229
+ else:
230
+ blockers.append("input Parquet lacks required GeoParquet metadata")
231
+
232
+ return {
233
+ "ok": not blockers,
234
+ "tool": TOOL,
235
+ "executed": False,
236
+ "feature_data_loaded": False,
237
+ "source": {
238
+ "sha256": sha256_file(source),
239
+ "bytes": source.stat().st_size,
240
+ "path_emitted": False,
241
+ "technical_inventory": technical,
242
+ },
243
+ "target": {
244
+ "format": format_name,
245
+ "suffix": destination.suffix.casefold(),
246
+ "path_emitted": False,
247
+ "exists": False,
248
+ "index_policy": args.index_policy,
249
+ "stable_id_declared": args.stable_id_column is not None,
250
+ "stable_id_name_emitted": False,
251
+ "stable_id_unique_verified": bool(args.id_unique_verified),
252
+ },
253
+ "geoparquet": (
254
+ {
255
+ "schema_version": args.schema_version,
256
+ "geometry_encoding": args.geometry_encoding,
257
+ "write_covering_bbox": bool(args.write_covering_bbox),
258
+ "default_stable_contract": bool(
259
+ args.schema_version == "1.0.0"
260
+ and args.geometry_encoding == "WKB"
261
+ and not args.write_covering_bbox
262
+ ),
263
+ }
264
+ if format_name == "geoparquet"
265
+ else None
266
+ ),
267
+ "privacy": {
268
+ "public_output": bool(args.public_output),
269
+ "sensitive_coordinates": bool(args.sensitive_coordinates),
270
+ "generalized_and_reviewed": bool(args.generalized_and_reviewed),
271
+ "coordinates_emitted": False,
272
+ },
273
+ "roundtrip_checks_required": [
274
+ "row count and stable-ID set",
275
+ "CRS and active/additional geometry columns",
276
+ "null, empty, invalid, geometry type, and dimensionality counts",
277
+ "field types, nullability, encoding, and expected format losses",
278
+ "protected coarse bounds and representative attributes",
279
+ "new artifact hash and package/native versions",
280
+ ],
281
+ "format_risks": warnings,
282
+ "blockers": blockers,
283
+ "resource_limits": {
284
+ "max_input_bytes": args.max_input_bytes,
285
+ "max_features_for_execution": max_features,
286
+ },
287
+ "network_accessed": False,
288
+ "coordinates_emitted": False,
289
+ "identifiers_emitted": False,
290
+ "stack": {"packages": package_versions(), "native": native_versions()},
291
+ }
292
+
293
+
294
+ def main(argv: list[str] | None = None) -> int:
295
+ args = build_parser().parse_args(argv)
296
+ try:
297
+ report = plan(args)
298
+ emit_json(report)
299
+ return 0 if report["ok"] else 2
300
+ except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
301
+ return fail_json(TOOL, exc)
302
+
303
+
304
+ if __name__ == "__main__":
305
+ sys.exit(main())