public SRTMReader(BinaryReader reader, SRTMFormat format) { if (reader == null) { throw new NullReferenceException("BinaryReader can't be NULL."); } _binaryReader = reader; _format = format; if (_format == SRTMFormat.SRTM1) { _tileSize = 3601; } else if (_format == SRTMFormat.SRTM3) { _tileSize = 1201; } else if (_format == SRTMFormat.Unknown) { throw new FormatException("Unkown HGT file format."); } _heightData = new Int16[_tileSize, _tileSize]; }
static void Main(string[] args) { if (args.Length < 1) { WriteInstructions(); } else { bool verbose = false; int i = 0, count = args.Length; if (args[0] == "-verbose") { verbose = true; i++; if (args.Length == 1) { WriteInstructions(); Environment.Exit(0); } } for (; i < count; i++) { try { FileStream file = File.Open(args[i], FileMode.Open); BinaryReader reader = new BinaryReader(file); SRTMFormat format = SRTMFormat.Unknown; if (file.Length == 3601 * 3601 * sizeof(Int16)) { format = SRTMFormat.SRTM1; } else if (file.Length == 1201 * 1201 * sizeof(Int16)) { format = SRTMFormat.SRTM3; } if (verbose) { Console.WriteLine("Reading SRTM file: " + args[i]); Console.WriteLine(" - Length: " + file.Length + " Bytes"); Console.WriteLine(" - Format: " + format.ToString() + Environment.NewLine); } SRTMReader srtm = new SRTMReader(reader, format); srtm.ReadAllData(false); BitmapTerrain bmpTerrain = new BitmapTerrain(srtm.GetTileSize(), srtm.GetTileSize()); bmpTerrain.ConvertFromSRTM(srtm, BitmapChannels.ChannelRed | BitmapChannels.ChannelGreen); if (verbose) { Console.WriteLine("Writing TIFF file from SRTM file..."); } string tiffPath = args[i]; int dot = tiffPath.IndexOf('.'); tiffPath = tiffPath.Substring(0, dot); tiffPath += ".tiff"; TIFFWriter.ExportTIFF(bmpTerrain.GetBitmap(), tiffPath); if (verbose) { Console.WriteLine("Success" + Environment.NewLine); } } catch (Exception ex) { if (verbose) { Console.WriteLine("Couldn't convert SRTM file:"); Console.WriteLine(ex.Message + Environment.NewLine); } } } } }