Ejemplo n.º 1
0
        /// <summary>
        /// liefert einen <see cref="GarminCore.BinaryReaderWriter"/> für die DEM-Datei
        /// </summary>
        /// <param name="dembr"></param>
        /// <param name="outpath">Ausgabepfad</param>
        /// <param name="basefilename"></param>
        /// <param name="overwrite"></param>
        /// <param name="symbolname"></param>
        /// <param name="zoomlevel"></param>
        static void CalculateDem(GarminCore.BinaryReaderWriter dembr, string outpath, string basefilename, bool overwrite, string symbolname, IList <int> zoomlevel)
        {
            GarminCore.Files.StdFile_DEM dem = new GarminCore.Files.StdFile_DEM();
            dem.Read(dembr);
            Console.WriteLine("-> " + basefilename + ".DEM with " + dem.ZoomlevelCount.ToString() + " zoomlevels");

            if (!Directory.Exists(outpath))
            {
                Directory.CreateDirectory(outpath);
            }

            string protfile = Path.Combine(outpath, basefilename + ".txt");

            if (File.Exists(protfile))
            {
                if (!overwrite)
                {
                    throw new Exception("Error: File '" + protfile + "' exists.");
                }
                else
                {
                    File.Delete(protfile);
                }
            }

            using (StreamWriter file = new StreamWriter(protfile)) {
                file.WriteLine(dem.ZoomlevelCount.ToString() + " zoomlevel");

                List <double> lon = new List <double>();
                List <double> lat = new List <double>();

                for (int zl = 0; zl < dem.ZoomlevelCount; zl++)
                {
                    bool used = false;
                    for (int i = 0; i < zoomlevel.Count; i++)
                    {
                        if (zoomlevel[i] == zl)
                        {
                            used = true;
                            break;
                        }
                    }
                    if (used)
                    {
                        GarminCore.Files.DEM.ZoomlevelTableitem record = dem.ZoomLevel[zl].ZoomlevelItem;

                        double west    = record.West;
                        double north   = record.North;
                        double ptdisth = record.PointDistanceHoriz;
                        double ptdistv = record.PointDistanceVert;

                        file.WriteLine("");
                        file.WriteLine("zoomlevel " + zl.ToString());
                        file.WriteLine("{0}x{1} tiles", record.MaxIdxHoriz + 1, record.MaxIdxVert + 1);
                        file.WriteLine("height {0} ... {1}", record.MinHeight, record.MaxHeight);

                        lon.Clear();
                        lat.Clear();
                        int subtileidx = 0;
                        for (int x = 0; x <= record.MaxIdxHoriz; x++)
                        {
                            for (int y = 0; y <= record.MaxIdxVert; y++)
                            {
                                GarminCore.Files.DEM.SubtileTableitem subtile = dem.ZoomLevel[zl].Subtiles[subtileidx].Tableitem;
                                subtileidx++;

                                double tileleft = west + x * (record.PointsHoriz - 1) * ptdisth;
                                double tiletop  = north - y * (record.PointsVert - 1) * ptdistv;

                                file.WriteLine("subtile: x={0}, y={1}, baseheight {2}, heightdiff {3}, west={4}, north={5}",
                                               x,
                                               y,
                                               subtile.Baseheight,
                                               subtile.Diff,
                                               tileleft.ToString(CultureInfo.InvariantCulture),
                                               tiletop.ToString(CultureInfo.InvariantCulture));

                                int maxx = x < record.MaxIdxHoriz ? record.PointsHoriz : record.LastColWidth + 1;
                                int maxy = y < record.MaxIdxVert ? record.PointsVert : record.LastRowHeight + 1;
                                for (int xt = 0; xt < maxx; xt++)
                                {
                                    for (int yt = 0; yt < maxx; yt++)
                                    {
                                        lat.Add(tileleft + xt * ptdisth);
                                        lon.Add(tiletop - yt * ptdistv);
                                    }
                                }

                                WriteGpxFile(outpath, basefilename, zl, x, y, overwrite, symbolname, lon, lat, maxx, maxy);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Funktion für alle Datei-Infos
        /// </summary>
        /// <param name="info"></param>
        /// <param name="hex"></param>
        /// <param name="firsthexadr"></param>
        /// <param name="filedata"></param>
        /// <param name="nodetype">"Thema" der Info</param>
        /// <param name="idx">wenn größer oder gleich 0, dann der Index auf ein Objekt einer Tabelle</param>
        /// <param name="tn"></param>
        public static void SectionAndIndex(StringBuilder info, out byte[] hex, out long firsthexadr, NodeContent.Content4File filedata, NodeContent.NodeType nodetype, int idx, TreeViewData tvd)
        {
            GarminCore.Files.StdFile_DEM dem = filedata.GetGarminFileAsDEM();
            int hexlen = 0;

            firsthexadr = 0;
            hex         = null;

            switch (nodetype)
            {
            case NodeContent.NodeType.DEM_Zoomlevel:
                firsthexadr = dem.PtrZoomlevel;
                if (idx < 0)
                {
                    info.AppendLine("ZoomlevelCount:       " + DecimalAndHexAndBinary(dem.ZoomlevelCount));
                    info.AppendLine("ZoomlevelRecordSize:  " + DecimalAndHexAndBinary(dem.ZoomlevelRecordSize));
                    hexlen = dem.ZoomlevelRecordSize * dem.ZoomlevelCount;
                }
                else
                {
                    GarminCore.Files.DEM.ZoomlevelTableitem record = dem.ZoomLevel[idx].ZoomlevelItem;

                    info.AppendLine("SpecType                (1 Byte): " + DecimalAndHexAndBinary(record.SpecType));
                    info.AppendLine("Number                  (1 Byte): " + DecimalAndHexAndBinary(record.No));
                    info.AppendLine("Tilesize horizontal     (4 Byte): " + DecimalAndHexAndBinary(record.PointsHoriz));
                    info.AppendLine("Tilesize vertical       (4 Byte): " + DecimalAndHexAndBinary(record.PointsVert));
                    info.AppendLine("LastRowHeight           (4 Byte): " + DecimalAndHexAndBinary(record.LastRowHeight));
                    info.AppendLine("LastColWidth            (4 Byte): " + DecimalAndHexAndBinary(record.LastColWidth));
                    info.AppendLine("Unknown12               (2 Byte): " + DecimalAndHexAndBinary(record.Unknown12));
                    info.AppendLine("MaxIdxHoriz             (4 Byte): " + DecimalAndHexAndBinary(record.MaxIdxHoriz));
                    info.AppendLine("MaxIdxVert              (4 Byte): " + DecimalAndHexAndBinary(record.MaxIdxVert));
                    info.AppendLine("Structure               (2 Byte): " + DecimalAndHexAndBinary(record.Structure, 16));
                    info.AppendLine("   OffsetSize              (Bit 0,1) +1: " + record.Structure_OffsetSize + " Byte");
                    info.AppendLine("   BaseheightSize          (Bit 2) +1:   " + record.Structure_BaseheightSize + " Byte");
                    info.AppendLine("   DiffSize                (Bit 3) +1:   " + record.Structure_DiffSize + " Byte");
                    info.AppendLine("   CodingtypeSize          (Bit 4):      " + record.Structure_CodingtypeSize + " Byte");
                    info.AppendLine("SubtileTableitemSize    (2 Byte): " + DecimalAndHexAndBinary(record.SubtileTableitemSize));
                    info.AppendLine("SubtileTableOffset      (4 Byte): " + DecimalAndHexAndBinary(record.PtrSubtileTable));
                    info.AppendLine("HeightdataOffset        (4 Byte): " + DecimalAndHexAndBinary(record.PtrHeightdata));
                    info.AppendLine("Left                    (4 Byte): " + DecimalAndHexAndBinary(record.west) + "; " + record.West.ToString() + "°");
                    info.AppendLine("Top                     (4 Byte): " + DecimalAndHexAndBinary(record.north) + "; " + record.North.ToString() + "°");
                    info.AppendLine("PointDistanceVertical   (4 Byte): " + DecimalAndHexAndBinary(record.pointDistanceVert) + "; " + record.PointDistanceVert.ToString() + "°");
                    info.AppendLine("PointDistanceHorizontal (4 Byte): " + DecimalAndHexAndBinary(record.pointDistanceHoriz) + "; " + record.PointDistanceHoriz.ToString() + "°");
                    info.AppendLine("MinHeight               (2 Byte): " + DecimalAndHexAndBinary(record.MinHeight));
                    info.AppendLine("MaxHeight               (2 Byte): " + DecimalAndHexAndBinary(record.MaxHeight));

                    firsthexadr += idx * dem.ZoomlevelRecordSize;
                    hexlen       = dem.ZoomlevelRecordSize;
                }
                break;

            case NodeContent.NodeType.Index:
                // etwas tricky, aber nc.Data des übergeordneten Knotens ist der ZoomLevel-Index
                if (tvd.TreeView.SelectedNode != null)
                {
                    int         zoomlevelidxidx = -1;
                    NodeContent nc = NodeContent4TreeNode(tvd.TreeView.SelectedNode.Parent);
                    if (nc.Type == NodeContent.NodeType.Index)
                    {
                        zoomlevelidxidx = (int)nc.Data;
                    }
                    if (zoomlevelidxidx >= 0)
                    {
                        GarminCore.Files.DEM.ZoomlevelTableitem zoomlevel = dem.ZoomLevel[zoomlevelidxidx].ZoomlevelItem;
                        GarminCore.Files.DEM.SubtileTableitem   subtile   = dem.ZoomLevel[zoomlevelidxidx].Subtiles[idx].Tableitem;
                        info.AppendLine("Offset     (" + zoomlevel.Structure_OffsetSize + " Byte): " + DecimalAndHexAndBinary(subtile.Offset));
                        info.AppendLine("Baseheight (" + zoomlevel.Structure_BaseheightSize + " Byte): " + DecimalAndHexAndBinary(subtile.Baseheight));
                        info.AppendLine("Diff       (" + zoomlevel.Structure_DiffSize + " Byte): " + DecimalAndHexAndBinary(subtile.Diff));
                        if (zoomlevel.Structure_CodingtypeSize > 0)
                        {
                            info.AppendLine("Type       (" + zoomlevel.Structure_CodingtypeSize + " Byte): " + DecimalAndHexAndBinary(subtile.Type));
                        }
                        info.AppendLine();
                        info.AppendLine("coded data (" + DecimalAndHexAndBinary(dem.ZoomLevel[zoomlevelidxidx].Subtiles[idx].DataLength) + " Bytes):");

                        firsthexadr = zoomlevel.PtrHeightdata + subtile.Offset;
                        hexlen      = dem.ZoomLevel[zoomlevelidxidx].Subtiles[idx].DataLength;
                    }
                }
                break;

            default:
                info.AppendLine("internal error: no info for nodetype '" + nodetype.ToString() + "'");
                break;
            }

            if (hexlen > 0)
            {
                hex = HexRange(firsthexadr, filedata.BinaryReader, hexlen);
            }
        }