| | |
| | | { |
| | | public class Handle |
| | | { |
| | | #region 成员变量 |
| | | public static readonly int MAX = 256 * 256; |
| | | |
| | | public static readonly double WaterHeightOffset = 1.0; |
| | |
| | | public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; |
| | | |
| | | public static readonly string GdalPath = ConfigurationManager.AppSettings["gdalPath"]; |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 运行 |
| | |
| | | |
| | | Dataset destDs = Gdal.Warp(dest, new Dataset[] { ds }, warpAppOptions, null, null); |
| | | destDs.Dispose(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重采样 * |
| | | /// </summary> |
| | | private static void Resample(string source, string dest, int width, int height) |
| | | { |
| | | // https://blog.51cto.com/u_16099346/6691820 |
| | | string cmd = string.Format("{0}gdalwarp.exe -t_srs {1} -ts {2} {3} -r {4} -of GTiff \"{5}\" \"{6}\"", GdalPath, "EPSG:4326", width, height, "bilinear", source, dest); |
| | | string err = ExecExe(cmd); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行命令 |
| | | /// </summary> |
| | | public static string ExecExe(string cmd) |
| | | { |
| | | string str = null; |
| | | Process p = null; |
| | | try |
| | | { |
| | | p = new Process(); |
| | | p.StartInfo.FileName = "cmd.exe"; |
| | | p.StartInfo.UseShellExecute = false; |
| | | p.StartInfo.CreateNoWindow = true; |
| | | p.StartInfo.RedirectStandardInput = true; |
| | | p.StartInfo.RedirectStandardOutput = true; |
| | | p.StartInfo.RedirectStandardError = true; |
| | | p.Start(); |
| | | |
| | | StreamWriter si = p.StandardInput; |
| | | StreamReader se = p.StandardError; |
| | | |
| | | si.AutoFlush = true; |
| | | si.WriteLine(cmd); |
| | | si.WriteLine("exit"); |
| | | |
| | | str = se.ReadToEnd(); |
| | | se.Close(); |
| | | si.Close(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | str = ex.Message; |
| | | } |
| | | finally |
| | | { |
| | | if (p != null) p.Close(); |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 暂时不用 |
| | | /// <summary> |
| | | /// 重采样 * |
| | | /// </summary> |
| | | private static void Resample(string source, string dest, int width, int height) |
| | | { |
| | | // https://blog.51cto.com/u_16099346/6691820 |
| | | string cmd = string.Format("{0}gdalwarp.exe -t_srs {1} -ts {2} {3} -r {4} -of GTiff \"{5}\" \"{6}\"", GdalPath, "EPSG:4326", width, height, "bilinear", source, dest); |
| | | string err = ExecExe(cmd); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行命令 |
| | | /// </summary> |
| | | public static string ExecExe(string cmd) |
| | | { |
| | | string str = null; |
| | | Process p = null; |
| | | try |
| | | { |
| | | p = new Process(); |
| | | p.StartInfo.FileName = "cmd.exe"; |
| | | p.StartInfo.UseShellExecute = false; |
| | | p.StartInfo.CreateNoWindow = true; |
| | | p.StartInfo.RedirectStandardInput = true; |
| | | p.StartInfo.RedirectStandardOutput = true; |
| | | p.StartInfo.RedirectStandardError = true; |
| | | p.Start(); |
| | | |
| | | StreamWriter si = p.StandardInput; |
| | | StreamReader se = p.StandardError; |
| | | |
| | | si.AutoFlush = true; |
| | | si.WriteLine(cmd); |
| | | si.WriteLine("exit"); |
| | | |
| | | str = se.ReadToEnd(); |
| | | se.Close(); |
| | | si.Close(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | str = ex.Message; |
| | | } |
| | | finally |
| | | { |
| | | if (p != null) p.Close(); |
| | | } |
| | | return str; |
| | | } |
| | | #endregion |
| | | } |
| | | } |