@dsh-gis/dsh-opengis-skill 0.1.3 → 0.2.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 (97) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +48 -22
  3. package/THIRD_PARTY_NOTICES.md +9 -0
  4. package/adaptations/brutile.md +8 -0
  5. package/adaptations/cesiumjs.md +8 -0
  6. package/adaptations/common.md +16 -0
  7. package/adaptations/deck-gl.md +8 -0
  8. package/adaptations/duckdb-spatial.md +8 -0
  9. package/adaptations/gdal-api.md +8 -0
  10. package/adaptations/gdal.md +8 -0
  11. package/adaptations/geolibre.md +8 -0
  12. package/adaptations/geometry-api-java.md +8 -0
  13. package/adaptations/geometry-api-net.md +8 -0
  14. package/adaptations/geonode.md +8 -0
  15. package/adaptations/geopandas.md +8 -0
  16. package/adaptations/geopipe-agent.md +8 -0
  17. package/adaptations/geoserver-cloud.md +8 -0
  18. package/adaptations/geoserver-rest-api.md +8 -0
  19. package/adaptations/geoserver.md +8 -0
  20. package/adaptations/geotools.md +8 -0
  21. package/adaptations/grass-gis.md +8 -0
  22. package/adaptations/jts.md +8 -0
  23. package/adaptations/kepler-gl.md +8 -0
  24. package/adaptations/leaflet.md +8 -0
  25. package/adaptations/mapbox-gl-js.md +8 -0
  26. package/adaptations/mapserver.md +8 -0
  27. package/adaptations/mapsui.md +8 -0
  28. package/adaptations/nettopologysuite.md +8 -0
  29. package/adaptations/opengis-all.md +8 -0
  30. package/adaptations/opengis-daf.md +8 -0
  31. package/adaptations/opengis-utils-for-java.md +8 -0
  32. package/adaptations/opengis-utils-for-net.md +8 -0
  33. package/adaptations/openlayers.md +8 -0
  34. package/adaptations/pdal.md +8 -0
  35. package/adaptations/postgis.md +8 -0
  36. package/adaptations/proj.md +8 -0
  37. package/adaptations/projnet4geoapi.md +8 -0
  38. package/adaptations/pyqgis.md +8 -0
  39. package/adaptations/qgis-process.md +8 -0
  40. package/adaptations/qgis-server.md +8 -0
  41. package/adaptations/shapely.md +8 -0
  42. package/adaptations/sharpmap.md +8 -0
  43. package/adaptations/spatialite.md +8 -0
  44. package/adaptations/whitebox-tools.md +8 -0
  45. package/assets/brutile/SKILL.md +289 -0
  46. package/assets/cesiumjs/SKILL.md +73 -23
  47. package/assets/deck-gl/SKILL.md +19 -20
  48. package/assets/duckdb-spatial/SKILL.md +370 -0
  49. package/assets/gdal/SKILL.md +50 -21
  50. package/assets/gdal-api/SKILL.md +6 -4
  51. package/assets/geolibre/SKILL.md +364 -0
  52. package/assets/geometry-api-java/SKILL.md +5 -6
  53. package/assets/geometry-api-net/SKILL.md +65 -21
  54. package/assets/geonode/SKILL.md +347 -0
  55. package/assets/geopandas/SKILL.md +17 -15
  56. package/assets/geopipe-agent/SKILL.md +25 -20
  57. package/assets/geoserver/SKILL.md +6 -4
  58. package/assets/geoserver-cloud/SKILL.md +14 -15
  59. package/assets/geoserver-rest-api/SKILL.md +13 -8
  60. package/assets/geotools/SKILL.md +7 -5
  61. package/assets/grass-gis/SKILL.md +19 -20
  62. package/assets/jts/SKILL.md +7 -4
  63. package/assets/kepler-gl/SKILL.md +313 -0
  64. package/assets/leaflet/SKILL.md +41 -19
  65. package/assets/mapbox-gl-js/SKILL.md +18 -19
  66. package/assets/mapserver/SKILL.md +17 -19
  67. package/assets/mapsui/SKILL.md +85 -48
  68. package/assets/nettopologysuite/SKILL.md +91 -20
  69. package/assets/opengis-all/SKILL.md +78 -270
  70. package/assets/opengis-all/reference/data-stages.md +262 -4
  71. package/assets/opengis-daf/SKILL.md +6 -5
  72. package/assets/opengis-utils-for-java/SKILL.md +52 -39
  73. package/assets/opengis-utils-for-java/reference/common-tasks.md +12 -12
  74. package/assets/opengis-utils-for-net/SKILL.md +105 -39
  75. package/assets/opengis-utils-for-net/reference/code-patterns.md +11 -11
  76. package/assets/opengis-utils-for-net/reference/util-classes.md +25 -26
  77. package/assets/openlayers/SKILL.md +66 -9
  78. package/assets/pdal/SKILL.md +21 -17
  79. package/assets/postgis/SKILL.md +61 -11
  80. package/assets/proj/SKILL.md +28 -30
  81. package/assets/projnet4geoapi/SKILL.md +299 -0
  82. package/assets/pyqgis/SKILL.md +28 -20
  83. package/assets/qgis-process/SKILL.md +71 -22
  84. package/assets/qgis-server/SKILL.md +20 -20
  85. package/assets/shapely/SKILL.md +132 -75
  86. package/assets/sharpmap/SKILL.md +93 -50
  87. package/assets/spatialite/SKILL.md +365 -0
  88. package/assets/whitebox-tools/SKILL.md +269 -0
  89. package/lib/adaptations.d.ts +47 -0
  90. package/lib/adaptations.js +268 -0
  91. package/lib/index.d.ts +1 -1
  92. package/lib/index.js +14 -2
  93. package/lib/skill-file.js +31 -7
  94. package/locale/en.json +1 -1
  95. package/locale/zh.json +1 -1
  96. package/package.json +12 -2
  97. package/upstream.json +56 -40
