process-raster

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
You 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:
OperationTriggersRequired inputs
clip
"clip", "crop", "subset",
--bbox
present
input raster + bbox
stack
"stack", "combine bands"list of input rasters
mosaic
"mosaic", "merge"input directory or list of rasters
raster-to-vector
"to vector", "vectorize", "polygonize"input raster
vector-to-raster
"to raster", "rasterize", "burn"input vector + pixel size
If the operation is unclear from the input, ask the user to specify.
解析
$@
以识别请求的操作:
操作触发关键词必填输入
clip
"clip"、"crop"、"subset"、存在
--bbox
输入栅格 + 边界框
stack
"stack"、"combine bands"输入栅格列表
mosaic
"mosaic"、"merge"输入目录或栅格列表
raster-to-vector
"to vector"、"vectorize"、"polygonize"输入栅格
vector-to-raster
"to raster"、"rasterize"、"burn"输入矢量 + 像素大小
如果无法从输入中明确操作类型,请询问用户指定。

Step 2 -- Resolve input file(s)

步骤2 -- 解析输入文件

For single-file operations (
clip
,
raster-to-vector
,
vector-to-raster
):
bash
find "$PWD" -name "INPUT_FILENAME" -not -path '*/.git/*' 2>/dev/null
For multi-file operations (
stack
,
mosaic
), if a directory is given:
bash
find "INPUT_DIR" -name "*.tif" -o -name "*.tiff" 2>/dev/null | sort
If 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}')
"
针对单文件操作(
clip
raster-to-vector
vector-to-raster
):
bash
find "$PWD" -name "INPUT_FILENAME" -not -path '*/.git/*' 2>/dev/null
针对多文件操作(
stack
mosaic
),如果给定目录:
bash
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>.tif
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}')
"
默认输出路径:
./clipped_<original_name>.tif

Stack 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>.gpkg
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)}')
"
默认输出路径:
./<original_name>.gpkg

Vector 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>.tif
Replace 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
/geoai-skills:inspect-geo
to examine the result in detail."
报告内容:
  • 执行的操作
  • 输入和输出文件路径
  • 输出文件的关键属性(尺寸、CRS、波段数、要素数)
然后建议:"使用
/geoai-skills:inspect-geo
详细查看处理结果。"

Error handling

错误处理

  • import geoai
    fails
    -> delegate to
    /geoai-skills:install-geoai
    .
  • File not found -> use
    find
    to locate, suggest corrected path.
  • 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不匹配(针对堆叠/拼接操作)-> 报告问题并建议先进行投影转换。
  • 磁盘空间不足 -> 报告错误。
  • 内存错误(处理超大栅格时)-> 建议分块处理或使用更小的范围。