示例#1
0
 public void SaveToStream(Stream stream)
 {
     if (this.Segments != null && this.Points != null)
     {
         byte[] bytes = BitConverter.GetBytes(this.Segments.Length);
         stream.Write(bytes, 0, bytes.Length);
         ShapeSegment[] array = this.Segments;
         for (int i = 0; i < array.Length; i++)
         {
             ShapeSegment shapeSegment = array[i];
             bytes    = new byte[Marshal.SizeOf(typeof(byte))];
             bytes[0] = (byte)shapeSegment.Type;
             stream.Write(bytes, 0, bytes.Length);
             bytes = BitConverter.GetBytes(shapeSegment.Length);
             stream.Write(bytes, 0, bytes.Length);
         }
         bytes = BitConverter.GetBytes(this.Points.Length);
         stream.Write(bytes, 0, bytes.Length);
         MapPoint[] array2 = this.Points;
         for (int j = 0; j < array2.Length; j++)
         {
             MapPoint mapPoint = array2[j];
             bytes = BitConverter.GetBytes(mapPoint.X);
             stream.Write(bytes, 0, bytes.Length);
             bytes = BitConverter.GetBytes(mapPoint.Y);
             stream.Write(bytes, 0, bytes.Length);
         }
     }
 }
示例#2
0
        private void UpdateMultiPolygonWithHoles()
        {
            int num  = 0;
            int num2 = 0;

            ShapeSegment[] array = this.Segments;
            for (int i = 0; i < array.Length; i++)
            {
                ShapeSegment shapeSegment = array[i];
                if (shapeSegment.Type == SegmentType.Polygon)
                {
                    if (shapeSegment.PolygonSignedArea <= 0.0)
                    {
                        num++;
                    }
                    else
                    {
                        num2++;
                    }
                }
                else if (shapeSegment.Type == SegmentType.StartFigure)
                {
                    this.MultiPolygonWithHoles = true;
                    return;
                }
            }
            this.MultiPolygonWithHoles = (num > 1 && num2 > 0);
        }
        public static void MoveLargestSegmentToFront(ref MapPoint[] points, ref ShapeSegment[] segments)
        {
            GeoUtils.CalculateSignedArea(ref points, ref segments);
            double num  = 0.0;
            int    num2 = 0;
            int    num3 = 0;

            for (int i = 0; i < segments.Length; i++)
            {
                if (segments[i].PolygonSignedArea < num)
                {
                    num  = segments[i].PolygonSignedArea;
                    num2 = i;
                }
            }
            if (num2 != 0)
            {
                List <MapPoint> list = new List <MapPoint>(points);
                num3 = 0;
                for (int j = 0; j < num2; j++)
                {
                    num3 += segments[j].Length;
                }
                List <MapPoint> range = list.GetRange(num3, segments[num2].Length);
                list.RemoveRange(num3, segments[num2].Length);
                list.InsertRange(0, range);
                points = list.ToArray();
                ShapeSegment shapeSegment = segments[0];
                segments[0]    = segments[num2];
                segments[num2] = shapeSegment;
            }
        }
        public static void CutShapes(ref MapPoint[] points, ref ShapeSegment[] segments)
        {
            List <ShapeSegment> list          = new List <ShapeSegment>();
            List <MapPoint>     list2         = new List <MapPoint>();
            PolygonCutter       polygonCutter = new PolygonCutter();
            int num = 0;

            ShapeSegment[] array = segments;
            for (int i = 0; i < array.Length; i++)
            {
                ShapeSegment segment = array[i];
                if (segment.Length > 0)
                {
                    bool flag = false;
                    List <ShapeSegment> list3 = default(List <ShapeSegment>);
                    List <MapPoint>     list4 = default(List <MapPoint>);
                    polygonCutter.ProcessShapeSegment(segment, (IList <MapPoint>)points, num, PolygonClosingPole.North, out list3, out list4, out flag);
                    if (flag)
                    {
                        List <ShapeSegment> list5 = default(List <ShapeSegment>);
                        List <MapPoint>     list6 = default(List <MapPoint>);
                        polygonCutter.ProcessShapeSegment(segment, (IList <MapPoint>)points, num, PolygonClosingPole.South, out list5, out list6, out flag);
                        ShapeSegment[] array2 = list3.ToArray();
                        MapPoint[]     array3 = list4.ToArray();
                        GeoUtils.CalculateSignedArea(ref array3, ref array2);
                        double num2 = 0.0;
                        for (int j = 0; j < array2.Length; j++)
                        {
                            num2 += Math.Abs(array2[j].PolygonSignedArea);
                        }
                        ShapeSegment[] array4 = list5.ToArray();
                        MapPoint[]     array5 = list6.ToArray();
                        GeoUtils.CalculateSignedArea(ref array5, ref array4);
                        double num3 = 0.0;
                        for (int k = 0; k < array4.Length; k++)
                        {
                            num3 += Math.Abs(array4[k].PolygonSignedArea);
                        }
                        if (num2 < num3)
                        {
                            list.AddRange(list3);
                            list2.AddRange(list4);
                        }
                        else
                        {
                            list.AddRange(list5);
                            list2.AddRange(list6);
                        }
                    }
                    else
                    {
                        list.AddRange(list3);
                        list2.AddRange(list4);
                    }
                }
                num += segment.Length;
            }
            segments = list.ToArray();
            points   = list2.ToArray();
        }
 public void ProcessShapeSegment(ShapeSegment segment, IList <MapPoint> points, int firstPointIndex, PolygonClosingPole closingPole, out List <ShapeSegment> segments, out List <MapPoint> segmentPoints, out bool isClosedAtPole)
 {
     isClosedAtPole = false;
     segments       = new List <ShapeSegment>();
     segmentPoints  = new List <MapPoint>();
     this.Load(points, firstPointIndex, segment.Length, closingPole);
     foreach (PolygonPart shape in this.GetShapes())
     {
         ShapeSegment item = default(ShapeSegment);
         item.Type   = segment.Type;
         item.Length = shape.Points.Count;
         segments.Add(item);
         segmentPoints.AddRange(shape.Points);
         isClosedAtPole |= shape.isClosedAtPole;
     }
 }
示例#6
0
 public void Simplify(Shape shape, double resolution)
 {
     if (!(resolution <= 0.0))
     {
         List <ShapeSegment> list  = new List <ShapeSegment>();
         List <MapPoint>     list2 = new List <MapPoint>();
         int num = 0;
         for (int i = 0; i < shape.ShapeData.Segments.Length; i++)
         {
             ShapeSegment item = shape.ShapeData.Segments[i];
             if (item.Type != 0 && item.Type != SegmentType.PolyLine)
             {
                 list.Add(item);
                 for (int j = 0; j < item.Length; j++)
                 {
                     list2.Add(shape.ShapeData.Points[num++]);
                 }
             }
             else
             {
                 MapPoint[] array = new MapPoint[item.Length];
                 for (int k = 0; k < item.Length; k++)
                 {
                     array[k] = shape.ShapeData.Points[num++];
                 }
                 ReducedPointList reducedPointList = this.ReducePoints(array, resolution);
                 if (reducedPointList.DistinctCount >= 3)
                 {
                     ShapeSegment item2 = default(ShapeSegment);
                     item2.Type   = item.Type;
                     item2.Length = reducedPointList.Count;
                     list.Add(item2);
                     list2.AddRange(reducedPointList);
                 }
             }
         }
         shape.ShapeData.Segments = list.ToArray();
         shape.ShapeData.Points   = list2.ToArray();
         shape.ShapeData.UpdateStoredParameters();
     }
 }