Esempio n. 1
0
        /// <summary>
        /// erzeugt eine Geo-PNG-Datei aus den HGT-Daten
        /// </summary>
        /// <param name="r"></param>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <param name="GeoColor"></param>
        /// <param name="DummyGeoColor"></param>
        static void CreateGeofile(HGTReader r, int lat, int lon, SortedDictionary <int, Color> GeoColor, Color DummyGeoColor)
        {
            string bitmapfile = string.Format("Height_{0}{1:D2}{2}{3:D3}.png",
                                              lat >= 0 ? "N" : "S", lat,
                                              lon >= 0 ? "E" : "W", lon);
            Bitmap bm;

            if (GeoColor.Count > 2)
            {
                bm = r.GetBitmap(GeoColor, DummyGeoColor);
            }
            else
            {
                bm = r.GetBitmap();
            }

            bm.Save(bitmapfile, System.Drawing.Imaging.ImageFormat.Png);
            //string worldfile = Path.GetFileNameWithoutExtension(bitmapfile) + ".pnw";
            string worldfile = bitmapfile + "w";         // Quantum-GIS will es so

            using (StreamWriter sw = new StreamWriter(worldfile)) {
                sw.WriteLine("{0}", (1 / (double)bm.Width).ToString(CultureInfo.InvariantCulture));
                sw.WriteLine("0");
                sw.WriteLine("0");
                sw.WriteLine("{0}", (-1 / (double)bm.Height).ToString(CultureInfo.InvariantCulture)); // negativ, weil die Zeilen von oben nach unten enthalten sind
                sw.WriteLine("{0}", lon);
                sw.WriteLine("{0}", lat + 1);                                                         // oberer Rand
            }
            Console.Error.WriteLine("Datei {0} geschrieben", bitmapfile);
        }
Esempio n. 2
0
        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);
        }