| | |
| | | if (!Directory.Exists(temp)) Directory.CreateDirectory(temp); |
| | | |
| | | CopeTerrain(terrainFile, outPath, layer); |
| | | CopeWater(waterPath, outPath, layer); |
| | | //CopeWater(waterPath, outPath, layer); |
| | | CopeFlow(flowPath, outPath, layer); |
| | | //CopeLayerJson(outPath, layer); |
| | | CopeLayerJson(outPath, layer); |
| | | |
| | | if (Directory.Exists(temp)) Directory.Delete(temp, true); |
| | | } |
| | |
| | | if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return; |
| | | |
| | | SetTerrainInfo(ds, layer); |
| | | CreateTerrainPng(ds, layer, outPath); |
| | | //CreateTerrainPng(ds, layer, outPath); |
| | | } |
| | | finally |
| | | { |
| | |
| | | foreach (int[] sizes in layer.terrain.size) |
| | | { |
| | | string tif = Path.Combine(tempPath, DateTime.Now.Ticks.ToString() + ".tif"); |
| | | Resample(ds.GetDescription(), tif, sizes[0], sizes[1]); |
| | | //Resample(ds.GetDescription(), tif, sizes[0], sizes[1]); |
| | | Resample(ds, tif, sizes[0], sizes[1]); |
| | | if (!File.Exists(tif)) |
| | | { |
| | | continue; |
| | |
| | | |
| | | /// <summary> |
| | | /// 重采样 |
| | | /// </summary> |
| | | private static void Resample(Dataset ds, string dest, int width, int height) |
| | | { |
| | | // https://blog.51cto.com/u_16099346/6691820 |
| | | //string args = string.Format("-t_srs {0} -ts {1} {2} -r {3} -of {4}", "EPSG:4326", width, height, "bilinear", "GTiff"); |
| | | //string[] options = Gdal.ParseCommandLine(args); |
| | | string[] options = new string[] |
| | | { |
| | | "-t_srs", |
| | | "EPSG:4326", |
| | | "-ts", |
| | | width.ToString(), |
| | | height.ToString(), |
| | | "-r", |
| | | "bilinear", |
| | | "-of", |
| | | "GTiff" |
| | | }; |
| | | GDALWarpAppOptions warpAppOptions = new GDALWarpAppOptions(options); |
| | | |
| | | 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) |
| | | { |
| | |
| | | { |
| | | for (int y = 0; y < height; y++) |
| | | { |
| | | int offset = x + y * height; |
| | | if (float.IsNaN(buffer[offset]) || buffer[offset] == -9999) |
| | | int offset = x + y * width; |
| | | if (float.IsNaN(buffer[offset]) || buffer[offset] < -999) |
| | | { |
| | | //image.SetPixel(x, y, Color.Transparent); |
| | | continue; |
| | |
| | | Graphics graphic = Graphics.FromImage(image); |
| | | graphic.Clear(Color.Transparent); // 填充透明色 |
| | | |
| | | // 用 R通道表示,流向为归一化的二维向量(x,y),G通道表示为 x *255 , B通道表示为 y * 255 |
| | | for (int x = 0; x < width; x++) |
| | | { |
| | | for (int y = 0; y < height; y++) |
| | | { |
| | | //int offset = x + y * height; |
| | | //if (float.IsNaN(vxBuffer[offset]) || vxBuffer[offset] == -9999) continue; |
| | | int offset = x + y * width; |
| | | if (float.IsNaN(vxBuffer[offset]) || vxBuffer[offset] < -999 || |
| | | float.IsNaN(vyBuffer[offset]) || vyBuffer[offset] < -999) continue; |
| | | |
| | | float vx = vxBuffer[offset], vy = vyBuffer[offset]; |
| | | //int val = Convert.ToInt32(vxBuffer[offset] * 100); |
| | | //int r = val / 65536; |
| | | //int g = (val - r * 65536) / 256; |
| | | //int b = val % 256; |
| | | int r = 0; |
| | | int g = 0; |
| | | int b = 0; |
| | | |
| | | //Color color = Color.FromArgb(127, r, g, b); |
| | | //image.SetPixel(x, y, color); |
| | | Color color = Color.FromArgb(127, r, g, b); |
| | | image.SetPixel(x, y, color); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | sw.Write(json); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 暂时不用 |
| | | /// <summary> |
| | | /// 重采样 * |
| | | /// </summary> |
| | | private static void Resample(Dataset ds, string dest, int width, int height) |
| | | { |
| | | // 设置Warp的选项:https://blog.csdn.net/qq_43210879/article/details/121350561 |
| | | string[] options = new string[] { |
| | | "format=GTiff", |
| | | "width=" + width, |
| | | "height=" + height, |
| | | "dstSRS=EPSG:4326" |
| | | }; |
| | | |
| | | OSGeo.GDAL.Driver driver = Gdal.GetDriverByName("GTiff"); |
| | | Dataset destDs = driver.Create(dest, width, height, ds.RasterCount, ds.GetRasterBand(1).DataType, null); |
| | | |
| | | GDALWarpAppOptions warpAppOptions = new GDALWarpAppOptions(options); |
| | | Gdal.Warp(destDs, new Dataset[] { ds }, warpAppOptions, null, null); |
| | | |
| | | destDs.Dispose(); |
| | | } |
| | | #endregion |
| | | } |