| | |
| | | if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return; |
| | | |
| | | SetTerrainInfo(ds, layer); |
| | | CreateTerrainPng(ds, layer, outPath); |
| | | //CreateTerrainPng(ds, layer, outPath); |
| | | } |
| | | finally |
| | | { |
| | |
| | | if (float.IsNaN(buffer[offset]) || buffer[offset] < -999) continue; |
| | | |
| | | //int val = Convert.ToInt32(buffer[offset] * 100); |
| | | int val = Convert.ToInt32((buffer[offset] - layer.extension.minHeight) * 100 / perHeight); |
| | | int val = Convert.ToInt32((buffer[offset] - layer.extension.minHeight + heightOffset) * 100 / perHeight); |
| | | int r = val / 65536; |
| | | int g = (val - r * 65536) / 256; |
| | | int b = val % 256; |
| | |
| | | SetWaterData(layer, files); |
| | | if (files.Count != layer.waters.data.Count) return; |
| | | |
| | | ProcessWaters(files, outPath, layer); |
| | | //ProcessWaters(files, outPath, layer); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | List<string> vyFiles = GetFiles(flowPath, "vy"); |
| | | if (null == vxFiles || null == vyFiles || vxFiles.Count != vyFiles.Count || vxFiles.Count != layer.waters.data.Count) return; |
| | | |
| | | Parallel.For(0, vxFiles.Count, i => |
| | | //Parallel.For(0, vxFiles.Count, i => |
| | | for (int i = 0; i < vxFiles.Count; i++) |
| | | { |
| | | Dataset vxDs = null, vyDs = null; |
| | | try |
| | | { |
| | | vxDs = Gdal.Open(vxFiles[i], Access.GA_ReadOnly); |
| | | vyDs = Gdal.Open(vyFiles[i], Access.GA_ReadOnly); |
| | | if (null == vxDs || 0 == vxDs.RasterCount || null == vxDs.GetSpatialRef() || |
| | | null == vyDs || 0 == vyDs.RasterCount || null == vyDs.GetSpatialRef()) return; |
| | | |
| | |
| | | if (null != vxDs) vxDs.Dispose(); |
| | | if (null != vyDs) vyDs.Dispose(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | float fx = GetFloatValue(vxBuffer[offset]); |
| | | float fy = GetFloatValue(vyBuffer[offset]); |
| | | |
| | | double dx = fx * 0.5 + 0.5; |
| | | double dy = fy * 0.5 + 0.5; |
| | | double dv = Math.Sqrt(Math.Pow(fx, 2) + Math.Pow(fy, 2)); |
| | | double dv = GetXyValue(fx, fy); |
| | | double dx = float.IsNaN(fx) ? 0 : fx * 0.5 + 0.5; |
| | | double dy = float.IsNaN(fy) ? 0 : fy * 0.5 + 0.5; |
| | | |
| | | int r = Convert.ToInt32(dv * 255); |
| | | int g = Convert.ToInt32(dx * 255); |
| | |
| | | /// </summary> |
| | | private static float GetFloatValue(float val) |
| | | { |
| | | return (float.IsNaN(val) || val < -999) ? 0 : val; |
| | | //return (float.IsNaN(val) || val < -999) ? float.NaN : val; |
| | | if (float.IsNaN(val) || val < -999) return float.NaN; |
| | | if (val > 1) return 1; |
| | | if (val < -1) return -1; |
| | | |
| | | return val; |
| | | } |
| | | |
| | | private static double GetXyValue(float fx, float fy) |
| | | { |
| | | if (float.IsNaN(fx) && float.IsNaN(fy)) |
| | | { |
| | | return 0; |
| | | } |
| | | if (float.IsNaN(fx)) |
| | | { |
| | | return Math.Abs(fy); |
| | | } |
| | | if (float.IsNaN(fy)) |
| | | { |
| | | return Math.Abs(fx); |
| | | } |
| | | |
| | | return Math.Sqrt(Math.Pow(fx, 2) + Math.Pow(fy, 2)); |
| | | } |
| | | #endregion |
| | | |