@@ -101,7 +101,7 @@ curl -u admin:geoserver "http://localhost:8080/geoserver/rest/about/version.json
101
101
 
102
102
  ---
103
103
 
104
- > 阶段一(数据获取与信息查询)与阶段二(数据处理与转换)的完整操作手册见 [reference/data-stages.md](reference/data-stages.md)
104
+ > 阶段一(数据获取与信息查询)、阶段二(数据处理与转换)、阶段三(空间分析)的完整操作手册见 [reference/data-stages.md](reference/data-stages.md)
105
105
 
106
106
  ## 核心 API 与命令速查
107
107
 
@@ -119,278 +119,82 @@ curl -u admin:geoserver "http://localhost:8080/geoserver/rest/about/version.json
119
119
 
120
120
  ---
121
121
 
122
- ## 阶段三:空间分析
122
+ ## 阶段三:空间分析(速查)
123
123
 
124
- ### 3.1 缓冲区分析
124
+ | 任务 | 命令入口 |
125
+ |------|----------|
126
+ | 缓冲区 | `qgis_process run native:buffer -- INPUT=... DISTANCE=... OUTPUT=...` |
127
+ | 交集/联合/差集 | `native:intersection / native:union / native:difference` |
128
+ | 融合 | `native:dissolve -- FIELD=...` |
129
+ | 空间连接 | `native:joinattributesbylocation -- PREDICATE=0` |
130
+ | 按属性/位置提取 | `native:extractbyattribute / native:extractbylocation` |
131
+ | 栅格波段运算 | `gdal_calc.py -A nir.tif -B red.tif --calc="(A-B)/(A+B)"` |
132
+ | DEM 分析 | `gdal_contour -i 10 / qgis_process run gdal:slope|aspect|hillshade` |
133
+ | 插值成 DEM | `gdal_grid -a invdist:power=2:zfield=Z` |
134
+ | 栅格矢量互转 | `gdal_polygonize.py / qgis_process run gdal:rasterize` |
135
+ | 地图渲染导出 | `PyQGIS QgsMapRendererSequentialJob / QgsLayoutExporter` |
125
136
 
