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,330 @@
1
+ # Geospatial Data Sources
2
+
3
+ Comprehensive catalog of satellite imagery, vector data, and APIs for geospatial analysis.
4
+
5
+ ## Satellite Data Sources
6
+
7
+ ### Sentinel Missions (ESA)
8
+
9
+ | Platform | Resolution | Coverage | Access |
10
+ |----------|------------|----------|--------|
11
+ | **Sentinel-2** | 10-60m | Global | https://scihub.copernicus.eu/ |
12
+ | **Sentinel-1** | 5-40m (SAR) | Global | https://scihub.copernicus.eu/ |
13
+ | **Sentinel-3** | 300m-1km | Global | https://scihub.copernicus.eu/ |
14
+ | **Sentinel-5P** | Various | Global | https://scihub.copernicus.eu/ |
15
+
16
+ ```python
17
+ # Access via Sentinelsat
18
+ from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
19
+
20
+ api = SentinelAPI('user', 'password', 'https://scihub.copernicus.eu/dhus')
21
+
22
+ # Search
23
+ products = api.query(geojson_to_wkt(aoi_geojson),
24
+ date=('20230101', '20231231'),
25
+ platformname='Sentinel-2',
26
+ cloudcoverpercentage=(0, 20))
27
+
28
+ # Download
29
+ api.download_all(products)
30
+ ```
31
+
32
+ ### Landsat (USGS/NASA)
33
+
34
+ | Platform | Resolution | Coverage | Access |
35
+ |----------|------------|----------|--------|
36
+ | **Landsat 9** | 30m | Global | https://earthexplorer.usgs.gov/ |
37
+ | **Landsat 8** | 30m | Global | https://earthexplorer.usgs.gov/ |
38
+ | **Landsat 7** | 15-60m | Global | https://earthexplorer.usgs.gov/ |
39
+ | **Landsat 5-7** | 30-60m | Global | https://earthexplorer.usgs.gov/ |
40
+
41
+ ### Commercial Satellite Data
42
+
43
+ | Provider | Platform | Resolution | API |
44
+ |----------|----------|------------|-----|
45
+ | **Planet** | PlanetScope, SkySat | 0.5-3m | planet.com |
46
+ | **Maxar** | WorldView, GeoEye | 0.3-1.2m | maxar.com |
47
+ | **Airbus** | Pleiades, SPOT | 0.5-2m | airbus.com |
48
+ | **Capella** | Capella-2 (SAR) | 0.5-1m | capellaspace.com |
49
+
50
+ ## Elevation Data
51
+
52
+ | Dataset | Resolution | Coverage | Source |
53
+ |---------|------------|----------|--------|
54
+ | **AW3D30** | 30m | Global | https://www.eorc.jaxa.jp/ALOS/en/aw3d30/ |
55
+ | **SRTM** | 30m | 56°S-60°N | https://www.usgs.gov/ |
56
+ | **ASTER GDEM** | 30m | 83°S-83°N | https://asterweb.jpl.nasa.gov/ |
57
+ | **Copernicus DEM** | 30m | Global | https://copernicus.eu/ |
58
+ | **ArcticDEM** | 2-10m | Arctic | https://www.pgc.umn.edu/ |
59
+
60
+ ```python
61
+ # Download SRTM via API
62
+ import elevation
63
+
64
+ # Download SRTM 1 arc-second (30m)
65
+ elevation.clip(bounds=(-122.5, 37.7, -122.3, 37.9), output='srtm.tif')
66
+
67
+ # Clean and fill gaps
68
+ elevation.clean('srtm.tif', 'srtm_filled.tif')
69
+ ```
70
+
71
+ ## Land Cover Data
72
+
73
+ | Dataset | Resolution | Classes | Source |
74
+ |---------|------------|---------|--------|
75
+ | **ESA WorldCover** | 10m | 11 classes | https://worldcover2021.esa.int/ |
76
+ | **ESRI Land Cover** | 10m | 10 classes | https://www.esri.com/ |
77
+ | **Copernicus Global** | 100m | 23 classes | https://land.copernicus.eu/ |
78
+ | **MODIS MCD12Q1** | 500m | 17 classes | https://lpdaac.usgs.gov/ |
79
+ | **NLCD (US)** | 30m | 20 classes | https://www.mrlc.gov/ |
80
+
81
+ ## Climate & Weather Data
82
+
83
+ ### Reanalysis Data
84
+
85
+ | Dataset | Resolution | Temporal | Access |
86
+ |---------|------------|----------|--------|
87
+ | **ERA5** | 31km | Hourly (1979+) | https://cds.climate.copernicus.eu/ |
88
+ | **MERRA-2** | 50km | Hourly (1980+) | https://gmao.gsfc.nasa.gov/ |
89
+ | **JRA-55** | 55km | 3-hourly (1958+) | https://jra.kishou.go.jp/ |
90
+
91
+ ```python
92
+ # Download ERA5 via CDS API
93
+ import cdsapi
94
+
95
+ c = cdsapi.Client()
96
+
97
+ c.retrieve(
98
+ 'reanalysis-era5-single-levels',
99
+ {
100
+ 'product_type': 'reanalysis',
101
+ 'variable': '2m_temperature',
102
+ 'year': '2023',
103
+ 'month': '01',
104
+ 'day': '01',
105
+ 'time': '12:00',
106
+ 'area': [37.9, -122.5, 37.7, -122.3],
107
+ 'format': 'netcdf'
108
+ },
109
+ 'era5_temp.nc'
110
+ )
111
+ ```
112
+
113
+ ## OpenStreetMap Data
114
+
115
+ ### Access Methods
116
+
117
+ ```python
118
+ # Via OSMnx
119
+ import osmnx as ox
120
+
121
+ # Download place boundary
122
+ gdf = ox.geocode_to_gdf('San Francisco, CA')
123
+
124
+ # Download street network
125
+ G = ox.graph_from_place('San Francisco, CA', network_type='drive')
126
+
127
+ # Download building footprints
128
+ buildings = ox.geometries_from_place('San Francisco, CA', tags={'building': True})
129
+
130
+ # Via Overpass API
131
+ import requests
132
+
133
+ overpass_url = "http://overpass-api.de/api/interpreter"
134
+ query = """
135
+ [out:json];
136
+ way["highway"](37.7,-122.5,37.9,-122.3);
137
+ out geom;
138
+ """
139
+
140
+ response = requests.get(overpass_url, params={'data': query})
141
+ data = response.json()
142
+ ```
143
+
144
+ ## Vector Data Sources
145
+
146
+ ### Natural Earth
147
+
148
+ ```python
149
+ import geopandas as gpd
150
+
151
+ # Admin boundaries (scale: 10m, 50m, 110m)
152
+ countries = gpd.read_file('https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_0_countries.zip')
153
+ urban_areas = gpd.read_file('https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_urban_areas.zip')
154
+ ports = gpd.read_file('https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_ports.zip')
155
+ ```
156
+
157
+ ### Other Sources
158
+
159
+ | Dataset | Type | Access |
160
+ |---------|------|--------|
161
+ | **GADM** | Admin boundaries | https://gadm.org/ |
162
+ | **HydroSHEDS** | Rivers, basins | https://www.hydrosheds.org/ |
163
+ | **Global Power Plant** | Power plants | https://datasets.wri.org/ |
164
+ | **WorldPop** | Population | https://www.worldpop.org/ |
165
+ | **GPW** | Population | https://sedac.ciesin.columbia.edu/ |
166
+ | **HDX** | Humanitarian data | https://data.humdata.org/ |
167
+
168
+ ## APIs
169
+
170
+ ### Google Maps Platform
171
+
172
+ ```python
173
+ import requests
174
+
175
+ # Geocoding
176
+ url = "https://maps.googleapis.com/maps/api/geocode/json"
177
+ params = {
178
+ 'address': 'Golden Gate Bridge',
179
+ 'key': YOUR_API_KEY
180
+ }
181
+
182
+ response = requests.get(url, params=params)
183
+ data = response.json()
184
+ location = data['results'][0]['geometry']['location']
185
+ ```
186
+
187
+ ### Mapbox
188
+
189
+ ```python
190
+ # Geocoding
191
+ import requests
192
+
193
+ url = "https://api.mapbox.com/geocoding/v5/mapbox.places/Golden%20Gate%20Bridge.json"
194
+ params = {'access_token': YOUR_ACCESS_TOKEN}
195
+
196
+ response = requests.get(url, params=params)
197
+ data = response.json()
198
+ ```
199
+
200
+ ### OpenWeatherMap
201
+
202
+ ```python
203
+ # Current weather
204
+ url = "https://api.openweathermap.org/data/2.5/weather"
205
+ params = {
206
+ 'lat': 37.7,
207
+ 'lon': -122.4,
208
+ 'appid': YOUR_API_KEY
209
+ }
210
+
211
+ response = requests.get(url, params=params)
212
+ weather = response.json()
213
+ ```
214
+
215
+ ## Data APIs in Python
216
+
217
+ ### STAC (SpatioTemporal Asset Catalog)
218
+
219
+ ```python
220
+ import pystac_client
221
+
222
+ # Connect to STAC catalog
223
+ catalog = pystac_client.Client.open("https://earth-search.aws.element84.com/v1")
224
+
225
+ # Search
226
+ search = catalog.search(
227
+ collections=["sentinel-2-l2a"],
228
+ bbox=[-122.5, 37.7, -122.3, 37.9],
229
+ datetime="2023-01-01/2023-12-31",
230
+ query={"eo:cloud_cover": {"lt": 20}}
231
+ )
232
+
233
+ items = search.get_all_items()
234
+ ```
235
+
236
+ ### Planetary Computer
237
+
238
+ ```python
239
+ import planetary_computer
240
+ import pystac_client
241
+
242
+ catalog = pystac_client.Client.open(
243
+ "https://planetarycomputer.microsoft.com/api/stac/v1",
244
+ modifier=planetary_computer.sign_inplace
245
+ )
246
+
247
+ # Search and sign items
248
+ items = catalog.search(...)
249
+ signed_items = [planetary_computer.sign(item) for item in items]
250
+ ```
251
+
252
+ ## Download Scripts
253
+
254
+ ### Automated Download Script
255
+
256
+ ```python
257
+ from sentinelsat import SentinelAPI
258
+ import rasterio
259
+ from rasterio.warp import calculate_default_transform, reproject, Resampling
260
+ import os
261
+
262
+ def download_and_process_sentinel2(aoi, date_range, output_dir):
263
+ """
264
+ Download and process Sentinel-2 imagery.
265
+ """
266
+ # Initialize API
267
+ api = SentinelAPI('user', 'password', 'https://scihub.copernicus.eu/dhus')
268
+
269
+ # Search
270
+ products = api.query(
271
+ aoi,
272
+ date=date_range,
273
+ platformname='Sentinel-2',
274
+ processinglevel='Level-2A',
275
+ cloudcoverpercentage=(0, 20)
276
+ )
277
+
278
+ # Download
279
+ api.download_all(products, directory_path=output_dir)
280
+
281
+ # Process each product
282
+ for product in products:
283
+ product_path = f"{output_dir}/{product['identifier']}.SAFE"
284
+ processed = process_sentinel2_product(product_path)
285
+ save_rgb_composite(processed, f"{output_dir}/{product['identifier']}_rgb.tif")
286
+
287
+ def process_sentinel2_product(product_path):
288
+ """Process Sentinel-2 L2A product."""
289
+ # Find 10m bands (B02, B03, B04, B08)
290
+ bands = {}
291
+ for band_id in ['B02', 'B03', 'B04', 'B08']:
292
+ band_path = find_band_file(product_path, band_id, resolution='10m')
293
+ with rasterio.open(band_path) as src:
294
+ bands[band_id] = src.read(1)
295
+ profile = src.profile
296
+
297
+ # Stack bands
298
+ stacked = np.stack([bands['B04'], bands['B03'], bands['B02']]) # RGB
299
+
300
+ return stacked, profile
301
+ ```
302
+
303
+ ## Data Quality Assessment
304
+
305
+ ```python
306
+ def assess_data_quality(raster_path):
307
+ """
308
+ Assess quality of geospatial raster data.
309
+ """
310
+ import rasterio
311
+ import numpy as np
312
+
313
+ with rasterio.open(raster_path) as src:
314
+ data = src.read()
315
+ profile = src.profile
316
+
317
+ quality_report = {
318
+ 'nodata_percentage': np.sum(data == src.nodata) / data.size * 100,
319
+ 'data_range': (data.min(), data.max()),
320
+ 'mean': np.mean(data),
321
+ 'std': np.std(data),
322
+ 'has_gaps': np.any(data == src.nodata),
323
+ 'projection': profile['crs'],
324
+ 'resolution': (profile['transform'][0], abs(profile['transform'][4]))
325
+ }
326
+
327
+ return quality_report
328
+ ```
329
+
330
+ For data access code examples, see [code-examples.md](code-examples.md).
@@ -0,0 +1,369 @@
1
+ # GIS Software Integration
2
+
3
+ Guide to integrating with major GIS platforms: QGIS, ArcGIS, GRASS GIS, and SAGA GIS.
4
+
5
+ ## QGIS / PyQGIS
6
+
7
+ ### Running Python Scripts in QGIS
8
+
9
+ ```python
10
+ # Processing framework script
11
+ from qgis.core import (QgsProject, QgsVectorLayer, QgsRasterLayer,
12
+ QgsProcessingAlgorithm, QgsProcessingParameterRasterLayer)
13
+
14
+ # Load layers
15
+ vector_layer = QgsVectorLayer("path/to/shapefile.shp", "layer_name", "ogr")
16
+ raster_layer = QgsRasterLayer("path/to/raster.tif", "raster_name", "gdal")
17
+
18
+ # Add to project
19
+ QgsProject.instance().addMapLayer(vector_layer)
20
+ QgsProject.instance().addMapLayer(raster_layer)
21
+
22
+ # Access features
23
+ for feature in vector_layer.getFeatures():
24
+ geom = feature.geometry()
25
+ attrs = feature.attributes()
26
+ ```
27
+
28
+ ### Creating QGIS Processing Scripts
29
+
30
+ ```python
31
+ from qgis.PyQt.QtCore import QCoreApplication
32
+ from qgis.core import (QgsProcessingAlgorithm, QgsProcessingParameterRasterDestination,
33
+ QgsProcessingParameterRasterLayer)
34
+
35
+ class NDVIAlgorithm(QgsProcessingAlgorithm):
36
+ INPUT = 'INPUT'
37
+ OUTPUT = 'OUTPUT'
38
+
39
+ def tr(self, string):
40
+ return QCoreApplication.translate('Processing', string)
41
+
42
+ def createInstance(self):
43
+ return NDVIAlgorithm()
44
+
45
+ def name(self):
46
+ return 'ndvi_calculation'
47
+
48
+ def displayName(self):
49
+ return self.tr('Calculate NDVI')
50
+
51
+ def group(self):
52
+ return self.tr('Raster')
53
+
54
+ def groupId(self):
55
+ return 'raster'
56
+
57
+ def shortHelpString(self):
58
+ return self.tr("Calculate NDVI from Sentinel-2 imagery")
59
+
60
+ def initAlgorithm(self, config=None):
61
+ self.addParameter(QgsProcessingParameterRasterLayer(
62
+ self.INPUT, self.tr('Input Sentinel-2 Raster')))
63
+
64
+ self.addParameter(QgsProcessingParameterRasterDestination(
65
+ self.OUTPUT, self.tr('Output NDVI')))
66
+
67
+ def processAlgorithm(self, parameters, context, feedback):
68
+ raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
69
+
70
+ # NDVI calculation
71
+ # ... implementation ...
72
+
73
+ return {self.OUTPUT: destination}
74
+ ```
75
+
76
+ ### Plugin Development
77
+
78
+ ```python
79
+ # __init__.py
80
+ def classFactory(iface):
81
+ from .my_plugin import MyPlugin
82
+ return MyPlugin(iface)
83
+
84
+ # my_plugin.py
85
+ from qgis.PyQt.QtCore import QSettings
86
+ from qgis.PyQt.QtWidgets import QAction
87
+ from qgis.core import QgsProject
88
+
89
+ class MyPlugin:
90
+ def __init__(self, iface):
91
+ self.iface = iface
92
+
93
+ def initGui(self):
94
+ self.action = QAction("My Plugin", self.iface.mainWindow())
95
+ self.action.triggered.connect(self.run)
96
+ self.iface.addPluginToMenu("My Plugin", self.action)
97
+
98
+ def run(self):
99
+ # Plugin logic here
100
+ pass
101
+
102
+ def unload(self):
103
+ self.iface.removePluginMenu("My Plugin", self.action)
104
+ ```
105
+
106
+ ## ArcGIS / ArcPy
107
+
108
+ ### Basic ArcPy Operations
109
+
110
+ ```python
111
+ import arcpy
112
+
113
+ # Set workspace
114
+ arcpy.env.workspace = "C:/data"
115
+
116
+ # Set output overwrite
117
+ arcpy.env.overwriteOutput = True
118
+
119
+ # Set scratch workspace
120
+ arcpy.env.scratchWorkspace = "C:/data/scratch"
121
+
122
+ # List features
123
+ feature_classes = arcpy.ListFeatureClasses()
124
+ rasters = arcpy.ListRasters()
125
+ ```
126
+
127
+ ### Geoprocessing Workflows
128
+
129
+ ```python
130
+ import arcpy
131
+ from arcpy.sa import *
132
+
133
+ # Check out Spatial Analyst extension
134
+ arcpy.CheckOutExtension("Spatial")
135
+
136
+ # Set environment
137
+ arcpy.env.workspace = "C:/data"
138
+ arcpy.env.cellSize = 10
139
+ arcpy.env.extent = "study_area"
140
+
141
+ # Slope analysis
142
+ out_slope = Slope("dem.tif")
143
+ out_slope.save("slope.tif")
144
+
145
+ # Aspect
146
+ out_aspect = Aspect("dem.tif")
147
+ out_aspect.save("aspect.tif")
148
+
149
+ # Hillshade
150
+ out_hillshade = Hillshade("dem.tif", azimuth=315, altitude=45)
151
+ out_hillshade.save("hillshade.tif")
152
+
153
+ # Viewshed analysis
154
+ out_viewshed = Viewshed("observer_points.shp", "dem.tif", obs_elevation_field="HEIGHT")
155
+ out_viewshed.save("viewshed.tif")
156
+
157
+ # Cost distance
158
+ cost_raster = CostDistance("source.shp", "cost.tif")
159
+ cost_raster.save("cost_distance.tif")
160
+
161
+ # Hydrology: Flow direction
162
+ flow_dir = FlowDirection("dem.tif")
163
+ flow_dir.save("flowdir.tif")
164
+
165
+ # Flow accumulation
166
+ flow_acc = FlowAccumulation(flow_dir)
167
+ flow_acc.save("flowacc.tif")
168
+
169
+ # Stream delineation
170
+ stream = Con(flow_acc > 1000, 1)
171
+ stream_raster = StreamOrder(stream, flow_dir)
172
+ ```
173
+
174
+ ### Vector Analysis
175
+
176
+ ```python
177
+ # Buffer analysis
178
+ arcpy.Buffer_analysis("roads.shp", "roads_buffer.shp", "100 meters")
179
+
180
+ # Spatial join
181
+ arcpy.SpatialJoin_analysis("points.shp", "zones.shp", "points_joined.shp",
182
+ join_operation="JOIN_ONE_TO_ONE",
183
+ match_option="HAVE_THEIR_CENTER_IN")
184
+
185
+ # Dissolve
186
+ arcpy.Dissolve_management("parcels.shp", "parcels_dissolved.shp",
187
+ dissolve_field="OWNER_ID")
188
+
189
+ # Intersect
190
+ arcpy.Intersect_analysis(["layer1.shp", "layer2.shp"], "intersection.shp")
191
+
192
+ # Clip
193
+ arcpy.Clip_analysis("input.shp", "clip_boundary.shp", "output.shp")
194
+
195
+ # Select by location
196
+ arcpy.SelectLayerByLocation_management("points_layer", "HAVE_THEIR_CENTER_IN",
197
+ "polygon_layer")
198
+
199
+ # Feature to raster
200
+ arcpy.FeatureToRaster_conversion("landuse.shp", "LU_CODE", "landuse.tif", 10)
201
+ ```
202
+
203
+ ### ArcGIS Pro Notebooks
204
+
205
+ ```python
206
+ # ArcGIS Pro Jupyter Notebook
207
+ import arcpy
208
+ import pandas as pd
209
+ import matplotlib.pyplot as plt
210
+
211
+ # Use current project's map
212
+ aprx = arcpy.mp.ArcGISProject("CURRENT")
213
+ m = aprx.listMaps()[0]
214
+
215
+ # Get layer
216
+ layer = m.listLayers("Parcels")[0]
217
+
218
+ # Export to spatial dataframe
219
+ sdf = pd.DataFrame.spatial.from_layer(layer)
220
+
221
+ # Plot
222
+ sdf.plot(column='VALUE', cmap='YlOrRd', legend=True)
223
+ plt.show()
224
+
225
+ # Geocode addresses
226
+ locator = "C:/data/locators/composite.locator"
227
+ results = arcpy.geocoding.GeocodeAddresses(
228
+ "addresses.csv", locator, "Address Address",
229
+ None, "geocoded_results.gdb"
230
+ )
231
+ ```
232
+
233
+ ## GRASS GIS
234
+
235
+ ### Python API for GRASS
236
+
237
+ ```python
238
+ import grass.script as gscript
239
+ import grass.script.array as garray
240
+
241
+ # Initialize GRASS session
242
+ gscript.run_command('g.gisenv', set='GISDBASE=/grassdata')
243
+ gscript.run_command('g.gisenv', set='LOCATION_NAME=nc_spm_08')
244
+ gscript.run_command('g.gisenv', set='MAPSET=user1')
245
+
246
+ # Import raster
247
+ gscript.run_command('r.in.gdal', input='elevation.tif', output='elevation')
248
+
249
+ # Import vector
250
+ gscript.run_command('v.in.ogr', input='roads.shp', output='roads')
251
+
252
+ # Get raster info
253
+ info = gscript.raster_info('elevation')
254
+ print(info)
255
+
256
+ # Slope analysis
257
+ gscript.run_command('r.slope.aspect', elevation='elevation',
258
+ slope='slope', aspect='aspect')
259
+
260
+ # Buffer
261
+ gscript.run_command('v.buffer', input='roads', output='roads_buffer',
262
+ distance=100)
263
+
264
+ # Overlay
265
+ gscript.run_command('v.overlay', ainput='zones', binput='roads',
266
+ operator='and', output='zones_roads')
267
+
268
+ # Calculate statistics
269
+ stats = gscript.parse_command('r.univar', map='elevation', flags='g')
270
+ ```
271
+
272
+ ## SAGA GIS
273
+
274
+ ### Using SAGA via Command Line
275
+
276
+ ```python
277
+ import subprocess
278
+ import os
279
+
280
+ # SAGA path
281
+ saga_cmd = "/usr/local/saga/saga_cmd"
282
+
283
+ # Grid Calculus
284
+ def saga_grid_calculus(input1, input2, output, formula):
285
+ cmd = [
286
+ saga_cmd, "grid_calculus", "GridCalculator",
287
+ f"-GRIDS={input1};{input2}",
288
+ f"-RESULT={output}",
289
+ f"-FORMULA={formula}"
290
+ ]
291
+ subprocess.run(cmd)
292
+
293
+ # Slope analysis
294
+ def saga_slope(dem, output_slope):
295
+ cmd = [
296
+ saga_cmd, "ta_morphometry", "SlopeAspectCurvature",
297
+ f"-ELEVATION={dem}",
298
+ f"-SLOPE={output_slope}"
299
+ ]
300
+ subprocess.run(cmd)
301
+
302
+ # Morphometric features
303
+ def saga_morphometry(dem):
304
+ cmd = [
305
+ saga_cmd, "ta_morphometry", "MorphometricFeatures",
306
+ f"-DEM={dem}",
307
+ f"-SLOPE=slope.sgrd",
308
+ f"-ASPECT=aspect.sgrd",
309
+ f"-CURVATURE=curvature.sgrd"
310
+ ]
311
+ subprocess.run(cmd)
312
+
313
+ # Channel network
314
+ def saga_channels(dem, threshold=1000):
315
+ cmd = [
316
+ saga_cmd, "ta_channels", "ChannelNetworkAndDrainageBasins",
317
+ f"-ELEVATION={dem}",
318
+ f"-CHANNELS=channels.shp",
319
+ f"-BASINS=basins.shp",
320
+ f"-THRESHOLD={threshold}"
321
+ ]
322
+ subprocess.run(cmd)
323
+ ```
324
+
325
+ ## Cross-Platform Workflows
326
+
327
+ ### Export QGIS to ArcGIS
328
+
329
+ ```python
330
+ import geopandas as gpd
331
+
332
+ # Read data processed in QGIS
333
+ gdf = gpd.read_file('qgis_output.geojson')
334
+
335
+ # Ensure CRS
336
+ gdf = gdf.to_crs('EPSG:32633')
337
+
338
+ # Export for ArcGIS (File Geodatabase)
339
+ gdf.to_file('arcgis_input.gpkg', driver='GPKG')
340
+ # ArcGIS can read GPKG directly
341
+
342
+ # Or export to shapefile
343
+ gdf.to_file('arcgis_input.shp')
344
+ ```
345
+
346
+ ### Batch Processing
347
+
348
+ ```python
349
+ import geopandas as gpd
350
+ from pathlib import Path
351
+
352
+ # Process multiple files
353
+ input_dir = Path('input')
354
+ output_dir = Path('output')
355
+
356
+ for shp in input_dir.glob('*.shp'):
357
+ gdf = gpd.read_file(shp)
358
+
359
+ # Process
360
+ gdf['area'] = gdf.geometry.area
361
+ gdf['buffered'] = gdf.geometry.buffer(100)
362
+
363
+ # Export for various platforms
364
+ basename = shp.stem
365
+ gdf.to_file(output_dir / f'{basename}_qgis.geojson')
366
+ gdf.to_file(output_dir / f'{basename}_arcgis.shp')
367
+ ```
368
+
369
+ For more GIS-specific examples, see [code-examples.md](code-examples.md).