process-raster
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYou are helping the user process geospatial raster data using geoai.
Input:
$@Follow these steps in order.
你正在使用geoai帮助用户处理地理空间栅格数据。
输入:
$@请按以下顺序执行步骤。
Step 1 -- Determine the operation
步骤1 -- 确定操作类型
Parse to identify the requested operation:
$@| Operation | Triggers | Required inputs |
|---|---|---|
| "clip", "crop", "subset", | input raster + bbox |
| "stack", "combine bands" | list of input rasters |
| "mosaic", "merge" | input directory or list of rasters |
| "to vector", "vectorize", "polygonize" | input raster |
| "to raster", "rasterize", "burn" | input vector + pixel size |
If the operation is unclear from the input, ask the user to specify.
解析以识别请求的操作:
$@| 操作 | 触发关键词 | 必填输入 |
|---|---|---|
| "clip"、"crop"、"subset"、存在 | 输入栅格 + 边界框 |
| "stack"、"combine bands" | 输入栅格列表 |
| "mosaic"、"merge" | 输入目录或栅格列表 |
| "to vector"、"vectorize"、"polygonize" | 输入栅格 |
| "to raster"、"rasterize"、"burn" | 输入矢量 + 像素大小 |
如果无法从输入中明确操作类型,请询问用户指定。
Step 2 -- Resolve input file(s)
步骤2 -- 解析输入文件
For single-file operations (, , ):
clipraster-to-vectorvector-to-rasterbash
find "$PWD" -name "INPUT_FILENAME" -not -path '*/.git/*' 2>/dev/nullFor multi-file operations (, ), if a directory is given:
stackmosaicbash
find "INPUT_DIR" -name "*.tif" -o -name "*.tiff" 2>/dev/null | sortIf the user recently inspected or downloaded a file and did not specify an input, check the state file for context:
bash
STATE_DIR=""
test -f .geoai-skills/state.json && STATE_DIR=".geoai-skills"
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")"
PROJECT_ID="$(echo "$PROJECT_ROOT" | tr '/' '-')"
test -f "$HOME/.geoai-skills/$PROJECT_ID/state.json" && STATE_DIR="$HOME/.geoai-skills/$PROJECT_ID"If state exists, read the last inspected or downloaded file:
bash
python3 -c "
import json
with open('STATE_DIR/state.json') as f:
state = json.load(f)
if 'last_inspected' in state:
print(f'Last inspected: {state[\"last_inspected\"][\"path\"]}')
if 'downloaded_files' in state:
for f in state['downloaded_files']:
print(f'Downloaded: {f}')
"针对单文件操作(、、):
clipraster-to-vectorvector-to-rasterbash
find "$PWD" -name "INPUT_FILENAME" -not -path '*/.git/*' 2>/dev/null针对多文件操作(、),如果给定目录:
stackmosaicbash
find "INPUT_DIR" -name "*.tif" -o -name "*.tiff" 2>/dev/null | sort如果用户最近查看或下载了文件但未指定输入,请检查状态文件获取上下文:
bash
STATE_DIR=""
test -f .geoai-skills/state.json && STATE_DIR=".geoai-skills"
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")"
PROJECT_ID="$(echo "$PROJECT_ROOT" | tr '/' '-')"
test -f "$HOME/.geoai-skills/$PROJECT_ID/state.json" && STATE_DIR="$HOME/.geoai-skills/$PROJECT_ID"如果状态文件存在,读取最近查看或下载的文件:
bash
python3 -c "
import json
with open('STATE_DIR/state.json') as f:
state = json.load(f)
if 'last_inspected' in state:
print(f'Last inspected: {state[\"last_inspected\"][\"path\"]}')
if 'downloaded_files' in state:
for f in state['downloaded_files']:
print(f'Downloaded: {f}')
"Step 3 -- Execute the operation
步骤3 -- 执行操作
Clip by bounding box
按边界框裁剪
bash
python3 -c "
import geoai
result = geoai.clip_raster_by_bbox(
input_raster='INPUT_PATH',
output_raster='OUTPUT_PATH',
bbox=[MINX, MINY, MAXX, MAXY],
)
print(f'Clipped raster saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"Default output:
./clipped_<original_name>.tifbash
python3 -c "
import geoai
result = geoai.clip_raster_by_bbox(
input_raster='INPUT_PATH',
output_raster='OUTPUT_PATH',
bbox=[MINX, MINY, MAXX, MAXY],
)
print(f'Clipped raster saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"默认输出路径:
./clipped_<original_name>.tifStack bands
堆叠波段
bash
python3 -c "
import geoai
result = geoai.stack_bands(
input_files=['FILE1', 'FILE2', 'FILE3'],
output_file='OUTPUT_PATH',
)
print(f'Stacked raster saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"bash
python3 -c "
import geoai
result = geoai.stack_bands(
input_files=['FILE1', 'FILE2', 'FILE3'],
output_file='OUTPUT_PATH',
)
print(f'Stacked raster saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"Mosaic GeoTIFFs
拼接GeoTIFF
bash
python3 -c "
import geoai
result = geoai.mosaic_geotiffs(
input_dir='INPUT_DIR',
output_file='OUTPUT_PATH',
)
print(f'Mosaic saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"bash
python3 -c "
import geoai
result = geoai.mosaic_geotiffs(
input_dir='INPUT_DIR',
output_file='OUTPUT_PATH',
)
print(f'Mosaic saved to: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"Raster to vector
栅格转矢量
bash
python3 -c "
import geoai
gdf = geoai.raster_to_vector(
raster_path='INPUT_PATH',
output_path='OUTPUT_PATH',
)
print(f'Vectorized: {len(gdf)} features')
print(f'Saved to: OUTPUT_PATH')
print(f'Columns: {list(gdf.columns)}')
"Default output:
./<original_name>.gpkgbash
python3 -c "
import geoai
gdf = geoai.raster_to_vector(
raster_path='INPUT_PATH',
output_path='OUTPUT_PATH',
)
print(f'Vectorized: {len(gdf)} features')
print(f'Saved to: OUTPUT_PATH')
print(f'Columns: {list(gdf.columns)}')
"默认输出路径:
./<original_name>.gpkgVector to raster
矢量转栅格
bash
python3 -c "
import geoai
result = geoai.vector_to_raster(
vector_path='INPUT_PATH',
output_path='OUTPUT_PATH',
pixel_size=PIXEL_SIZE,
)
print(f'Rasterized: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"Default pixel size: 1.0 (or infer from context). Default output:
./<original_name>.tifReplace all placeholder values with actual paths and parameters before running.
bash
python3 -c "
import geoai
result = geoai.vector_to_raster(
vector_path='INPUT_PATH',
output_path='OUTPUT_PATH',
pixel_size=PIXEL_SIZE,
)
print(f'Rasterized: {result}')
info = geoai.get_raster_info(result)
for k, v in info.items():
print(f'{k}: {v}')
"默认像素大小:1.0(或从上下文推断)。默认输出路径:
./<original_name>.tif运行前请将所有占位符替换为实际路径和参数。
Step 4 -- Update state
步骤4 -- 更新状态
If a state directory exists, update it with the output file path using the same state resolution pattern as Step 2.
如果状态目录存在,使用步骤2中的状态解析规则,将输出文件路径更新到状态文件中。
Step 5 -- Report and suggest
步骤5 -- 报告与建议
Report:
- Operation performed
- Input and output file paths
- Key properties of the output (dimensions, CRS, band count, feature count)
Then suggest: "Use to examine the result in detail."
/geoai-skills:inspect-geo报告内容:
- 执行的操作
- 输入和输出文件路径
- 输出文件的关键属性(尺寸、CRS、波段数、要素数)
然后建议:"使用详细查看处理结果。"
/geoai-skills:inspect-geoError handling
错误处理
- fails -> delegate to
import geoai./geoai-skills:install-geoai - File not found -> use to locate, suggest corrected path.
find - CRS mismatch (for stack/mosaic) -> report the issue and suggest reprojecting first.
- Insufficient disk space -> report the error.
- Memory error (very large rasters) -> suggest processing in tiles or using a smaller extent.
- 失败 -> 调用
import geoai处理。/geoai-skills:install-geoai - 文件未找到 -> 使用命令定位,建议修正路径。
find - CRS不匹配(针对堆叠/拼接操作)-> 报告问题并建议先进行投影转换。
- 磁盘空间不足 -> 报告错误。
- 内存错误(处理超大栅格时)-> 建议分块处理或使用更小的范围。