126
- ```bash
127
- # qgis_process
128
- qgis_process run native:buffer -- \
129
- INPUT=points.shp DISTANCE=1000 SEGMENTS=16 OUTPUT=buffered.gpkg
130
- ```
131
-
132
- ```python
133
- # PyQGIS (processing)
134
- result = processing.run("native:buffer", {
135
- 'INPUT': '/data/roads.shp',
136
- 'DISTANCE': 50,
137
- 'SEGMENTS': 10,
138
- 'DISSOLVE': False,
139
- 'OUTPUT': '/data/roads_buffer.shp'
140
- })
141
- ```
142
-
143
- ```python
144
- # PyQGIS (几何操作)
145
- buffered = geom.buffer(100, 16)
146
- ```
147
-
148
- ```python
149
- # GDAL Python API (OGR 几何)
150
- from osgeo import ogr
151
- pt = ogr.Geometry(ogr.wkbPoint)
152
- pt.SetPoint_2D(0, 116.4, 39.9)
153
- buffer = pt.Buffer(1.0)
154
- ```
155
-
156
- ### 3.2 叠加分析(交集/联合/差集)
157
-
158
- ```bash
159
- # qgis_process — 交集
160
- qgis_process run native:intersection -- \
161
- INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=intersection.shp
162
-
163
- # qgis_process — 联合
164
- qgis_process run native:union -- \
165
- INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=union.shp
166
-
167
- # qgis_process — 差集
168
- qgis_process run native:difference -- \
169
- INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=difference.shp
170
- ```
171
-
172
- ```python
173
- # PyQGIS
174
- result = processing.run("native:intersection", {
175
- 'INPUT': layer1, 'OVERLAY': layer2, 'OUTPUT': 'memory:intersected'
176
- })
177
- ```
178
-
179
- ```python
180
- # PyQGIS 几何级别操作
181
- intersection = geom1.intersection(geom2)
182
- union = geom1.combine(geom2)
183
- difference = geom1.difference(geom2)
184
- sym_diff = geom1.symDifference(geom2)
185
- ```
186
-
187
- ```python
188
- # GDAL OGR 几何级别操作
189
- inter = polygon.Intersection(pt)
190
- united = polygon.Union(pt)
191
- diff = polygon.Difference(pt)
192
- ```
193
-
194
- ### 3.3 融合(Dissolve)
195
-
196
- ```bash
197
- # qgis_process
198
- qgis_process run native:dissolve -- \
199
- INPUT=polygons.shp FIELD=type OUTPUT=dissolved.gpkg
200
- ```
201
-
202
- ```python
203
- # PyQGIS
204
- result = processing.run("native:dissolve", {
205
- 'INPUT': '/data/polygons.shp',
206
- 'FIELD': ['type'],
207
- 'OUTPUT': '/data/dissolved.gpkg'
208
- })
209
- ```
210
-
211
- ### 3.4 空间连接
212
-
213
- ```bash
214
- # qgis_process — 按位置连接属性
215
- qgis_process run native:joinattributesbylocation -- \
216
- INPUT=points.shp JOIN=polygons.shp PREDICATE=0 OUTPUT=joined.shp
217
- ```
218
-
219
- ```python
220
- # PyQGIS
221
- result = processing.run("native:joinattributesbylocation", {
222
- 'INPUT': points_layer,
223
- 'JOIN': polygons_layer,
224
- 'PREDICATE': [0], # 0=相交
225
- 'METHOD': 0, # 0=一对一
226
- 'OUTPUT': 'memory:joined'
227
- })
228
- ```
229
-
230
- ### 3.5 栅格计算(波段运算)
231
-
232
- ```bash
233
- # NDVI 计算
234
- gdal_calc.py -A nir.tif -B red.tif \
235
- --calc="(A-B)/(A+B)" --outfile=ndvi.tif
236
-
237
- # 栅格掩膜
238
- gdal_calc.py -A input.tif --calc="A*(A>100)" \
239
- --outfile=masked.tif --NoDataValue=0
240
-
241
- # 两个栅格平均
242
- gdal_calc.py -A input1.tif -B input2.tif \
243
- --calc="(A+B)/2" --outfile=mean.tif
244
- ```
245
-
246
- ### 3.6 DEM 分析
247
-
248
- ```bash
249
- # 等值线提取
250
- gdal_contour -a elevation dem.tif contours.shp -i 10
251
-
252
- # qgis_process — 坡度分析
253
- qgis_process run gdal:slope -- INPUT=dem.tif OUTPUT=slope.tif
254
-
255
- # qgis_process — 坡向分析
256
- qgis_process run gdal:aspect -- INPUT=dem.tif OUTPUT=aspect.tif
257
-
258
- # qgis_process — 山体阴影
259
- qgis_process run gdal:hillshade -- INPUT=dem.tif OUTPUT=hillshade.tif
260
- ```
261
-
262
- ```python
263
- # PyQGIS — 坡度分析
264
- result = processing.run("gdal:slope", {
265
- 'INPUT': '/data/dem.tif',
266
- 'OUTPUT': '/data/slope.tif'
267
- })
268
- ```
269
-
270
- ### 3.7 散点插值(创建 DEM)
137
+ > 完整的 3.1-3.10 逐项示例(qgis_process、PyQGIS、GDAL Python API 三种写法)见 [reference/data-stages.md](reference/data-stages.md)。
271
138
 
272
- ```bash
273
- # 反距离加权(IDW)插值
274
- gdal_grid -a invdist:power=2:smoothing=0 \
275
- -zfield Z input_points.shp output_dem.tif
276
-
277
- # 指定输出范围和分辨率
278
- gdal_grid -outsize 512 512 -tr 10 10 \
279
- -a average input_points.shp output_dem.tif
280
- ```
281
-
282
- ### 3.8 栅格矢量互转
139
+ > 阶段四(发布 GIS 地图服务)的完整 GeoServer REST 操作见 [reference/data-stages.md](reference/data-stages.md)
140
+ > 端到端工作流示例、内置算法速查、GDAL 命令速查、数据格式与环境变量见 [reference/workflow-cheatsheets.md](reference/workflow-cheatsheets.md)
283
141
 
284
- ```bash
285
- # 栅格转矢量(多边形化)
286
- gdal_polygonize.py input.tif output.shp
142
+ ## 典型工作流
287
143
 
288
- # qgis_process
289
- qgis_process run gdal:polygonize -- INPUT=input.tif OUTPUT=output.shp
144
+ ### 端到端:Shapefile → 缓冲分析 → GeoServer 发布 → Web 预览
290
145
 
291
- # 矢量转栅格
292
- qgis_process run gdal:rasterize -- \
293
- INPUT=input.shp FIELD=value OUTPUT=output.tif
294
- ```
146
+ 输入 `data/roads.shp`(EPSG:4326),输出 `http://localhost:8080/geoserver/wms` 上可用的图层 `demo:roads_buffer`。
295
147
 
