示例#1
0
 internal void SaveToStream(Stream stream)
 {
     if (Segments != null && Points != null)
     {
         byte[] bytes = BitConverter.GetBytes(Segments.Length);
         stream.Write(bytes, 0, bytes.Length);
         ShapeSegment[] array = 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(Points.Length);
         stream.Write(bytes, 0, bytes.Length);
         MapPoint[] array2 = Points;
         for (int i = 0; i < array2.Length; i++)
         {
             MapPoint mapPoint = array2[i];
             bytes = BitConverter.GetBytes(mapPoint.X);
             stream.Write(bytes, 0, bytes.Length);
             bytes = BitConverter.GetBytes(mapPoint.Y);
             stream.Write(bytes, 0, bytes.Length);
         }
     }
 }
示例#2
0
        internal static void MoveLargestSegmentToFront(ref MapPoint[] points, ref ShapeSegment[] segments)
        {
            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;
            }
        }
示例#3
0
        internal void LoadFromStream(Stream stream)
        {
            byte[] array  = new byte[Marshal.SizeOf(typeof(byte))];
            byte[] array2 = new byte[Marshal.SizeOf(typeof(int))];
            byte[] array3 = new byte[Marshal.SizeOf(typeof(double))];
            stream.Read(array2, 0, array2.Length);
            int num = BitConverter.ToInt32(array2, 0);

            Segments = new ShapeSegment[num];
            for (int i = 0; i < num; i++)
            {
                stream.Read(array, 0, array.Length);
                Segments[i].Type = (SegmentType)array[0];
                stream.Read(array2, 0, array2.Length);
                Segments[i].Length = BitConverter.ToInt32(array2, 0);
            }
            stream.Read(array2, 0, array2.Length);
            int num2 = BitConverter.ToInt32(array2, 0);

            Points = new MapPoint[num2];
            for (int j = 0; j < num2; j++)
            {
                stream.Read(array3, 0, array3.Length);
                Points[j].X = BitConverter.ToDouble(array3, 0);
                stream.Read(array3, 0, array3.Length);
                Points[j].Y = BitConverter.ToDouble(array3, 0);
            }
        }
示例#4
0
        private void UpdateMultiPolygonWithHoles()
        {
            int num  = 0;
            int num2 = 0;

            ShapeSegment[] array = 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)
                {
                    MultiPolygonWithHoles = true;
                    return;
                }
            }
            MultiPolygonWithHoles = (num > 1 && num2 > 0);
        }
示例#5
0
        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 isClosedAtPole = false;
                    polygonCutter.ProcessShapeSegment(segment, points, num, PolygonClosingPole.North, out List <ShapeSegment> segments2, out List <MapPoint> segmentPoints, out isClosedAtPole);
                    if (isClosedAtPole)
                    {
                        polygonCutter.ProcessShapeSegment(segment, points, num, PolygonClosingPole.South, out List <ShapeSegment> segments3, out List <MapPoint> segmentPoints2, out isClosedAtPole);
                        ShapeSegment[] segments4 = segments2.ToArray();
                        MapPoint[]     points2   = segmentPoints.ToArray();
                        CalculateSignedArea(ref points2, ref segments4);
                        double num2 = 0.0;
                        for (int j = 0; j < segments4.Length; j++)
                        {
                            num2 += Math.Abs(segments4[j].PolygonSignedArea);
                        }
                        ShapeSegment[] segments5 = segments3.ToArray();
                        MapPoint[]     points3   = segmentPoints2.ToArray();
                        CalculateSignedArea(ref points3, ref segments5);
                        double num3 = 0.0;
                        for (int k = 0; k < segments5.Length; k++)
                        {
                            num3 += Math.Abs(segments5[k].PolygonSignedArea);
                        }
                        if (num2 < num3)
                        {
                            list.AddRange(segments2);
                            list2.AddRange(segmentPoints);
                        }
                        else
                        {
                            list.AddRange(segments3);
                            list2.AddRange(segmentPoints2);
                        }
                    }
                    else
                    {
                        list.AddRange(segments2);
                        list2.AddRange(segmentPoints);
                    }
                }
                num += segment.Length;
            }
            segments = list.ToArray();
            points   = list2.ToArray();
        }
示例#6
0
 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>();
     Load(points, firstPointIndex, segment.Length, closingPole);
     foreach (PolygonPart shape in GetShapes())
     {
         ShapeSegment item = default(ShapeSegment);
         item.Type   = segment.Type;
         item.Length = shape.Points.Count;
         segments.Add(item);
         segmentPoints.AddRange(shape.Points);
         isClosedAtPole |= shape.isClosedAtPole;
     }
 }
        public void Simplify(Shape shape, double resolution)
        {
            if (resolution <= 0.0)
            {
                return;
            }
            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++]);
                    }
                    continue;
                }
                MapPoint[] array = new MapPoint[item.Length];
                for (int k = 0; k < item.Length; k++)
                {
                    array[k] = shape.ShapeData.Points[num++];
                }
                ReducedPointList reducedPointList = 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();
        }