@dsh-gis/dsh-opengis-skill 0.1.0 → 0.1.2

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 (37) hide show
  1. package/.editorconfig +19 -0
  2. package/CHANGELOG.md +96 -0
  3. package/LICENSE +21 -21
  4. package/README.md +91 -30
  5. package/THIRD_PARTY_NOTICES.md +37 -10
  6. package/assets/gdal/reference/raster-tools.md +538 -538
  7. package/assets/gdal/reference/vector-tools.md +149 -149
  8. package/assets/gdal-api/reference/raster-api.md +424 -424
  9. package/assets/gdal-api/reference/vector-api.md +724 -724
  10. package/assets/geometry-api-net/reference/geometry-types.md +243 -243
  11. package/assets/geopandas/reference/core-api.md +221 -221
  12. package/assets/geotools/reference/raster-rendering.md +108 -108
  13. package/assets/geotools/reference/vector-io.md +149 -149
  14. package/assets/jts/reference/geometry-operations.md +303 -303
  15. package/assets/mapsui/SKILL.md +283 -283
  16. package/assets/opengis-all/reference/data-stages.md +608 -608
  17. package/assets/opengis-all/reference/workflow-cheatsheets.md +324 -324
  18. package/assets/opengis-utils-for-java/reference/common-tasks.md +384 -384
  19. package/assets/opengis-utils-for-net/reference/code-patterns.md +124 -124
  20. package/assets/opengis-utils-for-net/reference/util-classes.md +291 -291
  21. package/assets/pyqgis/reference/processing-rendering.md +292 -292
  22. package/assets/pyqgis/reference/vector-raster-layers.md +318 -318
  23. package/assets/qgis-process/SKILL.md +414 -414
  24. package/assets/qgis-process/reference/algorithm-cheatsheet.md +194 -194
  25. package/assets/shapely/reference/operations-reference.md +199 -199
  26. package/cordis.patch.yml +6 -3
  27. package/lib/catalog.d.ts +50 -0
  28. package/lib/catalog.js +238 -0
  29. package/lib/index.d.ts +47 -6
  30. package/lib/index.js +32 -44
  31. package/lib/markdown-links.d.ts +11 -0
  32. package/lib/markdown-links.js +103 -0
  33. package/lib/skill-file.js +104 -17
  34. package/locale/en.json +1 -1
  35. package/locale/zh.json +1 -1
  36. package/package.json +11 -5
  37. package/upstream.json +64 -2