296
- ### 3.9 空间查询与过滤
148
+ 1. **探索数据**:`ogrinfo -so -al data/roads.shp` 确认要素数与 CRS
149
+ 2. **统一格式与坐标系**:`ogr2ogr -t_srs EPSG:3857 roads_3857.gpkg data/roads.shp`
150
+ 3. **空间分析**:`qgis_process run native:buffer -- INPUT=roads_3857.gpkg DISTANCE=500 OUTPUT=roads_buffer.gpkg`
151
+ 4. **验证结果**:`ogrinfo -so roads_buffer.gpkg roads_buffer` 核对方框与要素数
152
+ 5. **发布服务**:GeoServer REST 建工作空间 → 上传 GeoPackage → 发布图层
153
+ 6. **前端预览**:OpenLayers `TileWMS` 指向 `/geoserver/wms`,`LAYERS: 'demo:roads_buffer'`
297
154
 
298
155
  ```bash
299
- # ogr2ogr — 属性过滤
300
- ogr2ogr output.shp input.shp -where "population > 1000000"
301
-
302
- # ogr2ogr — 空间过滤
303
- ogr2ogr output.shp input.shp -spat 116.0 39.5 117.0 40.5
304
-
305
- # qgis_process — 按属性提取
306
- qgis_process run native:extractbyattribute -- \
307
- INPUT=input.shp FIELD=type OPERATOR=0 VALUE=road OUTPUT=roads.shp
308
-
309
- # qgis_process — 按位置提取
310
- qgis_process run native:extractbylocation -- \
311
- INPUT=points.shp INTERSECT=boundary.shp PREDICATE=0 OUTPUT=extracted.shp
312
- ```
313
-
314
- ```python
315
- # PyQGIS — 要素查询
316
- from qgis.core import QgsFeatureRequest, QgsRectangle
317
-
318
- # 属性过滤
319
- request = QgsFeatureRequest().setFilterExpression('"population" > 10000')
320
- for feature in layer.getFeatures(request):
321
- print(feature["name"])
322
-
323
- # 空间范围过滤
324
- rect = QgsRectangle(116.0, 39.0, 117.0, 40.0)
325
- request = QgsFeatureRequest().setFilterRect(rect)
326
- for feature in layer.getFeatures(request):
327
- print(feature.id())
328
- ```
329
-
330
- ```python
331
- # GDAL Python API — 空间过滤 + 属性过滤
332
- from osgeo import ogr
333
-
334
- ds = ogr.Open("input.shp")
335
- layer = ds.GetLayer(0)
336
- layer.SetSpatialFilterRect(116.0, 39.5, 117.0, 40.5)
337
- layer.SetAttributeFilter("POPULATION > 1000000")
338
-
339
- for feature in layer:
340
- print(feature.GetField("NAME"))
341
- ds = None
342
- ```
343
-
344
- ### 3.10 地图渲染与导出
345
-
346
- ```python
347
- # PyQGIS — 渲染为 PNG
348
- from qgis.core import QgsMapSettings, QgsMapRendererSequentialJob
349
- from qgis.PyQt.QtCore import QSize
350
-
351
- settings = QgsMapSettings()
352
- settings.setLayers([layer])
353
- settings.setDestinationCrs(layer.crs())
354
- settings.setExtent(layer.extent())
355
- settings.setOutputSize(QSize(1920, 1080))
356
-
357
- job = QgsMapRendererSequentialJob(settings)
358
- job.start()
359
- job.waitForFinished()
360
- job.renderedImage().save("/data/map_output.png")
156
+ # 1~4:本地分析与验证
157
+ ogrinfo -so -al data/roads.shp
158
+ ogr2ogr -t_srs EPSG:3857 roads_3857.gpkg data/roads.shp
159
+ QT_QPA_PLATFORM=offscreen qgis_process run native:buffer -- \
160
+ INPUT=roads_3857.gpkg DISTANCE=500 SEGMENTS=8 OUTPUT=roads_buffer.gpkg
161
+ ogrinfo -so roads_buffer.gpkg roads_buffer
162
+
163
+ # 5:发布(GeoServer 3.0.2,默认 admin/geoserver)
164
+ BASE=http://localhost:8080/geoserver/rest
165
+ curl -u admin:geoserver -X POST "$BASE/workspaces" \
166
+ -H 'Content-Type: application/json' \
167
+ -d '{"workspace":{"name":"demo"}}'
168
+
169
+ curl -u admin:geoserver -X PUT "$BASE/workspaces/demo/datastores/roads/file.gpkg?configure=all" \
170
+ -H 'Content-Type: application/geopackage+sqlite3' \
171
+ --data-binary @roads_buffer.gpkg
172
+
173
+ # 6:回读确认图层已发布
174
+ curl -u admin:geoserver "$BASE/layers/demo:roads_buffer.json"
361
175
  ```
362
176
 
