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,323 @@
1
+ # Vector I/O, GeoParquet, Arrow, and PostGIS
2
+
3
+ GeoPandas 1.x defaults to pyogrio for vector-file I/O. pyogrio and Fiona are
4
+ bindings to GDAL/OGR; actual formats, options, and behavior depend on the
5
+ installed native GDAL and drivers.
6
+
7
+ ## Local-only intake policy
8
+
9
+ Do not automatically pass any of these to GeoPandas/GDAL:
10
+
11
+ - `http://`, `https://`, `s3://`, `gs://`, Azure, or another remote URI;
12
+ - GDAL `/vsicurl/`, `/vsis3/`, `/vsizip/`, chained virtual filesystems, or
13
+ pyogrio `zip+...` paths;
14
+ - ZIP/KMZ/TAR/GZ/7z/RAR or nested archives;
15
+ - macro-enabled office files or an untrusted permissive driver;
16
+ - a user-supplied PostGIS connection string.
17
+
18
+ GeoPandas officially supports URLs and GDAL supports network/archive virtual
19
+ filesystems, but that capability crosses network, decompression, parser, and
20
+ credential trust boundaries. Obtain explicit approval, verify source/hash and
21
+ size out of band, unpack in a sandbox with resource limits, then process an
22
+ allowlisted local regular file.
23
+
24
+ The bundled CLIs reject URL/VSI/archive syntax, symlinks, path traversal, and
25
+ non-allowlisted suffixes.
26
+
27
+ ## Inspect before reading features
28
+
29
+ For GDAL-backed formats:
30
+
31
+ ```python
32
+ from pathlib import Path
33
+ import pyogrio
34
+
35
+ path = Path("approved/input.gpkg")
36
+ if not path.is_file() or path.is_symlink():
37
+ raise ValueError("Expected a vetted local regular file")
38
+
39
+ layers = pyogrio.list_layers(path)
40
+ info = pyogrio.read_info(path, layer="approved_layer", force_feature_count=False)
41
+ drivers = pyogrio.list_drivers()
42
+ ```
43
+
44
+ Record:
45
+
46
+ - primary-file hash and byte size (a Shapefile hash does not cover sidecars);
47
+ - driver, layer, declared feature count, fields/dtypes, encoding, geometry type;
48
+ - CRS and whether bounds were present, but redact precise bounds by default;
49
+ - `pyogrio.__gdal_version__`, `pyogrio.__gdal_geos_version__`, Shapely GEOS,
50
+ pyproj PROJ, package versions, and enabled driver capabilities.
51
+
52
+ `list_drivers()` returns capabilities containing `r`, `w`, and/or `a`, but a
53
+ listed driver is not proof every field/geometry is supported. Treat drivers as
54
+ an allowlist, not merely a discovered list.
55
+
56
+ ## `read_file`
57
+
58
+ Stable signature:
59
+
60
+ ```python
61
+ gdf = geopandas.read_file(
62
+ filename,
63
+ bbox=None,
64
+ mask=None,
65
+ columns=None,
66
+ rows=None,
67
+ engine="pyogrio",
68
+ use_arrow=True,
69
+ )
70
+ ```
71
+
72
+ Rules:
73
+
74
+ - `bbox` and `mask` are mutually exclusive.
75
+ - With pyogrio, a bbox tuple must already be in the dataset CRS. Fiona can
76
+ reproject a GeoSeries/GeoDataFrame bbox; do not depend on engine-specific
77
+ implicit behavior.
78
+ - A mask must have an explicit CRS compatible with the source.
79
+ - `columns=[]` reads geometry without attributes; `ignore_geometry=True`
80
+ returns a pandas DataFrame.
81
+ - `rows=n` reads the first n rows; `rows=slice(a, b)` reads a slice.
82
+ - `where=` is evaluated by a driver SQL dialect. Do not concatenate untrusted
83
+ expressions.
84
+ - Encoding auto-detection can fail; set a verified encoding explicitly.
85
+ - `use_arrow=True` requires PyArrow and speeds pyogrio bulk transfer, but does
86
+ not change parser trust or correctness requirements.
87
+ - Bound both file bytes and features. Some drivers cannot cheaply report a
88
+ count; read at most `limit + 1` and fail closed when the limit is exceeded.
89
+
90
+ GeoPandas may use HTTP range requests or download an entire URL in memory.
91
+ This skill therefore does not include remote-read examples.
92
+
93
+ ## Filters are not always exact
94
+
95
+ pyogrio documents:
96
+
97
+ - `bbox`/`mask` coordinates must use the dataset CRS;
98
+ - when GDAL is built with GEOS, geometry intersection filtering is exact;
99
+ - without GEOS, filters can return features whose **bounding boxes** intersect,
100
+ requiring a second exact predicate check;
101
+ - Arrow reads involving skip/max may read batches beyond the requested slice
102
+ before slicing;
103
+ - feature IDs are driver-specific and may start at 0, 1, or another value.
104
+
105
+ Do not treat driver FID as a portable stable feature ID.
106
+
107
+ ## Writing traditional vector formats
108
+
109
+ Write a new path and reopen it:
110
+
111
+ ```python
112
+ output = Path("derived/result.gpkg")
113
+ if output.exists() or output.is_symlink():
114
+ raise FileExistsError("Choose a new output path")
115
+
116
+ gdf.to_file(
117
+ output,
118
+ layer="result",
119
+ driver="GPKG",
120
+ engine="pyogrio",
121
+ index=False,
122
+ use_arrow=True,
123
+ )
124
+
125
+ roundtrip = geopandas.read_file(output, layer="result", engine="pyogrio")
126
+ ```
127
+
128
+ Never use implicit overwrite/append. Driver behavior varies and multi-file
129
+ formats complicate atomic writes.
130
+
131
+ ### Format tradeoffs
132
+
133
+ - **GeoPackage**: good general local interchange; multiple layers, one geometry
134
+ column per layer, SQL-backed metadata.
135
+ - **GeoJSON**: broadly interoperable but normally WGS84 longitude/latitude,
136
+ limited type fidelity, text-heavy, and easy to leak precise coordinates.
137
+ - **Shapefile**: legacy multi-file format with field-name, type, null, encoding,
138
+ geometry, and size constraints. Avoid for new work.
139
+ - **FlatGeobuf**: efficient stream/spatial-index format, but interoperability
140
+ still depends on driver versions.
141
+ - **GeoParquet**: efficient columnar storage with multiple geometry columns and
142
+ explicit geospatial metadata.
143
+
144
+ Traditional formats often cannot store lists, structs, arbitrary objects, or
145
+ multiple geometry columns. Plan conversions and reject silent loss.
146
+
147
+ ## GeoParquet and Feather
148
+
149
+ ```python
150
+ gdf.to_parquet(
151
+ "derived/result.parquet",
152
+ index=False,
153
+ compression="snappy",
154
+ geometry_encoding="WKB",
155
+ write_covering_bbox=False,
156
+ schema_version="1.0.0",
157
+ )
158
+
159
+ roundtrip = geopandas.read_parquet(
160
+ "derived/result.parquet",
161
+ columns=["feature_id", "geometry"],
162
+ )
163
+ ```
164
+
165
+ GeoPandas 1.1.4 write semantics:
166
+
167
+ - all geometry columns are preserved;
168
+ - default `geometry_encoding="WKB"` maximizes interoperability;
169
+ - default supported stable schema is **1.0.0**;
170
+ - `geometry_encoding="geoarrow"` requires GeoParquet 1.1.0, supports
171
+ single-geometry native encodings, and is still described as experimental;
172
+ - `write_covering_bbox=True` adds a per-row `bbox` column and 1.1 covering
173
+ metadata. It costs compute and may reveal precise extents;
174
+ - `schema_version` replaces the removed/deprecated old `version=` usage;
175
+ - `index=None` writes non-RangeIndex values as columns and stores RangeIndex as
176
+ metadata. Use an explicit stable feature-ID column instead.
177
+
178
+ Read semantics:
179
+
180
+ - selecting no geometry columns raises; use `pandas.read_parquet` for a
181
+ non-spatial result;
182
+ - if the stored primary geometry is omitted, the first selected geometry
183
+ becomes active;
184
+ - bbox filtering works only when covering metadata/columns were written;
185
+ - if GeoParquet `crs` metadata is **missing**, the specification default is
186
+ `OGC:CRS84`;
187
+ - an explicit `crs: null` means unknown/undefined, which is different;
188
+ - WKB/native coordinates are x/y regardless of authority axis order.
189
+
190
+ GeoParquet 1.1 metadata requires a `geo` JSON value, `primary_column`, and
191
+ metadata for every geometry column. Geometry columns must be root-level and may
192
+ be optional; native child coordinates cannot contain nulls. `edges` defaults to
193
+ `planar`. Feature identifiers are outside the core specification, so define and
194
+ document your own stable-ID metadata/column.
195
+
196
+ Do not use bbox covering for public sensitive-location data without
197
+ generalization and approval.
198
+
199
+ ### Arrow in memory
200
+
201
+ GeoPandas 1.0 added `to_arrow()` and `from_arrow()` using GeoArrow extension
202
+ types. These improve interchange but do not make an array self-validating:
203
+ verify extension metadata, CRS, geometry encoding/type, nulls, and active
204
+ geometry after round-trip. GeoPandas 1.1 adds `to_pandas_kwargs` controls for
205
+ non-geometry Arrow conversion.
206
+
207
+ ## PostGIS without credential leakage
208
+
209
+ Required writing dependencies are SQLAlchemy, GeoAlchemy2, and psycopg/psycopg2.
210
+ Create connections from named secrets without embedding or logging a connection
211
+ URL:
212
+
213
+ ```python
214
+ import os
215
+ from sqlalchemy import URL, create_engine
216
+
217
+ db_url = URL.create(
218
+ "postgresql+psycopg",
219
+ username=os.environ["GEOPANDAS_POSTGIS_USER"],
220
+ password=os.environ["GEOPANDAS_POSTGIS_PASSWORD"],
221
+ host=os.environ["GEOPANDAS_POSTGIS_HOST"],
222
+ port=int(os.environ["GEOPANDAS_POSTGIS_PORT"]),
223
+ database=os.environ["GEOPANDAS_POSTGIS_DATABASE"],
224
+ )
225
+ engine = create_engine(db_url)
226
+ ```
227
+
228
+ Read only those named variables (or secret-manager equivalents). Never print
229
+ `db_url`, `engine.url`, exception payloads containing it, or the broader
230
+ environment.
231
+
232
+ Use parameterized values and trusted SQL identifiers:
233
+
234
+ ```python
235
+ from sqlalchemy import text
236
+
237
+ query = text(
238
+ "SELECT feature_id, geom FROM approved_schema.features "
239
+ "WHERE category = :category"
240
+ )
241
+ gdf = geopandas.read_postgis(
242
+ query,
243
+ con=engine,
244
+ geom_col="geom",
245
+ params={"category": approved_category},
246
+ chunksize=10_000,
247
+ )
248
+ ```
249
+
250
+ `read_postgis` infers one CRS from the SRID of the first geometry and assigns it
251
+ to all rows unless `crs=` is supplied. Verify all geometries share the expected
252
+ SRID. With `chunksize`, it returns an iterator; validate every chunk and enforce
253
+ a total-row limit.
254
+
255
+ For writes:
256
+
257
+ ```python
258
+ with engine.begin() as connection:
259
+ gdf.to_postgis(
260
+ "derived_features",
261
+ con=connection,
262
+ schema="approved_schema",
263
+ if_exists="fail",
264
+ index=False,
265
+ chunksize=10_000,
266
+ )
267
+ ```
268
+
269
+ - Default to `if_exists="fail"`.
270
+ - `replace` drops an existing table and is destructive.
271
+ - Validate schema/table/geometry column names against an allowlist; do not
272
+ interpolate user input.
273
+ - GeoPandas 1.1.2 fixed SQL injection through a geometry-column name; remain on
274
+ a patched version and still validate identifiers.
275
+ - Use least-privilege database roles and a transaction.
276
+
277
+ ## Fiona-to-pyogrio migration
278
+
279
+ GeoPandas 1.0 changed the default engine from Fiona to pyogrio. Differences
280
+ include:
281
+
282
+ - schema/metadata keywords and driver options;
283
+ - writing attribute-only tables;
284
+ - handling empty geometries and unsupported field types;
285
+ - datetime resolution/timezone behavior;
286
+ - append and encoding behavior;
287
+ - error/warning text and filter behavior.
288
+
289
+ Set `engine=` explicitly for reproducibility and test round-trips before
290
+ migration. Do not assume identical outputs merely because both engines use GDAL.
291
+
292
+ ## Export verification and provenance
293
+
294
+ For every output:
295
+
296
+ 1. choose a new local path and explicit format/driver/layer;
297
+ 2. record source hashes, source layer, stack/native versions, CRS, precision,
298
+ repair, and transformation choices;
299
+ 3. record field names/types/nullability, geometry columns/types, stable ID,
300
+ index policy, encoding, dimensions, and expected losses;
301
+ 4. write, then reopen with an independent code path when feasible;
302
+ 5. compare row count, stable-ID set, null/empty/invalid/type counts, CRS, bounds
303
+ at protected precision, and representative attribute values;
304
+ 6. hash the completed artifact and store the audit separately.
305
+
306
+ Use `scripts/vector_inventory.py` for redacted intake and
307
+ `scripts/export_plan.py` for a non-executing output contract.
308
+
309
+ ## Sources (verified 2026-07-23)
310
+
311
+ - [GeoPandas reading and writing files](https://geopandas.org/en/stable/docs/user_guide/io.html).
312
+ - [geopandas.read_file](https://geopandas.org/en/stable/docs/reference/api/geopandas.read_file.html).
313
+ - [GeoDataFrame.to_file](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_file.html).
314
+ - [GeoDataFrame.to_parquet](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_parquet.html).
315
+ - [geopandas.read_parquet](https://geopandas.org/en/stable/docs/reference/api/geopandas.read_parquet.html).
316
+ - [geopandas.read_postgis](https://geopandas.org/en/stable/docs/reference/api/geopandas.read_postgis.html).
317
+ - [GeoDataFrame.to_postgis](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_postgis.html).
318
+ - [Fiona-to-pyogrio migration](https://geopandas.org/en/stable/docs/user_guide/fiona_to_pyogrio.html).
319
+ - [pyogrio introduction](https://pyogrio.readthedocs.io/en/stable/introduction.html).
320
+ - [pyogrio API](https://pyogrio.readthedocs.io/en/stable/api.html).
321
+ - [GeoParquet 1.1.0 specification](https://geoparquet.org/releases/v1.1.0/).
322
+ - [GeoArrow 0.2 specification](https://github.com/geoarrow/geoarrow).
323
+ - [GeoPandas 1.1.2 security/bug-fix release](https://github.com/geopandas/geopandas/releases/tag/v1.1.2) — released 2025-12-22.
@@ -0,0 +1,207 @@
1
+ # GeoPandas data structures
2
+
3
+ GeoPandas 1.1.4 extends pandas with a `geometry` extension dtype backed by
4
+ Shapely 2. A `GeoSeries` is one geometry-valued pandas Series; a `GeoDataFrame`
5
+ is a DataFrame with one active geometry column and may contain additional
6
+ geometry columns.
7
+
8
+ ## Construction
9
+
10
+ Always assign CRS at construction when it is known from authoritative metadata.
11
+ Do not infer it from coordinate ranges.
12
+
13
+ ```python
14
+ import geopandas as gpd
15
+ import pandas as pd
16
+ from shapely import Point, box
17
+
18
+ points = gpd.GeoSeries(
19
+ [Point(0, 0), Point(1, 1), None],
20
+ index=["feature-a", "feature-b", "feature-c"],
21
+ crs="EPSG:3857",
22
+ name="location",
23
+ )
24
+
25
+ gdf = gpd.GeoDataFrame(
26
+ {
27
+ "feature_id": ["feature-a", "feature-b"],
28
+ "value": [10, 20],
29
+ "geometry": [Point(0, 0), Point(1, 1)],
30
+ },
31
+ geometry="geometry",
32
+ crs="EPSG:3857",
33
+ )
34
+
35
+ table = pd.DataFrame({"x": [0.0, 1.0], "y": [0.0, 1.0]})
36
+ from_xy = gpd.GeoDataFrame(
37
+ table,
38
+ geometry=gpd.points_from_xy(table["x"], table["y"]),
39
+ crs="EPSG:3857",
40
+ )
41
+ ```
42
+
43
+ `points_from_xy` interprets arguments as x then y. For geographic data, that is
44
+ normally longitude then latitude in the coordinate array, even though the
45
+ authority definition of EPSG:4326 advertises latitude-first axes.
46
+
47
+ ## Active and additional geometry columns
48
+
49
+ Frame-level spatial methods act on one active geometry column:
50
+
51
+ ```python
52
+ gdf["buffered"] = gdf.geometry.buffer(10)
53
+ gdf = gdf.set_geometry("buffered")
54
+
55
+ assert gdf.active_geometry_name == "buffered"
56
+ assert gdf.geometry.name == "buffered"
57
+
58
+ gdf = gdf.rename_geometry("analysis_geometry")
59
+ ```
60
+
61
+ Important distinctions:
62
+
63
+ - `gdf.geometry` always returns the active geometry, not necessarily a column
64
+ literally named `"geometry"`.
65
+ - `rename_geometry()` updates the active-column bookkeeping. A plain pandas
66
+ `rename(columns=...)` must be followed by `set_geometry()`.
67
+ - A `GeoDataFrame` can hold multiple geometry columns with different CRS
68
+ metadata. Switching the active column switches the CRS exposed as `gdf.crs`.
69
+ - Ordinary vector formats generally support only one geometry per layer.
70
+ GeoParquet and Feather can preserve multiple geometry columns.
71
+ - GeoPandas 1.0 changed `set_geometry(named_series)`: the Series name becomes
72
+ the active column name and the old geometry column is preserved. Avoid the
73
+ deprecated `drop=` parameter; rename/drop explicitly.
74
+
75
+ Check every geometry column independently:
76
+
77
+ ```python
78
+ geometry_columns = [
79
+ name for name, dtype in gdf.dtypes.items() if str(dtype) == "geometry"
80
+ ]
81
+ column_crs = {name: gdf[name].crs for name in geometry_columns}
82
+ ```
83
+
84
+ ## Missing, empty, and invalid are different
85
+
86
+ Treat these states separately:
87
+
88
+ | State | Test | Meaning |
89
+ |---|---|---|
90
+ | Missing | `series.isna()` | Unknown geometry, represented by `None` |
91
+ | Empty | `series.is_empty` | A geometry object with no coordinates |
92
+ | Invalid | `~series.is_valid` after excluding missing | Coordinates violate topology rules |
93
+
94
+ ```python
95
+ missing = gdf.geometry.isna()
96
+ empty = gdf.geometry.is_empty
97
+ invalid = (~missing) & (~empty) & (~gdf.geometry.is_valid)
98
+ usable = ~(missing | empty | invalid)
99
+ ```
100
+
101
+ Missing values generally propagate through element-wise operations and are
102
+ ignored by reductions such as `union_all()`. Empty geometries participate as
103
+ geometries: they may have area `0.0` and remain empty after intersection.
104
+ Never use only `dropna()` to remove unusable geometries.
105
+
106
+ ## Index alignment
107
+
108
+ Binary geometry methods are **row-wise**, not all-pairs operations. With a
109
+ GeoSeries argument, `align=None` defaults to label alignment:
110
+
111
+ ```python
112
+ left = gpd.GeoSeries([Point(0, 0), Point(1, 1)], index=["a", "b"])
113
+ right = gpd.GeoSeries([Point(1, 1), Point(0, 0)], index=["b", "a"])
114
+
115
+ by_label = left.intersects(right, align=True)
116
+ by_position = left.intersects(right, align=False)
117
+ ```
118
+
119
+ Use `align=False` only after proving equal lengths and intended row order.
120
+ GeoPandas 1.0 raises on some unaligned pandas Series method arguments to avoid
121
+ ambiguous automatic alignment. For all-pairs matching use a spatial join or
122
+ spatial-index query.
123
+
124
+ Assignment also aligns by index:
125
+
126
+ ```python
127
+ result = gdf.copy()
128
+ derived = result.geometry.buffer(10)
129
+ result.loc[:, "buffered"] = derived # label-aligned
130
+ ```
131
+
132
+ Reset or preserve indices deliberately before positional work. Never assume the
133
+ pandas index is a stable feature identifier.
134
+
135
+ ## Feature identity and duplicate controls
136
+
137
+ Keep a non-null, stable feature-ID column across reads, joins, explode,
138
+ overlay, dissolve, and exports:
139
+
140
+ ```python
141
+ ids = gdf["feature_id"]
142
+ if ids.isna().any() or ids.duplicated(keep=False).any():
143
+ raise ValueError("feature_id must be non-null and unique for this workflow")
144
+ ```
145
+
146
+ Cardinality-changing operations need explicit provenance:
147
+
148
+ - `explode(ignore_index=False, index_parts=False)` defaults to no part-level
149
+ MultiIndex in GeoPandas 1.0+. Create a part number if parts need identity.
150
+ - Spatial joins can repeat either side; retain both source IDs.
151
+ - Overlay can split one feature into many. Add source IDs before overlay and
152
+ generate a derived ID afterward.
153
+ - Dissolve intentionally combines IDs; record group keys and aggregation rules.
154
+ - `pd.concat` requires compatible geometry-column CRS and can preserve duplicate
155
+ indices unless `ignore_index=True`.
156
+
157
+ ## Geometry type and dimensionality
158
+
159
+ `geom_type`, `has_z`, and (with Shapely 2.1) `has_m` describe different
160
+ properties. Mixed geometry types are valid in memory but can break overlay or
161
+ export contracts. Z and M ordinates are not used by GeoPandas' planar topology:
162
+
163
+ ```python
164
+ summary = {
165
+ "types": gdf.geometry.geom_type.value_counts(dropna=False).to_dict(),
166
+ "has_z": int(gdf.geometry.has_z.sum()),
167
+ "has_m": int(gdf.geometry.has_m.sum()),
168
+ }
169
+ ```
170
+
171
+ Do not silently drop Z/M. If a target format or operation is 2D-only, record the
172
+ loss and create a new derived artifact.
173
+
174
+ ## Copying and conversion
175
+
176
+ - Use `gdf.copy()` before replacing an active geometry.
177
+ - Call `merge()` from the GeoDataFrame side; `plain_df.merge(gdf, ...)` can
178
+ return a non-spatial DataFrame.
179
+ - Reading a non-spatial layer with `read_file()` returns a pandas DataFrame in
180
+ GeoPandas 1.0+.
181
+ - `np.asarray(gdf.geometry)` or `gdf.geometry.to_numpy()` replaces removed
182
+ access to `GeometryArray.data`.
183
+ - Do not serialize geometries with pickle for exchange. Use GeoPackage,
184
+ GeoParquet, WKB, or WKT with an explicit CRS contract.
185
+
186
+ ## Minimum structure audit
187
+
188
+ Record, without emitting coordinates or identifiers:
189
+
190
+ 1. row and column counts;
191
+ 2. active and additional geometry-column names;
192
+ 3. CRS per geometry column;
193
+ 4. counts of missing, empty, invalid, Z/M, and each geometry type;
194
+ 5. index uniqueness and stable-ID null/duplicate counts;
195
+ 6. source hash, parser/driver, package/native versions, and operation timestamp.
196
+
197
+ The bundled `scripts/vector_inventory.py` emits a redacted metadata inventory;
198
+ `scripts/geometry_validity_report.py` adds bounded geometry-state counts.
199
+
200
+ ## Sources (verified 2026-07-23)
201
+
202
+ - [GeoPandas data structures](https://geopandas.org/en/stable/docs/user_guide/data_structures.html).
203
+ - [GeoSeries API](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.html).
204
+ - [GeoDataFrame API](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.html).
205
+ - [Missing and empty geometries](https://geopandas.org/en/stable/docs/user_guide/missing_empty.html).
206
+ - [GeoSeries.intersects alignment](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.intersects.html).
207
+ - [GeoPandas 1.0.0 release and migrations](https://github.com/geopandas/geopandas/releases/tag/v1.0.0) — released 2024-06-24.