@@ -1,538 +1,538 @@
1
- # GDAL Raster Tools Reference
2
-
3
- > 这是 [../SKILL.md](../SKILL.md) 的补充文件,收录 GDAL 栅格工具的完整参数表与示例。
4
-
5
- ---
6
-
7
- ## gdalinfo — Raster Info Query
8
-
9
- **描述**: 显示栅格数据的元数据、地理信息、波段信息、统计值。
10
-
11
- **基本用法**:
12
-
13
- ```bash
14
- # 基本信息
15
- gdalinfo dem.tif
16
-
17
- # JSON 输出(GDAL 3.1+)
18
- gdalinfo -json dem.tif
19
-
20
- # 仅显示摘要(不显示统计值)
21
- gdalinfo -checksum dem.tif
22
-
23
- # 显示统计信息
24
- gdalinfo -stats dem.tif
25
-
26
- # 显示色表
27
- gdalinfo -checksum terrain.tif | grep -A5 "Color Table"
28
-
29
- # 计算直方图
30
- gdalinfo -hist image.tif
31
- ```
32
-
33
- **关键参数**:
34
-
35
- | 参数 | 说明 |
36
- |------|------|
37
- | `-json` | JSON 格式输出 |
38
- | `-stats` | 计算并显示统计信息 |
39
- | `-approx_stats` | 近似统计(快速) |
40
- | `-checksum` | 显示校验和 |
41
- | `-hist` | 显示直方图 |
42
- | `-mm` | 显示最小/最大值 |
43
- | `-noct` | 不显示色表 |
44
-
45
- **示例**:
46
-
47
- ```bash
48
- # 获取 DEM 范围和分辨率
49
- gdalinfo dem.tif | grep -E "^Size|^Upper Left|Corner|Pixel Size"
50
-
51
- # 获取 JSON 格式地理信息
52
- gdalinfo -json image.tif | jq '.coordinateSystem'
53
-
54
- # 检查数据类型和波段数
55
- gdalinfo image.tif | grep "Type:\|Band"
56
- ```
57
-
58
- ---
59
-
60
- ## gdal_translate — Format Conversion and Resampling
61
-
62
- **描述**: 将栅格文件转换为不同格式、调整分辨率、裁剪、创建缩放图等。
63
-
64
- **基本用法**:
65
-
66
- ```bash
67
- # 格式转换(GeoTIFF → PNG)
68
- gdal_translate input.tif output.png
69
-
70
- # 格式转换(带压缩)
71
- gdal_translate -co COMPRESS=DEFLATE input.tif output.tif
72
-
73
- # 重采样(降低分辨率)
74
- gdal_translate -outsize 50% 50% input.tif output.tif
75
-
76
- # 重采样到指定分辨率
77
- gdal_translate -tr 10 10 input.tif output.tif
78
-
79
- # 裁剪到范围
80
- gdal_translate -projwin -180 90 -170 80 input.tif output.tif
81
-
82
- # 创建缩放版本(1/4 大小)
83
- gdal_translate -outsize 25% 25% input.tif thumbnail.tif
84
-
85
- # 转换数据类型
86
- gdal_translate -ot Byte input.tif output.tif
87
-
88
- # 设置 NoData 值
89
- gdal_translate -a_nodata 0 input.tif output.tif
90
-
91
- # 只提取特定波段
92
- gdal_translate -b 1 rgb.tif red.tif
93
- ```
94
-
95
- **关键参数**:
96
-
97
- | 参数 | 说明 |
98
- |------|------|
99
- | `-of <format>` | 输出格式 |
100
- | `-outsize <xsize> <ysize>` | 输出大小(像素或百分比) |
101
- | `-tr <xres> <yres>` | 目标分辨率 |
102
- | `-projwin <ulx> <uly> <lrx> <lry>` | 裁剪范围 |
103
- | `-ot <datatype>` | 输出数据类型 |
104
- | `-b <band>` | 选择波段 |
105
- | `-a_nodata <value>` | 设置 NoData 值 |
106
- | `-co <NAME>=<VALUE>` | 创建选项(如压缩) |
107
-
108
- ---
109
-
110
- ## gdalwarp — Reprojection and Mosaicking
111
-
112
- **描述**: 重投影栅格、裁剪、融合多个栅格(镶嵌)、重新采样。
113
-
114
- **基本用法**:
115
-
116
- ```bash
117
- # 重投影(UTM 50N → WGS84)
118
- gdalwarp -t_srs EPSG:4326 input_utm.tif output_wgs84.tif
119
-
120
- # 镶嵌多个文件
121
- gdalwarp input1.tif input2.tif input3.tif output_mosaic.tif
122
-
123
- # 重采样并重投影
124
- gdalwarp -tr 30 30 -t_srs EPSG:4326 input.tif output.tif
125
-
126
- # 裁剪(指定范围)
127
- gdalwarp -te -10 40 10 50 input.tif output.tif
128
-
129
- # 用矢量边界裁剪
130
- gdalwarp -cutline clip_boundary.shp -crop_to_cutline input.tif output.tif
131
-
132
- # 最近邻重采样(用于分类数据)
133
- gdalwarp -r near input.tif output.tif
134
-
135
- # 双线性插值(用于连续数据)
136
- gdalwarp -r bilinear input.tif output.tif
137
-
138
- # 立方卷积插值(高质量)
139
- gdalwarp -r cubic input.tif output.tif
140
-
141
- # 多线程处理
142
- gdalwarp -wm 512 -co COMPRESS=DEFLATE input.tif output.tif
143
- ```
144
-
145
- **关键参数**:
146
-
147
- | 参数 | 说明 |
148
- |------|------|
149
- | `-t_srs <EPSG>` | 目标坐标参考系 |
150
- | `-s_srs <EPSG>` | 源坐标参考系 |
151
- | `-tr <xres> <yres>` | 目标分辨率 |
152
- | `-te <xmin> <ymin> <xmax> <ymax>` | 目标范围 |
153
- | `-cutline <file>` | 用矢量边界裁剪 |
154
- | `-crop_to_cutline` | 自动裁剪到边界 |
155
- | `-r {near\|bilinear\|cubic\|cubicspline\|lanczos}` | 重采样算法 |
156
- | `-wm <megabytes>` | 工作内存大小 |
157
- | `-co <NAME>=<VALUE>` | 创建选项 |
158
- | `-multi` | 多线程处理 |
159
-
160
- ---
161
-
162
- ## gdal_merge.py — Raster Mosaic
163
-
164
- **描述**: 合并多个栅格为单一文件。与 `gdalwarp` 类似,但更简单,不支持重投影。
165
-
166
- **基本用法**:
167
-
168
- ```bash
169
- # 基本合并
170
- gdal_merge.py -o output.tif input1.tif input2.tif input3.tif
171
-
172
- # 指定输出格式
173
- gdal_merge.py -of JPEG -o output.jpg *.tif
174
-
175
- # 设置像素大小
176
- gdal_merge.py -ps 30 30 -o output.tif *.tif
177
-
178
- # 分离波段(创建多波段文件)
179
- gdal_merge.py -separate -o rgb.tif r.tif g.tif b.tif
180
-
181
- # 设置 NoData 值
182
- gdal_merge.py -n 0 -o output.tif *.tif
183
-
184
- # 指定输出范围
185
- gdal_merge.py -ul_lr -180 90 180 -90 -o output.tif *.tif
186
-
187
- # 初始化像素值
188
- gdal_merge.py -init 255 -o output.tif input1.tif input2.tif
189
- ```
190
-
191
- **关键参数**:
192
-
193
- | 参数 | 说明 |
194
- |------|------|
195
- | `-o <filename>` | 输出文件名 |
196
- | `-of <format>` | 输出格式 |
197
- | `-ps <pixelsize_x> <pixelsize_y>` | 像素大小 |
198
- | `-tap` | 目标对齐像素 |
199
- | `-separate` | 分离波段到不同输出波段 |
200
- | `-n <nodata>` | 输入 NoData 值 |
201
- | `-a_nodata <value>` | 输出 NoData 值 |
202
- | `-ul_lr <ulx> <uly> <lrx> <lry>` | 输出范围 |
203
- | `-init <value>` | 初始化像素值 |
204
-
205
- ---
206
-
207
- ## gdal_calc.py — Raster Calculator
208
-
209
- **描述**: 使用 NumPy 语法进行栅格数学运算。支持逻辑和算术操作。
210
-
211
- **基本用法**:
212
-
213
- ```bash
214
- # 两个栅格平均
215
- gdal_calc.py -A input1.tif -B input2.tif --calc="(A+B)/2" --outfile=mean.tif
216
-
217
- # 计算 NDVI(植被指数)
218
- gdal_calc.py -A nir.tif -B red.tif \
219
- --calc="(A-B)/(A+B)" --outfile=ndvi.tif
220
-
221
- # 三个栅格相加
222
- gdal_calc.py -A band1.tif -B band2.tif -C band3.tif \
223
- --calc="A+B+C" --outfile=sum.tif
224
-
225
- # 逻辑操作(掩膜)
226
- gdal_calc.py -A input.tif --calc="A*(A>100)" \
227
- --outfile=masked.tif --NoDataValue=0
228
-
229
- # 范围选择
230
- gdal_calc.py -A input.tif --calc="A*logical_and(A>50,A<150)" \
231
- --outfile=filtered.tif
232
-
233
- # 多个表达式创建多波段输出
234
- gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=2 \
235
- --calc="(A+B)/2" --calc="B-A" --outfile=result.tif
236
-
237
- # 处理 NoData 值
238
- gdal_calc.py -A input.tif --hideNoData \
239
- --calc="A*2" --outfile=output.tif
240
-
241
- # 转换数据类型
242
- gdal_calc.py -A input.tif --type=Int16 \
243
- --calc="A.astype(numpy.int16)" --outfile=output.tif
244
- ```
245
-
246
- **关键参数**:
247
-
248
- | 参数 | 说明 |
249
- |------|------|
250
- | `-A, -B, ..., -Z <filename>` | 输入栅格(字母标识) |
251
- | `--A_band=<n>` | 指定输入波段号 |
252
- | `--calc=<expression>` | 计算表达式(NumPy 语法) |
253
- | `--outfile=<filename>` | 输出文件 |
254
- | `--NoDataValue=<value>` | 输出 NoData 值 |
255
- | `--type=<datatype>` | 输出数据类型 |
256
- | `--format=<format>` | 输出格式 |
257
- | `--hideNoData` | 忽略输入 NoData(参与计算) |
258
- | `--extent=union\|intersect` | 处理不同范围的栅格 |
259
-
260
- ---
261
-
262
- ## gdal_contour — Contour Line Extraction
263
-
264
- **描述**: 从 DEM 提取等高线,生成矢量线或多边形。
265
-
266
- **基本用法**:
267
-
268
- ```bash
269
- # 提取等高线(10 米间隔)
270
- gdal_contour -a elevation dem.tif contours.shp -i 10
271
-
272
- # 添加属性字段
273
- gdal_contour -a elev dem.tif contours.shp -i 10
274
-
275
- # 输出为 GeoJSON
276
- gdal_contour -f GeoJSON dem.tif contours.geojson -i 50
277
-
278
- # 生成多边形等值区域
279
- gdal_contour -p -amin min -amax max dem.tif contour_polygons.shp -i 20
280
-
281
- # 指定特定等高线值
282
- gdal_contour -fl 100 200 300 dem.tif fixed_contours.shp
283
-
284
- # 从特定波段提取
285
- gdal_contour -b 1 dem.tif contours.shp -i 10
286
- ```
287
-
288
- **关键参数**:
289
-
290
- | 参数 | 说明 |
291
- |------|------|
292
- | `-a <name>` | 属性字段名(存储高度值) |
293
- | `-amin <name>` | 多边形最小值字段 |
294
- | `-amax <name>` | 多边形最大值字段 |
295
- | `-i <interval>` | 等高线间隔 |
296
- | `-fl <level>` | 固定高度值(可多个) |
297
- | `-off <offset>` | 间隔偏移量 |
298
- | `-p` | 生成多边形而非线 |
299
- | `-3d` | 输出 3D 矢量 |
300
- | `-f <format>` | 输出格式 |
301
- | `-b <band>` | 源波段号 |
302
-
303
- ---
304
-
305
- ## gdal_grid — Grid Creation from Scattered Points
306
-
307
- **描述**: 从矢量点数据(如 LiDAR、采样点)创建规则网格 DEM,支持多种插值算法。
308
-
309
- **基本用法**:
310
-
311
- ```bash
312
- # 基本网格化(使用平均值)
313
- gdal_grid -a average input_points.shp output_dem.tif
314
-
315
- # 反距离加权(IDW)插值
316
- gdal_grid -a invdist:power=2:smoothing=0 input_points.shp output_dem.tif
317
-
318
- # 克里金插值
319
- gdal_grid -a kriging:variogram=spherical input_points.shp output_dem.tif
320
-
321
- # 指定输出范围和分辨率
322
- gdal_grid -outsize 512 512 -tr 10 10 \
323
- -a average input_points.shp output_dem.tif
324
-
325
- # 只使用 Z 属性字段
326
- gdal_grid -zfield Z -a invdist input_points.shp output_dem.tif
327
-
328
- # 设置 NoData 值
329
- gdal_grid -a_nodata -9999 -a average input_points.shp output_dem.tif
330
-
331
- # 指定空间范围
332
- gdal_grid -te 0 0 1000 1000 -a average input_points.shp output_dem.tif
333
- ```
334
-
335
- **关键参数**:
336
-
337
- | 参数 | 说明 |
338
- |------|------|
339
- | `-a <algorithm>` | 插值算法(average, invdist, kriging 等) |
340
- | `-zfield <name>` | 用于 Z 值的属性字段 |
341
- | `-outsize <xsize> <ysize>` | 输出栅格大小 |
342
- | `-tr <xres> <yres>` | 输出分辨率 |
343
- | `-te <xmin> <ymin> <xmax> <ymax>` | 输出范围 |
344
- | `-ot <datatype>` | 输出数据类型 |
345
- | `-a_srs <srs>` | 输出坐标参考系 |
346
- | `-a_nodata <value>` | NoData 值 |
347
-
348
- **支持的算法**:
349
- - `average` — 平均值(最简单)
350
- - `invdist` — 反距离加权(常用)
351
- - `invdistnn` — 反距离加权(最近邻)
352
- - `kriging` — 克里金插值(高级)
353
- - `linear` — 线性内插(TIN)
354
-
355
- ---
356
-
357
- ## gdal_polygonize.py — Raster to Vector Polygon
358
-
359
- **描述**: 将栅格转换为矢量多边形,每个像素值对应一个多边形。
360
-
361
- **基本用法**:
362
-
363
- ```bash
364
- # 基本转换
365
- gdal_polygonize.py input.tif output.shp
366
-
367
- # 指定输出格式
368
- gdal_polygonize.py input.tif -f GeoJSON output.geojson
369
-
370
- # 转换特定波段
371
- gdal_polygonize.py -b 1 input.tif output.shp
372
-
373
- # 使用 8 连通性(默认 4 连通)
374
- gdal_polygonize.py -8 input.tif output.shp
375
-
376
- # 使用掩膜过滤
377
- gdal_polygonize.py -mask mask.tif input.tif output.shp
378
-
379
- # 输出到数据库
380
- gdal_polygonize.py input.tif -f PostgreSQL \
381
- "PG:dbname=mydb" -nln polygons
382
-
383
- # 自定义字段名
384
- gdal_polygonize.py input.tif output.shp output_layer value_field
385
- ```
386
-
387
- **关键参数**:
388
-
389
- | 参数 | 说明 |
390
- |------|------|
391
- | `-b <band>` | 源波段号 |
392
- | `-8` | 使用 8 连通性(默认 4) |
393
- | `-mask <file>` | 掩膜文件 |
394
- | `-nomask` | 不使用掩膜 |
395
- | `-f <format>` | 输出格式 |
396
- | `-nln <name>` | 输出图层名 |
397
-
398
- ---
399
-
400
- ## gdaltindex — Raster Tile Index
401
-
402
- **描述**: 为多个栅格文件创建索引,生成矢量文件列出每个瓦片的范围。用于 MapServer 等。
403
-
404
- **基本用法**:
405
-
406
- ```bash
407
- # 基本索引
408
- gdaltindex index.shp *.tif
409
-
410
- # 输出为 GeoPackage
411
- gdaltindex -of GPKG index.gpkg *.tif
412
-
413
- # 绝对路径
414
- gdaltindex -write_absolute_path index.shp *.tif
415
-
416
- # 重投影索引
417
- gdaltindex -t_srs EPSG:4326 index.shp *.tif
418
-
419
- # 递归搜索目录
420
- gdaltindex -recursive -of GPKG index.gpkg /path/to/rasters/
421
-
422
- # 使用通配符过滤
423
- gdaltindex -filename_filter "*.tif" index.shp /data/
424
-
425
- # 跳过不同投影的文件
426
- gdaltindex -skip_different_projection index.shp *.tif
427
-
428
- # 存储源 SRS 信息
429
- gdaltindex -src_srs_name src_srs -src_srs_format EPSG index.shp *.tif
430
- ```
431
-
432
- **关键参数**:
433
-
434
- | 参数 | 说明 |
435
- |------|------|
436
- | `-of <format>` | 输出格式 |
437
- | `-write_absolute_path` | 存储绝对路径 |
438
- | `-skip_different_projection` | 跳过异投影文件 |
439
- | `-t_srs <srs>` | 目标投影(统一所有瓦片) |
440
- | `-src_srs_name <name>` | SRS 字段名 |
441
- | `-recursive` | 递归搜索目录 |
442
- | `-filename_filter <pattern>` | 文件名过滤 |
443
- | `-tileindex <name>` | 索引字段名(默认 location) |
444
-
445
- ---
446
-
447
- ## gdal_edit.py — Edit Raster Metadata
448
-
449
- **描述**: 修改现有栅格的地理参考信息、坐标系、NoData 值等。
450
-
451
- **基本用法**:
452
-
453
- ```bash
454
- # 设置坐标参考系
455
- gdal_edit.py -a_srs EPSG:4326 input.tif
456
-
457
- # 设置地理范围
458
- gdal_edit.py -a_ullr -180 90 180 -90 input.tif
459
-
460
- # 设置分辨率
461
- gdal_edit.py -tr 30 30 input.tif
462
-
463
- # 设置 NoData 值
464
- gdal_edit.py -a_nodata 0 input.tif
465
-
466
- # 添加地面控制点(GCP)
467
- gdal_edit.py -gcp 0 0 -74.0 40.0 input.tif
468
-
469
- # 添加元数据
470
- gdal_edit.py -mo DATUM=WGS84 -mo SOURCE=USGS input.tif
471
-
472
- # 计算并设置统计信息
473
- gdal_edit.py -stats input.tif
474
-
475
- # 清除地理参考
476
- gdal_edit.py -unsetgt input.tif
477
-
478
- # 删除 NoData 值
479
- gdal_edit.py -unsetnodata input.tif
480
- ```
481
-
482
- **关键参数**:
483
-
484
- | 参数 | 说明 |
485
- |------|------|
486
- | `-a_srs <srs>` | 设置坐标参考系 |
487
- | `-a_ullr <ulx> <uly> <lrx> <lry>` | 设置地理范围 |
488
- | `-tr <xres> <yres>` | 设置分辨率 |
489
- | `-unsetgt` | 删除地理参考 |
490
- | `-a_nodata <value>` | 设置 NoData 值 |
491
- | `-unsetnodata` | 删除 NoData 值 |
492
- | `-stats` | 计算统计信息 |
493
- | `-mo <KEY>=<VALUE>` | 添加元数据 |
494
- | `-gcp <pixel> <line> <x> <y>` | 添加地面控制点 |
495
-
496
- ---
497
-
498
- ## nearblack — Clean Black/White Borders
499
-
500
- **描述**: 将接近黑色或白色的边界像素设置为纯黑或白,用于清理空照片的角落。
501
-
502
- **基本用法**:
503
-
504
- ```bash
505
- # 清理黑色边界(默认)
506
- nearblack input.tif -o output.tif
507
-
508
- # 搜索白色边界
509
- nearblack -white input.tif -o output.tif
510
-
511
- # 自定义颜色
512
- nearblack -color 100,100,100 input.tif -o output.tif
513
-
514
- # 设置容差
515
- nearblack -near 20 input.tif -o output.tif
516
-
517
- # 添加 Alpha 通道
518
- nearblack -setalpha input.tif -o output.tif
519
-
520
- # 添加掩膜波段
521
- nearblack -setmask input.tif -o output.tif
522
-
523
- # 指定输出格式
524
- nearblack -of JPEG input.tif -o output.jpg
525
- ```
526
-
527
- **关键参数**:
528
-
529
- | 参数 | 说明 |
530
- |------|------|
531
- | `-o <file>` | 输出文件 |
532
- | `-of <format>` | 输出格式 |
533
- | `-white` | 搜索白色而非黑色 |
534
- | `-color <c1>,<c2>,...` | 搜索特定颜色 |
535
- | `-near <dist>` | 颜色容差(0-255,默认 15) |
536
- | `-nb <pixels>` | 连续非黑像素数(默认 2) |
537
- | `-setalpha` | 添加 Alpha 通道 |
538
- | `-setmask` | 添加掩膜波段 |
1
+ # GDAL Raster Tools Reference
2
+
3
+ > 这是 [../SKILL.md](../SKILL.md) 的补充文件,收录 GDAL 栅格工具的完整参数表与示例。
4
+
5
+ ---
6
+
7
+ ## gdalinfo — Raster Info Query
8
+
9
+ **描述**: 显示栅格数据的元数据、地理信息、波段信息、统计值。
10
+
11
+ **基本用法**:
12
+
13
+ ```bash
14
+ # 基本信息
15
+ gdalinfo dem.tif
16
+
17
+ # JSON 输出(GDAL 3.1+)
18
+ gdalinfo -json dem.tif
19
+
20
+ # 仅显示摘要(不显示统计值)
21
+ gdalinfo -checksum dem.tif
22
+
23
+ # 显示统计信息
24
+ gdalinfo -stats dem.tif
25
+
26
+ # 显示色表
27
+ gdalinfo -checksum terrain.tif | grep -A5 "Color Table"
28
+
29
+ # 计算直方图
30
+ gdalinfo -hist image.tif
31
+ ```
32
+
33
+ **关键参数**:
34
+
35
+ | 参数 | 说明 |
36
+ |------|------|
37
+ | `-json` | JSON 格式输出 |
38
+ | `-stats` | 计算并显示统计信息 |
39
+ | `-approx_stats` | 近似统计(快速) |
40
+ | `-checksum` | 显示校验和 |
41
+ | `-hist` | 显示直方图 |
42
+ | `-mm` | 显示最小/最大值 |
43
+ | `-noct` | 不显示色表 |
44
+
45
+ **示例**:
46
+
47
+ ```bash
48
+ # 获取 DEM 范围和分辨率
49
+ gdalinfo dem.tif | grep -E "^Size|^Upper Left|Corner|Pixel Size"
50
+
51
+ # 获取 JSON 格式地理信息
52
+ gdalinfo -json image.tif | jq '.coordinateSystem'
53
+
54
+ # 检查数据类型和波段数
55
+ gdalinfo image.tif | grep "Type:\|Band"
56
+ ```
57
+
58
+ ---
59
+
60
+ ## gdal_translate — Format Conversion and Resampling
61
+
62
+ **描述**: 将栅格文件转换为不同格式、调整分辨率、裁剪、创建缩放图等。
63
+
64
+ **基本用法**:
65
+
66
+ ```bash
67
+ # 格式转换(GeoTIFF → PNG)
68
+ gdal_translate input.tif output.png
69
+
70
+ # 格式转换(带压缩)
71
+ gdal_translate -co COMPRESS=DEFLATE input.tif output.tif
72
+
73
+ # 重采样(降低分辨率)
74
+ gdal_translate -outsize 50% 50% input.tif output.tif
75
+
76
+ # 重采样到指定分辨率
77
+ gdal_translate -tr 10 10 input.tif output.tif
78
+
79
+ # 裁剪到范围
80
+ gdal_translate -projwin -180 90 -170 80 input.tif output.tif
81
+
82
+ # 创建缩放版本(1/4 大小)
83
+ gdal_translate -outsize 25% 25% input.tif thumbnail.tif
84
+
85
+ # 转换数据类型
86
+ gdal_translate -ot Byte input.tif output.tif
87
+
88
+ # 设置 NoData 值
89
+ gdal_translate -a_nodata 0 input.tif output.tif
90
+
91
+ # 只提取特定波段
92
+ gdal_translate -b 1 rgb.tif red.tif
93
+ ```
94
+
95
+ **关键参数**:
96
+
97
+ | 参数 | 说明 |
98
+ |------|------|
99
+ | `-of <format>` | 输出格式 |
100
+ | `-outsize <xsize> <ysize>` | 输出大小(像素或百分比) |
101
+ | `-tr <xres> <yres>` | 目标分辨率 |
102
+ | `-projwin <ulx> <uly> <lrx> <lry>` | 裁剪范围 |
103
+ | `-ot <datatype>` | 输出数据类型 |
104
+ | `-b <band>` | 选择波段 |
105
+ | `-a_nodata <value>` | 设置 NoData 值 |
106
+ | `-co <NAME>=<VALUE>` | 创建选项(如压缩) |
107
+
108
+ ---
109
+
110
+ ## gdalwarp — Reprojection and Mosaicking
111
+
112
+ **描述**: 重投影栅格、裁剪、融合多个栅格(镶嵌)、重新采样。
113
+
114
+ **基本用法**:
115
+
116
+ ```bash
117
+ # 重投影(UTM 50N → WGS84)
118
+ gdalwarp -t_srs EPSG:4326 input_utm.tif output_wgs84.tif
119
+
120
+ # 镶嵌多个文件
121
+ gdalwarp input1.tif input2.tif input3.tif output_mosaic.tif
122
+
123
+ # 重采样并重投影
124
+ gdalwarp -tr 30 30 -t_srs EPSG:4326 input.tif output.tif
125
+
126
+ # 裁剪(指定范围)
127
+ gdalwarp -te -10 40 10 50 input.tif output.tif
128
+
129
+ # 用矢量边界裁剪
130
+ gdalwarp -cutline clip_boundary.shp -crop_to_cutline input.tif output.tif
131
+
132
+ # 最近邻重采样(用于分类数据)
133
+ gdalwarp -r near input.tif output.tif
134
+
135
+ # 双线性插值(用于连续数据)
136
+ gdalwarp -r bilinear input.tif output.tif
137
+
138
+ # 立方卷积插值(高质量)
139
+ gdalwarp -r cubic input.tif output.tif
140
+
141
+ # 多线程处理
142
+ gdalwarp -wm 512 -co COMPRESS=DEFLATE input.tif output.tif
143
+ ```
144
+
145
+ **关键参数**:
146
+
147
+ | 参数 | 说明 |
148
+ |------|------|
149
+ | `-t_srs <EPSG>` | 目标坐标参考系 |
150
+ | `-s_srs <EPSG>` | 源坐标参考系 |
151
+ | `-tr <xres> <yres>` | 目标分辨率 |
152
+ | `-te <xmin> <ymin> <xmax> <ymax>` | 目标范围 |
153
+ | `-cutline <file>` | 用矢量边界裁剪 |
154
+ | `-crop_to_cutline` | 自动裁剪到边界 |
155
+ | `-r {near\|bilinear\|cubic\|cubicspline\|lanczos}` | 重采样算法 |
156
+ | `-wm <megabytes>` | 工作内存大小 |
157
+ | `-co <NAME>=<VALUE>` | 创建选项 |
158
+ | `-multi` | 多线程处理 |
159
+
160
+ ---
161
+
162
+ ## gdal_merge.py — Raster Mosaic
163
+
164
+ **描述**: 合并多个栅格为单一文件。与 `gdalwarp` 类似,但更简单,不支持重投影。
165
+
166
+ **基本用法**:
167
+
168
+ ```bash
169
+ # 基本合并
170
+ gdal_merge.py -o output.tif input1.tif input2.tif input3.tif
171
+
172
+ # 指定输出格式
173
+ gdal_merge.py -of JPEG -o output.jpg *.tif
174
+
175
+ # 设置像素大小
176
+ gdal_merge.py -ps 30 30 -o output.tif *.tif
177
+
178
+ # 分离波段(创建多波段文件)
179
+ gdal_merge.py -separate -o rgb.tif r.tif g.tif b.tif
180
+
181
+ # 设置 NoData 值
182
+ gdal_merge.py -n 0 -o output.tif *.tif
183
+
184
+ # 指定输出范围
185
+ gdal_merge.py -ul_lr -180 90 180 -90 -o output.tif *.tif
186
+
187
+ # 初始化像素值
188
+ gdal_merge.py -init 255 -o output.tif input1.tif input2.tif
189
+ ```
190
+
191
+ **关键参数**:
192
+
193
+ | 参数 | 说明 |
194
+ |------|------|
195
+ | `-o <filename>` | 输出文件名 |
196
+ | `-of <format>` | 输出格式 |
197
+ | `-ps <pixelsize_x> <pixelsize_y>` | 像素大小 |
198
+ | `-tap` | 目标对齐像素 |
199
+ | `-separate` | 分离波段到不同输出波段 |
200
+ | `-n <nodata>` | 输入 NoData 值 |
201
+ | `-a_nodata <value>` | 输出 NoData 值 |
202
+ | `-ul_lr <ulx> <uly> <lrx> <lry>` | 输出范围 |
203
+ | `-init <value>` | 初始化像素值 |
204
+
205
+ ---
206
+
207
+ ## gdal_calc.py — Raster Calculator
208
+
209
+ **描述**: 使用 NumPy 语法进行栅格数学运算。支持逻辑和算术操作。
210
+
211
+ **基本用法**:
212
+
213
+ ```bash
214
+ # 两个栅格平均
215
+ gdal_calc.py -A input1.tif -B input2.tif --calc="(A+B)/2" --outfile=mean.tif
216
+
217
+ # 计算 NDVI(植被指数)
218
+ gdal_calc.py -A nir.tif -B red.tif \
219
+ --calc="(A-B)/(A+B)" --outfile=ndvi.tif
220
+
221
+ # 三个栅格相加
222
+ gdal_calc.py -A band1.tif -B band2.tif -C band3.tif \
223
+ --calc="A+B+C" --outfile=sum.tif
224
+
225
+ # 逻辑操作(掩膜)
226
+ gdal_calc.py -A input.tif --calc="A*(A>100)" \
227
+ --outfile=masked.tif --NoDataValue=0
228
+
229
+ # 范围选择
230
+ gdal_calc.py -A input.tif --calc="A*logical_and(A>50,A<150)" \
231
+ --outfile=filtered.tif
232
+
233
+ # 多个表达式创建多波段输出
234
+ gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=2 \
235
+ --calc="(A+B)/2" --calc="B-A" --outfile=result.tif
236
+
237
+ # 处理 NoData 值
238
+ gdal_calc.py -A input.tif --hideNoData \
239
+ --calc="A*2" --outfile=output.tif
240
+
241
+ # 转换数据类型
242
+ gdal_calc.py -A input.tif --type=Int16 \
243
+ --calc="A.astype(numpy.int16)" --outfile=output.tif
244
+ ```
245
+
246
+ **关键参数**:
247
+
248
+ | 参数 | 说明 |
249
+ |------|------|
250
+ | `-A, -B, ..., -Z <filename>` | 输入栅格(字母标识) |
251
+ | `--A_band=<n>` | 指定输入波段号 |
252
+ | `--calc=<expression>` | 计算表达式(NumPy 语法) |
253
+ | `--outfile=<filename>` | 输出文件 |
254
+ | `--NoDataValue=<value>` | 输出 NoData 值 |
255
+ | `--type=<datatype>` | 输出数据类型 |
256
+ | `--format=<format>` | 输出格式 |
257
+ | `--hideNoData` | 忽略输入 NoData(参与计算) |
258
+ | `--extent=union\|intersect` | 处理不同范围的栅格 |
259
+
260
+ ---
261
+
262
+ ## gdal_contour — Contour Line Extraction
263
+
264
+ **描述**: 从 DEM 提取等高线,生成矢量线或多边形。
265
+
266
+ **基本用法**:
267
+
268
+ ```bash
269
+ # 提取等高线(10 米间隔)
270
+ gdal_contour -a elevation dem.tif contours.shp -i 10
271
+
272
+ # 添加属性字段
273
+ gdal_contour -a elev dem.tif contours.shp -i 10
274
+
275
+ # 输出为 GeoJSON
276
+ gdal_contour -f GeoJSON dem.tif contours.geojson -i 50
277
+
278
+ # 生成多边形等值区域
279
+ gdal_contour -p -amin min -amax max dem.tif contour_polygons.shp -i 20
280
+
281
+ # 指定特定等高线值
282
+ gdal_contour -fl 100 200 300 dem.tif fixed_contours.shp
283
+
284
+ # 从特定波段提取
285
+ gdal_contour -b 1 dem.tif contours.shp -i 10
286
+ ```
287
+
288
+ **关键参数**:
289
+
290
+ | 参数 | 说明 |
291
+ |------|------|
292
+ | `-a <name>` | 属性字段名(存储高度值) |
293
+ | `-amin <name>` | 多边形最小值字段 |
294
+ | `-amax <name>` | 多边形最大值字段 |
295
+ | `-i <interval>` | 等高线间隔 |
296
+ | `-fl <level>` | 固定高度值(可多个) |
297
+ | `-off <offset>` | 间隔偏移量 |
298
+ | `-p` | 生成多边形而非线 |
299
+ | `-3d` | 输出 3D 矢量 |
300
+ | `-f <format>` | 输出格式 |
301
+ | `-b <band>` | 源波段号 |
302
+
303
+ ---
304
+
305
+ ## gdal_grid — Grid Creation from Scattered Points
306
+
307
+ **描述**: 从矢量点数据(如 LiDAR、采样点)创建规则网格 DEM,支持多种插值算法。
308
+
309
+ **基本用法**:
310
+
311
+ ```bash
312
+ # 基本网格化(使用平均值)
313
+ gdal_grid -a average input_points.shp output_dem.tif
314
+
315
+ # 反距离加权(IDW)插值
316
+ gdal_grid -a invdist:power=2:smoothing=0 input_points.shp output_dem.tif
317
+
318
+ # 克里金插值
319
+ gdal_grid -a kriging:variogram=spherical input_points.shp output_dem.tif
320
+
321
+ # 指定输出范围和分辨率
322
+ gdal_grid -outsize 512 512 -tr 10 10 \
323
+ -a average input_points.shp output_dem.tif
324
+
325
+ # 只使用 Z 属性字段
326
+ gdal_grid -zfield Z -a invdist input_points.shp output_dem.tif
327
+
328
+ # 设置 NoData 值
329
+ gdal_grid -a_nodata -9999 -a average input_points.shp output_dem.tif
330
+
331
+ # 指定空间范围
332
+ gdal_grid -te 0 0 1000 1000 -a average input_points.shp output_dem.tif
333
+ ```
334
+
335
+ **关键参数**:
336
+
337
+ | 参数 | 说明 |
338
+ |------|------|
339
+ | `-a <algorithm>` | 插值算法(average, invdist, kriging 等) |
340
+ | `-zfield <name>` | 用于 Z 值的属性字段 |
341
+ | `-outsize <xsize> <ysize>` | 输出栅格大小 |
342
+ | `-tr <xres> <yres>` | 输出分辨率 |
343
+ | `-te <xmin> <ymin> <xmax> <ymax>` | 输出范围 |
344
+ | `-ot <datatype>` | 输出数据类型 |
345
+ | `-a_srs <srs>` | 输出坐标参考系 |
346
+ | `-a_nodata <value>` | NoData 值 |
347
+
348
+ **支持的算法**:
349
+ - `average` — 平均值(最简单)
350
+ - `invdist` — 反距离加权(常用)
351
+ - `invdistnn` — 反距离加权(最近邻)
352
+ - `kriging` — 克里金插值(高级)
353
+ - `linear` — 线性内插(TIN)
354
+
355
+ ---
356
+
357
+ ## gdal_polygonize.py — Raster to Vector Polygon
358
+
359
+ **描述**: 将栅格转换为矢量多边形,每个像素值对应一个多边形。
360
+
361
+ **基本用法**:
362
+
363
+ ```bash
364
+ # 基本转换
365
+ gdal_polygonize.py input.tif output.shp
366
+
367
+ # 指定输出格式
368
+ gdal_polygonize.py input.tif -f GeoJSON output.geojson
369
+
370
+ # 转换特定波段
371
+ gdal_polygonize.py -b 1 input.tif output.shp
372
+
373
+ # 使用 8 连通性(默认 4 连通)
374
+ gdal_polygonize.py -8 input.tif output.shp
375
+
376
+ # 使用掩膜过滤
377
+ gdal_polygonize.py -mask mask.tif input.tif output.shp
378
+
379
+ # 输出到数据库
380
+ gdal_polygonize.py input.tif -f PostgreSQL \
381
+ "PG:dbname=mydb" -nln polygons
382
+
383
+ # 自定义字段名
384
+ gdal_polygonize.py input.tif output.shp output_layer value_field
385
+ ```
386
+
387
+ **关键参数**:
388
+
389
+ | 参数 | 说明 |
390
+ |------|------|
391
+ | `-b <band>` | 源波段号 |
392
+ | `-8` | 使用 8 连通性(默认 4) |
393
+ | `-mask <file>` | 掩膜文件 |
394
+ | `-nomask` | 不使用掩膜 |
395
+ | `-f <format>` | 输出格式 |
396
+ | `-nln <name>` | 输出图层名 |
397
+
398
+ ---
399
+
400
+ ## gdaltindex — Raster Tile Index
401
+
402
+ **描述**: 为多个栅格文件创建索引,生成矢量文件列出每个瓦片的范围。用于 MapServer 等。
403
+
404
+ **基本用法**:
405
+
406
+ ```bash
407
+ # 基本索引
408
+ gdaltindex index.shp *.tif
409
+
410
+ # 输出为 GeoPackage
411
+ gdaltindex -of GPKG index.gpkg *.tif
412
+
413
+ # 绝对路径
414
+ gdaltindex -write_absolute_path index.shp *.tif
415
+
416
+ # 重投影索引
417
+ gdaltindex -t_srs EPSG:4326 index.shp *.tif
418
+
419
+ # 递归搜索目录
420
+ gdaltindex -recursive -of GPKG index.gpkg /path/to/rasters/
421
+
422
+ # 使用通配符过滤
423
+ gdaltindex -filename_filter "*.tif" index.shp /data/
424
+
425
+ # 跳过不同投影的文件
426
+ gdaltindex -skip_different_projection index.shp *.tif
427
+
428
+ # 存储源 SRS 信息
429
+ gdaltindex -src_srs_name src_srs -src_srs_format EPSG index.shp *.tif
430
+ ```
431
+
432
+ **关键参数**:
433
+
434
+ | 参数 | 说明 |
435
+ |------|------|
436
+ | `-of <format>` | 输出格式 |
437
+ | `-write_absolute_path` | 存储绝对路径 |
438
+ | `-skip_different_projection` | 跳过异投影文件 |
439
+ | `-t_srs <srs>` | 目标投影(统一所有瓦片) |
440
+ | `-src_srs_name <name>` | SRS 字段名 |
441
+ | `-recursive` | 递归搜索目录 |
442
+ | `-filename_filter <pattern>` | 文件名过滤 |
443
+ | `-tileindex <name>` | 索引字段名(默认 location) |
444
+
445
+ ---
446
+
447
+ ## gdal_edit.py — Edit Raster Metadata
448
+
449
+ **描述**: 修改现有栅格的地理参考信息、坐标系、NoData 值等。
450
+
451
+ **基本用法**:
452
+
453
+ ```bash
454
+ # 设置坐标参考系
455
+ gdal_edit.py -a_srs EPSG:4326 input.tif
456
+
457
+ # 设置地理范围
458
+ gdal_edit.py -a_ullr -180 90 180 -90 input.tif
459
+
460
+ # 设置分辨率
461
+ gdal_edit.py -tr 30 30 input.tif
462
+
463
+ # 设置 NoData 值
464
+ gdal_edit.py -a_nodata 0 input.tif
465
+
466
+ # 添加地面控制点(GCP)
467
+ gdal_edit.py -gcp 0 0 -74.0 40.0 input.tif
468
+
469
+ # 添加元数据
470
+ gdal_edit.py -mo DATUM=WGS84 -mo SOURCE=USGS input.tif
471
+
472
+ # 计算并设置统计信息
473
+ gdal_edit.py -stats input.tif
474
+
475
+ # 清除地理参考
476
+ gdal_edit.py -unsetgt input.tif
477
+
478
+ # 删除 NoData 值
479
+ gdal_edit.py -unsetnodata input.tif
480
+ ```
481
+
482
+ **关键参数**:
483
+
484
+ | 参数 | 说明 |
485
+ |------|------|
486
+ | `-a_srs <srs>` | 设置坐标参考系 |
487
+ | `-a_ullr <ulx> <uly> <lrx> <lry>` | 设置地理范围 |
488
+ | `-tr <xres> <yres>` | 设置分辨率 |
489
+ | `-unsetgt` | 删除地理参考 |
490
+ | `-a_nodata <value>` | 设置 NoData 值 |
491
+ | `-unsetnodata` | 删除 NoData 值 |
492
+ | `-stats` | 计算统计信息 |
493
+ | `-mo <KEY>=<VALUE>` | 添加元数据 |
494
+ | `-gcp <pixel> <line> <x> <y>` | 添加地面控制点 |
495
+
496
+ ---
497
+
498
+ ## nearblack — Clean Black/White Borders
499
+
500
+ **描述**: 将接近黑色或白色的边界像素设置为纯黑或白,用于清理空照片的角落。
501
+
502
+ **基本用法**:
503
+
504
+ ```bash
505
+ # 清理黑色边界(默认)
506
+ nearblack input.tif -o output.tif
507
+
508
+ # 搜索白色边界
509
+ nearblack -white input.tif -o output.tif
510
+
511
+ # 自定义颜色
512
+ nearblack -color 100,100,100 input.tif -o output.tif
513
+
514
+ # 设置容差
515
+ nearblack -near 20 input.tif -o output.tif
516
+
517
+ # 添加 Alpha 通道
518
+ nearblack -setalpha input.tif -o output.tif
519
+
520
+ # 添加掩膜波段
521
+ nearblack -setmask input.tif -o output.tif
522
+
523
+ # 指定输出格式
524
+ nearblack -of JPEG input.tif -o output.jpg
525
+ ```
526
+
527
+ **关键参数**:
528
+
529
+ | 参数 | 说明 |
530
+ |------|------|
531
+ | `-o <file>` | 输出文件 |
532
+ | `-of <format>` | 输出格式 |
533
+ | `-white` | 搜索白色而非黑色 |
534
+ | `-color <c1>,<c2>,...` | 搜索特定颜色 |
535
+ | `-near <dist>` | 颜色容差(0-255,默认 15) |
536
+ | `-nb <pixels>` | 连续非黑像素数(默认 2) |
537
+ | `-setalpha` | 添加 Alpha 通道 |
538
+ | `-setmask` | 添加掩膜波段 |