示例#1
0
        /// <summary>
        /// "sichere" Linien erzeugen (ev. aufteilen)
        /// </summary>
        /// <param name="line"></param>
        /// <param name="maxsize">max. "quadratisches" Umgrenzung in Grad</param>
        /// <returns></returns>
        static List <DetailMap.Poly> MakeSafeLines(DetailMap.Poly line, int maxsize)
        {
            List <DetailMap.Poly> lst = new List <DetailMap.Poly>();

            // zwischen 2 zu weit entfernte Punkte wird ein neuer Punkt eingefügt
            MapUnitPoint p2 = line.PointCount > 1 ? line.GetPoint(0) : null;

            for (int i = 0; i < line.PointCount - 1; i++)
            {
                MapUnitPoint p1 = p2;
                if (p1 != null)
                {
                    p2 = line.GetPoint(i + 1);
                    if (Math.Abs(p2.Longitude - p1.Longitude) > maxsize ||
                        Math.Abs(p2.Latitude - p1.Latitude) > maxsize)
                    {
                        line.AddPoint(p1 + (p2 - p1) / 2, false, true, i + 1);
                        i--;
                        p2 = p1;
                    }
                }
            }

            lst.Add(line);

            // sind zu viele Punkte (in der letzten Linie der Liste) vorhanden, wird die Linie geteilt
            if (lst[lst.Count - 1].PointCount > MAX_POINTS_IN_LINE)
            {
                DetailMap.Poly line1      = lst[lst.Count - 1];
                int            wantedSize = (line1.PointCount < MAX_POINTS_IN_LINE + MIN_POINTS_IN_LINE) ?
                                            line1.PointCount / 2 + 10 :
                                            MAX_POINTS_IN_LINE;
                lst.Add(splitPoly(line1, wantedSize - 1));
            }

            // Alle Linien der Liste haben jetzt weder zu viele Punkte noch zu weit entfernte Punkte.

            for (int i = 0; i < lst.Count; i++)
            {
                DetailMap.Poly line1 = lst[i];
                if (line1.Bound.Width > maxsize ||
                    line1.Bound.Height > maxsize) // Aufteilung ist nötig
                {
                    Bound testbound = new Bound(line1.GetPoint(0));
                    for (int j = 1; j < line1.PointCount; j++)
                    {
                        testbound.Embed(line1.GetPoint(j));
                        if (testbound.Width > maxsize ||
                            testbound.Height > maxsize)
                        {
                            DetailMap.Poly line2 = splitPoly(line1, j - 1);
                            lst.Insert(i + 1, line2); // wird als nächste getestet
                            break;
                        }
                    }
                }
            }

            return(lst);
        }