本文主要是介绍gdalwarp.exe 调用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
c# 调用 gdalwarp.exe
- 下载
- apps
- wkt 格式
- 参数说明
- 本次调用源影像投影字符串为WKT1_ESRI格式
- WKT1_ESRI格式
- WKT1_GDAL格式
- 命令行调用 gdalwarp.exe
下载
https://www.gisinternals.com/stable.php下载所需版本的编译好的Gdal
如:
release-1900-x64-gdal-2-4-mapserver-7-4.zip为编译好的dll,c#可以直接使用
release-1900-x64-gdal-2-4-mapserver-7-4-libs.zip,包含头文件和gdal.lib,c/c++可以直接使用
apps
release-1900-x64-gdal-2-4-4-mapserver-7-4-3\bin\gdal\apps目录下包含gdalwarp.exe,需放在外层gdal204.dll同级目录下
wkt 格式
Gdal3.0后 SpatialReference类的导出wkt函数
exportToWkt(out string argout,string[] options)
参数说明
主要设置 MULTILINE=YES / NO,FORMAT=SFSQL / WKT1_SIMPLE / WKT1 / WKT1_GDAL / WKT1_ESRI / WKT2_2015 / WKT2_2018 / WKT2 / DEFAULT
本次调用源影像投影字符串为WKT1_ESRI格式
string esriString;
string gdalString;
var formatEsri = new[] { "FORMAT=WKT1_ESRI" };
var formatGdal = new[] { "FORMAT=WKT1_GDAL" };
spProj.ExportToWkt(out esriString, formatEsri);
spProj.ExportToWkt(out gdalString, formatGdal);
两种格式 投影名称不同
WKT1_ESRI格式
"PROJCS[\"CGCS2000_3_Degree_GK_CM_123E\",GEOGCS[\"GCS_China_Geodetic_Coordinate_System_2000\",DATUM[\"China_2000\",SPHEROID[\"CGCS2000\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",123],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]"
WKT1_GDAL格式
"PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 126E\",GEOGCS[\"China Geodetic Coordinate System 2000\",DATUM[\"China_2000\",SPHEROID[\"CGCS2000\",6378137,298.257222101],AUTHORITY[\"EPSG\",\"1043\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",126],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]"
命令行调用 gdalwarp.exe
重采样方法:-r cubic
输出分辨率:-tr 2 2
设置瓦片:-co TILED=YES,默认为条形
输出投影:-t_srs “wkt”,支持 从SpatialReference导出的wkt字符串,但需要双引号包裹
以下为c#启动进程调用 gdalwarp.exe
const string projName = "PROJCS";
const string centralMeridian = "central_meridian";// ProjectionString从影像获取
var spProj = new SpatialReference(ri.ProjectionString);
// spProj 操作 ...
// .GetProjParm获取中央经线,可对应设置
// .GetAttrValue获取投影名称,可对应设置
// .SetTM 设置横轴墨卡托的 5 个参数,包含中央经线等
string tSrs;
double clong;
clong = spProj.GetProjParm(centralMeridian, clong);
spProj.GetAttrValue(projName,0)
spProj.ExportToWkt(out tSrs);var gdalWarpExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "gdalwarp.exe");
var startInfo = new ProcessStartInfo(gdalWarpExe)
{WindowStyle = ProcessWindowStyle.Normal,Arguments = string.Format("-t_srs {0}{1}{2} -r cubic -tr {3} {4} {5} {6} -co TILED=YES",'"', tSrs,'"', resolutoin, resolutoin, tifFi.FullName, System.IO.Path.Combine(tifPath, "B.TIF")),UseShellExecute = false,RedirectStandardOutput = true,CreateNoWindow = true
};
var process = new Process { StartInfo = startInfo };
process.Start();
参考文献
https://gdal.org/programs/gdalwarp.html
https://gdal.org/api/ogrspatialref.html
这篇关于gdalwarp.exe 调用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!