static long Do4Tile(Options opt, int lat, int lon, long FirstID, ref string sOutfile) { long LastID = FirstID; try { Console.Error.WriteLine("==> Lese Ausgangsdaten Lat {0}° Lon {1}° ...", lat, lon); HGTReader r = new HGTReader(lat, lon, opt.HGTPath); if (opt.OnlyGeoPng) // erzeugt nur ein georef. Bitmap { CreateGeofile(r, lat, lon, opt.GeoColor, opt.DummyGeoColor); return(0); } else { Console.Error.WriteLine("Daten übernehmen ..."); ContourProcessor2 cp = new ContourProcessor2(r, opt.MaxThreads); if (opt.OnlyArcInfoASCIIGrid) { CreateArcInfoASCIIGrid(string.Format("Height_{0}{1:D2}{2}{3:D3}.asc", lat >= 0 ? "N" : "S", lat, lon >= 0 ? "E" : "W", lon), cp); return(0); } else { cp.FirstID = FirstID; if (sOutfile.Length > 0) { cp.Outfile = sOutfile; } sOutfile = cp.Outfile; cp.ShowPoints = opt.ShowPoints; cp.ShowAreas = opt.ShowAreas; cp.OSMBound = opt.OSMBound; cp.OSMBounds = opt.OSMBounds; cp.OSMTimestamp = opt.OSMTimestamp; cp.OSMUser = opt.OSMUser; cp.OSMVersion = opt.OSMVersion; cp.OSMVisible = opt.OSMVisible; if (File.Exists(cp.Outfile) && !opt.OutputOverwrite) { Console.Error.WriteLine("Zieldatei '{0}' existiert schon ... Abbruch", cp.Outfile); FileStream fsr = new FileStream(cp.Outfile, FileMode.Open, FileAccess.Read); GZipStream decompress = Path.GetExtension(cp.Outfile).ToLower() == ".gz" ? new GZipStream(fsr, CompressionMode.Decompress) : null; using (StreamReader sr = new StreamReader(decompress != null ? (Stream)decompress : fsr)) { string line; sr.ReadLine(); // <?xml... sr.ReadLine(); // <osm... do { line = sr.ReadLine(); if (line != null && line.Length > 3 && line.Substring(0, 3) == "<no") { // <node id='1010000014' line = line.Substring(10); int pos = line.IndexOf('\''); if (pos > 0) { LastID = Convert.ToInt32(line.Substring(0, pos)); } } else { break; } } while (line != null); } return(LastID); } cp.CreateIsohypsen((short)opt.MinorDistance, opt.MediumFactor * opt.MinorDistance, opt.MajorFactor * opt.MediumFactor * opt.MinorDistance, opt.MaxNodesPerWay, opt.WriteElevationType, opt.FakeDistance, opt.MinVerticePoints, opt.MinBoundingbox, opt.DouglasPeucker, opt.LineBitmapWidth, opt.PolylineBitmapWidth, opt.Textdata); Console.Error.WriteLine("verwendete OSM-ID's: {0} .. {1}", cp.FirstID, cp.LastID); Console.Error.WriteLine("==> OSM-Datei: {0}", cp.Outfile); LastID = cp.LastID; } cp = null; GC.Collect(); } } catch (Exception ex) { Console.Error.WriteLine("Fehler: " + ex.Message); Console.Error.WriteLine(ex.StackTrace); LastID = FirstID; // es sind keine ID's dazu gekommen } return(LastID); }
/// <summary> /// erzeugt aus den Daten im Contour-Prozessor eine Datei im Format "ArcInfo ASCII Grid" /// </summary> /// <param name="filename"></param> /// <param name="cp"></param> static void CreateArcInfoASCIIGrid(string filename, ContourProcessor2 cp) { /* * ncols xxxxx * ncols refers to the number of columns in the grid and xxxxx is the numerical value * * nrows xxxxx * nrows refers to the number of rows in the grid and xxxxx is the numerical value * * xllcorner xxxxx * xllcorner refers to the western edge of the grid and xxxxx is the numerical value * xllcorner and yllcorner are given as the EDGES of the grid, NOT the centers of the edge cells. * The origin of the grid is the upper left and terminus at the lower right. * * yllcorner xxxxx * yllcorner refers to the southern edge of the grid and xxxxx is the numerical value * * cellsize xxxxx * cellsize refers to the resolution of the grid and xxxxx is the numerical value * * nodata_value xxxxx * nodata_value refers to the value that represents missing data and xxxxx is the numerical value. This is * optional and your parser should not assume it will be present. Note: that if you need a good value, the ESRI default is -9999. * * Beispiel: * ncols 157 * nrows 171 * xllcorner -156.08749650000 * yllcorner 18.870890200000 * cellsize 0.00833300 * 0 0 1 1 1 2 3 3 5 6 8 9 12 14 18 21 25 30 35 41 47 53 * 59 66 73 79 86 92 97 102 106 109 112 113 113 113 111 109 106 * 103 98 94 89 83 78 72 67 61 56 51 46 41 37 32 29 25 22 19 * etc... */ using (StreamWriter sw = new StreamWriter(filename)) { short nodata = -29999; Console.Error.WriteLine("schreibe Datei '{0}' ...", filename); sw.WriteLine("ncols {0}", cp.Width.ToString()); sw.WriteLine("nrows {0}", cp.Height.ToString()); //sw.WriteLine("xllcorner {0}", (cp.Left + 1.0 / (2 * cp.Width)).ToString(CultureInfo.InvariantCulture)); //sw.WriteLine("yllcorner {0}", (cp.Bottom + 1.0 / (2 * cp.Height)).ToString(CultureInfo.InvariantCulture)); sw.WriteLine("xllcorner {0}", cp.Left.ToString(CultureInfo.InvariantCulture)); sw.WriteLine("yllcorner {0}", cp.Bottom.ToString(CultureInfo.InvariantCulture)); sw.WriteLine("cellsize {0}", (1.0 / cp.Width).ToString(CultureInfo.InvariantCulture)); sw.WriteLine("nodata_value {0}", nodata); for (int r = 0; r < cp.Height; r++) { for (int c = 0; c < cp.Width; c++) { int v = cp.Get(c, r); if (v == HGTReader.NoValue) { v = nodata; } sw.Write(" " + v.ToString()); } sw.WriteLine(); } } }