363
- ```python
364
- # PyQGIS — 导出 PDF
365
- from qgis.core import QgsProject, QgsPrintLayout, QgsLayoutItemMap, QgsLayoutExporter
366
-
367
- project = QgsProject.instance()
368
- layout = QgsPrintLayout(project)
369
- layout.initializeDefaults()
370
-
371
- map_item = QgsLayoutItemMap(layout)
372
- map_item.setRect(20, 20, 200, 150)
373
- map_item.setExtent(layer.extent())
374
- map_item.setLayers([layer])
375
- layout.addLayoutItem(map_item)
376
-
377
- exporter = QgsLayoutExporter(layout)
378
- exporter.exportToPdf("/data/output.pdf", QgsLayoutExporter.PdfExportSettings())
177
+ ```js
178
+ // 6:OpenLayers 前端预览
179
+ import Map from 'ol/Map.js';
180
+ import View from 'ol/View.js';
181
+ import TileLayer from 'ol/layer/Tile.js';
182
+ import TileWMS from 'ol/source/TileWMS.js';
183
+
184
+ new Map({
185
+ target: 'map',
186
+ layers: [new TileLayer({
187
+ source: new TileWMS({
188
+ url: 'http://localhost:8080/geoserver/wms',
189
+ params: { LAYERS: 'demo:roads_buffer', TILED: true }
190
+ })
191
+ })],
192
+ view: new View({ center: [12968000, 4863000], zoom: 12 })
193
+ });
379
194
  ```
380
195
 
381
- ---
382
-
383
- > 阶段四(发布 GIS 地图服务)的完整 GeoServer REST 操作见 [reference/data-stages.md](reference/data-stages.md)
384
- > 端到端工作流示例、内置算法速查、GDAL 命令速查、数据格式与环境变量见 [reference/workflow-cheatsheets.md](reference/workflow-cheatsheets.md)
385
-
386
- ## 典型工作流
196
+ **验收**:`curl -u admin:geoserver .../layers/demo:roads_buffer.json` 返回 200 且含 `"enabled": true`;前端地图能看到缓冲区图形。任一步失败都不要继续后续阶段——先修当前阶段的产物。
387
197
 
388
- 1. **探索数据**:`ogrinfo -json` / `gdalinfo -json` — 获取结构化元数据
389
- 2. **格式转换**:`ogr2ogr` / `gdal_translate` — 统一数据格式
390
- 3. **坐标统一**:`ogr2ogr -t_srs` / `gdalwarp -t_srs` — 统一坐标系
391
- 4. **空间分析**:`qgis_process run` / `processing.run()` — 执行分析算法
392
- 5. **结果验证**:`ogrinfo -json` / `gdalinfo -json` — 验证输出
393
- 6. **发布服务**:GeoServer REST API — 上传并发布地图服务
394
198
 
395
199
  ---
396
200
 
@@ -407,17 +211,6 @@ exporter.exportToPdf("/data/output.pdf", QgsLayoutExporter.PdfExportSettings())
407
211
 
408
212
  ---
409
213
 
410
- ## DeepSeek Harness 使用建议
411
-
412
- - **加载与引用**:用 `skill("opengis-all")` 加载(用户也可输入 `/opengis-all`);本页是阶段索引,详细步骤在 `reference/data-stages.md` 与 `reference/workflow-cheatsheets.md`,按当前阶段 `read`,不要一次全读。
413
- - **执行环境**:命令交给 dsh 的 shell 工具(Windows 用 `pwsh`;仅暴露 `run_code` 的会话在 `tools.pwsh` 中执行)。示例是 Linux/bash 写法,按平台改写 `apt`、`/tmp`、`export` 与反引号;Windows 路径加引号。
414
- - **先探测工具链**:`gdalinfo --version`、`qgis_process --version`、`python3 -c "from osgeo import gdal; print(gdal.VersionInfo())"`、`curl -u admin:geoserver "http://localhost:8080/geoserver/rest/about/version.json"`;缺哪个阶段就加载相邻技能(如 `skill("gdal")`、`skill("qgis-process")`)。
415
- - **分阶段交付**:每阶段产物落盘到工作区(GeoPackage/COG/GeoJSON),下一阶段只读取产物;先用 `ogrinfo -so`、`gdalinfo -json` 看摘要,不要把大文件或大段输出贴进上下文。
416
- - **验证**:转换后重新打开结果核对 CRS、范围、要素数;发布后用 `curl` 回读 REST 资源或 `GetCapabilities`;无显示器环境设置 `QT_QPA_PLATFORM=offscreen`;`qgis_process` 参数先用 `qgis_process help <id> --json` 确认。
417
- - **安全**:`gdal_edit.py`、覆盖输出、GeoServer `?recurse=true` 删除均不可逆;先备份并确认路径,安装 GDAL/QGIS、启动服务或使用数据库凭据前先征得用户同意。
418
-
419
- ---
420
-
421
214
  ## 常见问题
422
215
 
423
216
  | 问题 | 解决 |
@@ -432,6 +225,17 @@ exporter.exportToPdf("/data/output.pdf", QgsLayoutExporter.PdfExportSettings())
432
225
 
433
226
  ---
434
227
 
228
+ ## AI 使用建议
229
+
230
+ - **本技能的组织**:主文件给高频用法,完整参数表与高级示例在 `reference/data-stages.md`、`reference/workflow-cheatsheets.md`,需要时再展开;示例工程与生成的数据写到工作目录,不要改动技能目录本身。
231
+ - **执行环境**:命令在终端 / shell 中执行(Windows 用 PowerShell)。示例是 Linux/bash 写法,按平台改写 `apt`、`/tmp`、`export` 与反引号;Windows 路径加引号。
232
+ - **先探测工具链**:`gdalinfo --version`、`qgis_process --version`、`python3 -c "from osgeo import gdal; print(gdal.VersionInfo())"`、`curl -u admin:geoserver "http://localhost:8080/geoserver/rest/about/version.json"`;缺哪个阶段就加载相邻技能(如 `gis/gdal`、`gis/qgis-process`)。
233
+ - **分阶段交付**:每阶段产物落盘到工作区(GeoPackage/COG/GeoJSON),下一阶段只读取产物;先用 `ogrinfo -so`、`gdalinfo -json` 看摘要,不要把大文件或大段输出贴进上下文。
234
+ - **验证**:转换后重新打开结果核对 CRS、范围、要素数;发布后用 `curl` 回读 REST 资源或 `GetCapabilities`;无显示器环境设置 `QT_QPA_PLATFORM=offscreen`;`qgis_process` 参数先用 `qgis_process help <id> --json` 确认。
235
+ - **安全**:`gdal_edit.py`、覆盖输出、GeoServer `?recurse=true` 删除均不可逆;先备份并确认路径,安装 GDAL/QGIS、启动服务或使用数据库凭据前先征得用户同意。
236
+
237
+ ---
238
+
435
239
  ## 相关技能
436
240
 
437
241
  - **gdal** — GDAL 命令行工具:[../gdal/SKILL.md](../gdal/SKILL.md)
@@ -442,6 +246,10 @@ exporter.exportToPdf("/data/output.pdf", QgsLayoutExporter.PdfExportSettings())
442
246
  - **geopipe-agent** — AI 驱动的 GIS 流水线:[../geopipe-agent/SKILL.md](../geopipe-agent/SKILL.md)
443
247
  - **openlayers** — 前端 2D 地图可视化:[../openlayers/SKILL.md](../openlayers/SKILL.md)
444
248
  - **cesiumjs** — 前端 3D 地球可视化:[../cesiumjs/SKILL.md](../cesiumjs/SKILL.md)
249
+ - **duckdb-spatial** — 用 SQL 直接分析 Shapefile/GeoParquet:[../duckdb-spatial/SKILL.md](../duckdb-spatial/SKILL.md)
250
+ - **geolibre** — 浏览器/桌面里做 GIS,无需服务端:[../geolibre/SKILL.md](../geolibre/SKILL.md)
251
+ - **whitebox-tools** — 地形/水文/LiDAR 批量分析:[../whitebox-tools/SKILL.md](../whitebox-tools/SKILL.md)
252
+ - **pdal** — 点云 LAS/LAZ 处理与 DEM 生成:[../pdal/SKILL.md](../pdal/SKILL.md)
445
253
 
446
254
  ## 参考资源
447
255
 
@@ -1,6 +1,6 @@
1
1
  # OpenGIS Data Pipeline Stages Reference
2
2
 
3
- Stage 1 (data acquisition/query), stage 2 (processing/conversion) and stage 4 (GeoServer publishing) split from SKILL.md.
3
+ Stage 1 (data acquisition/query), stage 2 (processing/conversion), stage 3 (spatial analysis) and stage 4 (GeoServer publishing) split from SKILL.md.
4
4
 
5
5
  ---
6
6
 
@@ -435,6 +435,267 @@ gdal_edit.py -mo DATUM=WGS84 -mo SOURCE=USGS input.tif
435
435
 
436
436
  ---
437
437
 
438
+ ## 阶段三:空间分析
439
+
440
+ ### 3.1 缓冲区分析
441
+
442
+ ```bash
443
+ # qgis_process
444
+ qgis_process run native:buffer -- \
445
+ INPUT=points.shp DISTANCE=1000 SEGMENTS=16 OUTPUT=buffered.gpkg
446
+ ```
447
+
448
+ ```python
449
+ # PyQGIS (processing)
450
+ result = processing.run("native:buffer", {
451
+ 'INPUT': '/data/roads.shp',
452
+ 'DISTANCE': 50,
453
+ 'SEGMENTS': 10,
454
+ 'DISSOLVE': False,
455
+ 'OUTPUT': '/data/roads_buffer.shp'
456
+ })
457
+ ```
458
+
459
+ ```python
460
+ # PyQGIS (几何操作)
461
+ buffered = geom.buffer(100, 16)
462
+ ```
463
+
464
+ ```python
465
+ # GDAL Python API (OGR 几何)
466
+ from osgeo import ogr
467
+ pt = ogr.Geometry(ogr.wkbPoint)
468
+ pt.SetPoint_2D(0, 116.4, 39.9)
469
+ buffer = pt.Buffer(1.0)
470
+ ```
471
+
472
+ ### 3.2 叠加分析(交集/联合/差集)
473
+
474
+ ```bash
475
+ # qgis_process — 交集
476
+ qgis_process run native:intersection -- \
477
+ INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=intersection.shp
478
+
479
+ # qgis_process — 联合
480
+ qgis_process run native:union -- \
481
+ INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=union.shp
482
+
483
+ # qgis_process — 差集
484
+ qgis_process run native:difference -- \
485
+ INPUT=layer1.shp OVERLAY=layer2.shp OUTPUT=difference.shp
486
+ ```
487
+
488
+ ```python
489
+ # PyQGIS
490
+ result = processing.run("native:intersection", {
491
+ 'INPUT': layer1, 'OVERLAY': layer2, 'OUTPUT': 'memory:intersected'
492
+ })
493
+ ```
494
+
495
+ ```python
496
+ # PyQGIS 几何级别操作
497
+ intersection = geom1.intersection(geom2)
498
+ union = geom1.combine(geom2)
499
+ difference = geom1.difference(geom2)
500
+ sym_diff = geom1.symDifference(geom2)
501
+ ```
502
+
503
+ ```python
504
+ # GDAL OGR 几何级别操作
505
+ inter = polygon.Intersection(pt)
506
+ united = polygon.Union(pt)
507
+ diff = polygon.Difference(pt)
508
+ ```
509
+
510
+ ### 3.3 融合(Dissolve)
511
+
512
+ ```bash
513
+ # qgis_process
514
+ qgis_process run native:dissolve -- \
515
+ INPUT=polygons.shp FIELD=type OUTPUT=dissolved.gpkg
516
+ ```
517
+
518
+ ```python
519
+ # PyQGIS
520
+ result = processing.run("native:dissolve", {
521
+ 'INPUT': '/data/polygons.shp',
522
+ 'FIELD': ['type'],
523
+ 'OUTPUT': '/data/dissolved.gpkg'
524
+ })
525
+ ```
526
+
527
+ ### 3.4 空间连接
528
+
529
+ ```bash
530
+ # qgis_process — 按位置连接属性
531
+ qgis_process run native:joinattributesbylocation -- \
532
+ INPUT=points.shp JOIN=polygons.shp PREDICATE=0 OUTPUT=joined.shp
533
+ ```
534
+
535
+ ```python
536
+ # PyQGIS
537
+ result = processing.run("native:joinattributesbylocation", {
538
+ 'INPUT': points_layer,
539
+ 'JOIN': polygons_layer,
540
+ 'PREDICATE': [0], # 0=相交
541
+ 'METHOD': 0, # 0=一对一
542
+ 'OUTPUT': 'memory:joined'
543
+ })
544
+ ```
545
+
546
+ ### 3.5 栅格计算(波段运算)
547
+
548
+ ```bash
549
+ # NDVI 计算
550
+ gdal_calc.py -A nir.tif -B red.tif \
551
+ --calc="(A-B)/(A+B)" --outfile=ndvi.tif
552
+
553
+ # 栅格掩膜
554
+ gdal_calc.py -A input.tif --calc="A*(A>100)" \
555
+ --outfile=masked.tif --NoDataValue=0
556
+
557
+ # 两个栅格平均
558
+ gdal_calc.py -A input1.tif -B input2.tif \
559
+ --calc="(A+B)/2" --outfile=mean.tif
560
+ ```
561
+
562
+ ### 3.6 DEM 分析
563
+
564
+ ```bash
565
+ # 等值线提取
566
+ gdal_contour -a elevation dem.tif contours.shp -i 10
567
+
568
+ # qgis_process — 坡度分析
569
+ qgis_process run gdal:slope -- INPUT=dem.tif OUTPUT=slope.tif
570
+
571
+ # qgis_process — 坡向分析
572
+ qgis_process run gdal:aspect -- INPUT=dem.tif OUTPUT=aspect.tif
573
+
574
+ # qgis_process — 山体阴影
575
+ qgis_process run gdal:hillshade -- INPUT=dem.tif OUTPUT=hillshade.tif
576
+ ```
577
+
578
+ ```python
579
+ # PyQGIS — 坡度分析
580
+ result = processing.run("gdal:slope", {
581
+ 'INPUT': '/data/dem.tif',
582
+ 'OUTPUT': '/data/slope.tif'
583
+ })
584
+ ```
585
+
586
+ ### 3.7 散点插值(创建 DEM)
587
+
588
+ ```bash
589
+ # 反距离加权(IDW)插值
590
+ gdal_grid -a invdist:power=2:smoothing=0 \
591
+ -zfield Z input_points.shp output_dem.tif
592
+
593
+ # 指定输出范围和分辨率
594
+ gdal_grid -outsize 512 512 -tr 10 10 \
595
+ -a average input_points.shp output_dem.tif
596
+ ```
597
+
598
+ ### 3.8 栅格矢量互转
599
+
600
+ ```bash
601
+ # 栅格转矢量(多边形化)
602
+ gdal_polygonize.py input.tif output.shp
603
+
604
+ # qgis_process
605
+ qgis_process run gdal:polygonize -- INPUT=input.tif OUTPUT=output.shp
606
+
607
+ # 矢量转栅格
608
+ qgis_process run gdal:rasterize -- \
609
+ INPUT=input.shp FIELD=value OUTPUT=output.tif
610
+ ```
611
+
612
+ ### 3.9 空间查询与过滤
613
+
614
+ ```bash
615
+ # ogr2ogr — 属性过滤
616
+ ogr2ogr output.shp input.shp -where "population > 1000000"
617
+
618
+ # ogr2ogr — 空间过滤
619
+ ogr2ogr output.shp input.shp -spat 116.0 39.5 117.0 40.5
620
+
621
+ # qgis_process — 按属性提取
622
+ qgis_process run native:extractbyattribute -- \
623
+ INPUT=input.shp FIELD=type OPERATOR=0 VALUE=road OUTPUT=roads.shp
624
+
625
+ # qgis_process — 按位置提取
626
+ qgis_process run native:extractbylocation -- \
627
+ INPUT=points.shp INTERSECT=boundary.shp PREDICATE=0 OUTPUT=extracted.shp
628
+ ```
629
+
630
+ ```python
631
+ # PyQGIS — 要素查询
632
+ from qgis.core import QgsFeatureRequest, QgsRectangle
633
+
634
+ # 属性过滤
635
+ request = QgsFeatureRequest().setFilterExpression('"population" > 10000')
636
+ for feature in layer.getFeatures(request):
637
+ print(feature["name"])
638
+
639
+ # 空间范围过滤
640
+ rect = QgsRectangle(116.0, 39.0, 117.0, 40.0)
641
+ request = QgsFeatureRequest().setFilterRect(rect)
642
+ for feature in layer.getFeatures(request):
643
+ print(feature.id())
644
+ ```
645
+
646
+ ```python
647
+ # GDAL Python API — 空间过滤 + 属性过滤
648
+ from osgeo import ogr
649
+
650
+ ds = ogr.Open("input.shp")
651
+ layer = ds.GetLayer(0)
652
+ layer.SetSpatialFilterRect(116.0, 39.5, 117.0, 40.5)
653
+ layer.SetAttributeFilter("POPULATION > 1000000")
654
+
655
+ for feature in layer:
656
+ print(feature.GetField("NAME"))
657
+ ds = None
658
+ ```
659
+
660
+ ### 3.10 地图渲染与导出
661
+
662
+ ```python
663
+ # PyQGIS — 渲染为 PNG
664
+ from qgis.core import QgsMapSettings, QgsMapRendererSequentialJob
665
+ from qgis.PyQt.QtCore import QSize
666
+
667
+ settings = QgsMapSettings()
668
+ settings.setLayers([layer])
669
+ settings.setDestinationCrs(layer.crs())
670
+ settings.setExtent(layer.extent())
671
+ settings.setOutputSize(QSize(1920, 1080))
672
+
673
+ job = QgsMapRendererSequentialJob(settings)
674
+ job.start()
675
+ job.waitForFinished()
676
+ job.renderedImage().save("/data/map_output.png")
677
+ ```
678
+
679
+ ```python
680
+ # PyQGIS — 导出 PDF
681
+ from qgis.core import QgsProject, QgsPrintLayout, QgsLayoutItemMap, QgsLayoutExporter
682
+
683
+ project = QgsProject.instance()
684
+ layout = QgsPrintLayout(project)
685
+ layout.initializeDefaults()
686
+
687
+ map_item = QgsLayoutItemMap(layout)
688
+ map_item.setRect(20, 20, 200, 150)
689
+ map_item.setExtent(layer.extent())
690
+ map_item.setLayers([layer])
691
+ layout.addLayoutItem(map_item)
692
+
693
+ exporter = QgsLayoutExporter(layout)
694
+ exporter.exportToPdf("/data/output.pdf", QgsLayoutExporter.PdfExportSettings())
695
+ ```
696
+
697
+ ---
698
+
438
699
  ## 阶段四:发布 GIS 地图服务(GeoServer REST API)
439
700
 
440
701
  **基础 URL:** `http://{host}:{port}/geoserver/rest`
@@ -603,6 +864,3 @@ curl -u admin:geoserver -XPOST \
603
864
  | 清空图层缓存 | POST | `/gwc/rest/seed/{layer}.json` |
604
865
  | 查看缓存任务 | GET | `/gwc/rest/seed/{layer}.json` |
605
866
  | 批量截断 | POST | `/gwc/rest/masstruncate` |
606
-
607
- ---
608
-