| | |
| | | string temp = Path.Combine(outPath, "temp"); |
| | | if (!Directory.Exists(temp)) Directory.CreateDirectory(temp); |
| | | |
| | | CopeTerrain(terrainFile, outPath, layer); |
| | | CopeTerrain(terrainFile, waterPath, outPath, layer); |
| | | CopeWater(waterPath, outPath, layer); |
| | | CopeFlow(flowPath, outPath, layer); |
| | | CopeLayerJson(outPath, layer); |
| | |
| | | /// <summary> |
| | | /// 处理地形 |
| | | /// </summary> |
| | | private static void CopeTerrain(string terrainFile, string outPath, Domain.Layer layer) |
| | | private static void CopeTerrain(string terrainFile, string waterPath, string outPath, Domain.Layer layer) |
| | | { |
| | | Dataset ds = null; |
| | | try |
| | |
| | | if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return; |
| | | |
| | | SetTerrainInfo(ds, layer); |
| | | SetWaterInfo(waterPath, layer); |
| | | CreateTerrainPng(ds, layer, outPath); |
| | | } |
| | | finally |
| | |
| | | graphic.Clear(Color.Transparent); // 填充透明色 |
| | | |
| | | //double perHeight = (layer.terrain.maxHeight - layer.terrain.minHeight) * 100 / 65536; |
| | | double differ = layer.terrain.maxHeight - layer.terrain.minHeight; |
| | | //double differ = layer.terrain.maxHeight - layer.terrain.minHeight; |
| | | double differ = layer.extension.maxHeight - layer.extension.minHeight - 1, minHeight = layer.extension.minHeight - 1; |
| | | for (int x = 0; x < width; x++) |
| | | { |
| | | for (int y = 0; y < height; y++) |
| | | { |
| | | int offset = x + y * width; |
| | | if (float.IsNaN(buffer[offset]) || buffer[offset] < -999) continue; |
| | | if (float.IsNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue; |
| | | |
| | | //int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) * 100 / perHeight); |
| | | int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) / differ * 65536); |
| | | //int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) / differ * 255); // 65535 |
| | | int val = Convert.ToInt32((buffer[offset] - minHeight) / differ * 255); |
| | | int r = 0; |
| | | int g = val / 256; |
| | | int b = val % 256; |
| | | int g = 0; |
| | | int b = val > 255 ? 255 : val; |
| | | |
| | | Color color = Color.FromArgb(127, r, g, b); |
| | | image.SetPixel(x, y, color); |
| | |
| | | |
| | | #region 水面 |
| | | /// <summary> |
| | | /// 处理水面 |
| | | /// 设置水面信息 |
| | | /// </summary> |
| | | private static void CopeWater(string waterPath, string outPath, Domain.Layer layer) |
| | | private static void SetWaterInfo(string waterPath, Domain.Layer layer) |
| | | { |
| | | List<string> files = GetFiles(waterPath); |
| | | List<string> files = layer.waters.files = GetFiles(waterPath); |
| | | if (null == files || files.Count == 0) return; |
| | | |
| | | SetWaterData(layer, files); |
| | | SetWaterHeight(layer, files); |
| | | if (files.Count != layer.waters.data.Count) return; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 处理水面 |
| | | /// </summary> |
| | | private static void CopeWater(string waterPath, string outPath, Domain.Layer layer) |
| | | { |
| | | List<String> files = layer.waters.files; |
| | | if (files.Count == 0 || files.Count != layer.waters.data.Count) return; |
| | | |
| | | ProcessWaters(files, outPath, layer); |
| | | } |
| | |
| | | private static List<String> GetFiles(string path, string prefix = "") |
| | | { |
| | | string[] files = Directory.GetFiles(path, prefix + "*.tif?", SearchOption.TopDirectoryOnly); |
| | | if (null == files || files.Length == 0) return null; |
| | | if (null == files || files.Length == 0) return new List<string>(); |
| | | |
| | | List<string> list = files.ToList(); |
| | | list.Sort(); |
| | |
| | | DateTime d = new DateTime(now.Year, now.Month, now.Day, hour, minute, second); |
| | | layer.waters.data.Add((d.Ticks - startTicks) / 10000); |
| | | } |
| | | layer.duration.start = layer.waters.data[0]; |
| | | layer.duration.end = layer.waters.data[layer.waters.data.Count - 1]; |
| | | } |
| | | |
| | | /// <summary> |