Gdal之投影转换、裁切、合并
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gdal之投影转换、裁切、合并相关的知识,希望对你有一定的参考价值。
参考技术A 1). 语法:gdalwarp [ -- help - general] [ -- formats]
[ - s_srs srs_def] [ - t_srs srs_def] [ - ct string] [ - to "NAME=VALUE"] * [ - novshiftgrid]
[ - order n | - tps | - rpc | - geoloc] [ - et err_threshold]
[ - refine_gcps tolerance [minimum_gcps]]
[ - te xmin ymin xmax ymax] [ - te_srs srs_def]
[ - tr xres yres] [ - tap] [ - ts width height]
[ - ovr level | AUTO | AUTO - n | NONE] [ - wo "NAME=VALUE"] [ - ot Byte / Int16 /... ]
[ - wt Byte / Int16]
[ - srcnodata "value [value...]"] [ - dstnodata "value [value...]"]
[ - srcalpha |- nosrcalpha] [ - dstalpha]
[ - r resampling_method] [ - wm memory_in_mb] [ - multi] [ - q]
[ - cutline datasource] [ - cl layer] [ - cwhere expression]
[ - csql statement] [ - cblend dist_in_pixels] [ - crop_to_cutline]
[ - of format] [ - co "NAME=VALUE"] * [ - overwrite]
[ - nomd] [ - cvmd meta_conflict_value] [ - setci] [ - oo NAME = VALUE] *
[ - doo NAME = VALUE] *
srcfile * dstfile
2).示例 :
案例:栅格数据合并/裁切/投影转换
场景: 想要将 data1 . img、data2 . img 格式文件 合并为 merge.img 格式文件 并设置无值区值为-9999
脚本:gdalwarp.exe -srcnodata -9999 -dstnodata -9999 -of HFA data1.img data2.img merge.img
参考:https://www.osgeo.cn/gdal/programs/gdalwarp.html
脚本:BAT脚本示范
@echo off
chcp 936
@echo "gdal/gdalwarp.exe" -srcnodata -9999 -dstnodata -9999 -of HFA data1.img data2.img merge.img
"gdal/gdalwarp.exe" -srcnodata -9999 -dstnodata -9999 -of HFA data1.img data2.img merge.img
pause
拓展1:BAT脚本,批量将.tif格式文件合并/裁切【按csv文件合并/裁切】
//MergeOrCut.bat
@echo off
chcp 936
setlocal enabledelayedexpansion
set tifvar=
for /f "delims=" %%a in (%1.csv) do (
set tifvar=!tifvar! %%a
)
@echo "gdal/gdalwarp.exe" --config GDAL_CACHEMAX 8192
--config GDAL_FILENAME_IS_UTF8 NO --config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -cutline %1.shp -co "BIGTIFF=YES" -multi
-wo NUM_THREADS=ALL_CPUS -wm 4096 -r cubic -overwrite %tifvar% %1.tif
"gdal/gdalwarp.exe" --config GDAL_CACHEMAX 8192
--config GDAL_FILENAME_IS_UTF8 NO --config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -cutline %1.shp -co "BIGTIFF=YES" -multi
-wo NUM_THREADS=ALL_CPUS -wm 4096 -r cubic -overwrite %tifvar% %1.tif
pause
//RunMergeOrCut.bat 【输出栅格与合并/裁剪矢量文件的名称】
@echo off
chcp 936
for /f "delims=" %%i in (name.txt) do (
call MergeOrCut.bat %%i
)
pause
拓展2:BAT脚本,批量将.tif格式文件合并/裁切【遍历目录合并/裁切】
//MergeOrCut.bat
@echo off
chcp 936
setlocal enabledelayedexpansion
set tifvar=
for /f "delims=" %%a in ('dir %3 /b/s') do (
set tifvar=!tifvar! %%a
)
@echo "gdal/gdalwarp.exe" --config GDAL_CACHEMAX 8192
--config GDAL_FILENAME_IS_UTF8 NO --config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -cutline %2 -co "BIGTIFF=YES" -multi
-wo NUM_THREADS=ALL_CPUS -wm 4096 -r cubic -overwrite %tifvar% %1.tif
"gdal/gdalwarp.exe" --config GDAL_CACHEMAX 8192
--config GDAL_FILENAME_IS_UTF8 NO --config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -cutline %2 -co "BIGTIFF=YES" -multi
-wo NUM_THREADS=ALL_CPUS -wm 4096 -r cubic -overwrite %tifvar% %1.tif
pause
//RunMergeOrCut.bat 【输出栅格文件名称】 【合并/裁剪矢量文件名称】【栅格目录】
@echo off
chcp 936
for /f "tokens=1-3 delims=," %%i in (name.txt) do (
call MergeOrCut.bat %%i %%j %%k
)
pause
拓展3:BAT脚本,将.tif格式文件投影转换
//Projection.bat
@echo off
chcp 936
@echo "gdal/gdalwarp.exe" --config GDAL_FILENAME_IS_UTF8 NO
--config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -multi -wo NUM_THREADS=ALL_CPUS -r cubic -overwrite -t_srs "EPSG:4326"
data.tif data_srs.tif
"gdal/gdalwarp.exe" --config GDAL_FILENAME_IS_UTF8 NO
--config SHAPE_ENCODING UTF-8 --config GDAL_DATA gdal/gdal-data -crop_to_cutline -multi -wo NUM_THREADS=ALL_CPUS -r cubic -overwrite -t_srs "EPSG:4326"
data.tif data_srs.tif
pause
以上是关于Gdal之投影转换、裁切、合并的主要内容,如果未能解决你的问题,请参考以下文章