예제 #1
0
        /// <summary>
        /// Write GrADS map file
        /// </summary>
        /// <param name="aFile">file name</param>
        /// <param name="Polylines">PolylineShape list</param>
        public static void WriteMapFile_GrADS(string aFile, List <PolylineShape> Polylines)
        {
            FileStream   fs = new FileStream(aFile, FileMode.Create, FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(fs);
            int          i;
            ArrayList    points = new ArrayList();

            for (i = 0; i < Polylines.Count; i++)
            {
                PolylineShape aPLS = Polylines[i];
                for (int p = 0; p < aPLS.PartNum; p++)
                {
                    points = new ArrayList();
                    if (p == aPLS.PartNum - 1)
                    {
                        for (int pp = aPLS.parts[p]; pp < aPLS.PointNum; pp++)
                        {
                            points.Add((MeteoInfoC.PointD)aPLS.Points[pp]);
                        }
                    }
                    else
                    {
                        for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++)
                        {
                            points.Add((MeteoInfoC.PointD)aPLS.Points[pp]);
                        }
                    }
                    WriteGrADSMapBW(bw, points);
                }
            }

            bw.Close();
            fs.Close();
        }
        private static int GetContentLength(object aShape, ShapeTypes aST)
        {
            int contentLength = 0;

            switch (aST)
            {
            case ShapeTypes.Point:
                contentLength = 2 + 4 * 2;
                break;

            case ShapeTypes.Polyline:
                PolylineShape aPLS = (PolylineShape)aShape;
                contentLength = 2 + 4 * 4 + 2 + 2 + 2 * aPLS.PartNum + 4 * 2 * aPLS.PointNum;
                break;

            case ShapeTypes.PolylineZ:
                PolylineZShape aPLZS = (PolylineZShape)aShape;
                contentLength = 2 + 4 * 4 + 2 + 2 + 2 * aPLZS.PartNum + 4 * 2 * aPLZS.PointNum +
                                4 + 4 + 4 * aPLZS.PointNum + 4 + 4 + 4 * aPLZS.PointNum;
                break;

            case ShapeTypes.Polygon:
                PolygonShape aPGS = (PolygonShape)aShape;
                contentLength = 2 + 4 * 4 + 2 + 2 + 2 * aPGS.PartNum + 4 * 2 * aPGS.PointNum;
                break;
            }

            return(contentLength);
        }
예제 #3
0
        public void TestPolylinePositions()
        {
            PolylineShape line = new PolylineShape(1, m_metadata, m_extent, m_parts, m_positions);

            Assert.AreEqual(line[0][0], new Cartographic(0.0, 0.0, 0.0));
            Assert.AreEqual(line[0][1], new Cartographic(Constants.RadiansPerDegree, Constants.RadiansPerDegree, 0.0));
        }
예제 #4
0
        /// <summary>
        /// Writes the polyline to its <see cref="CzmlDocument"/>.
        /// </summary>
        public override void Write()
        {
            PolylineShape polyline = (PolylineShape)m_shape;

            for (int i = 0; i < polyline.Count; i++)
            {
                ShapePart part = polyline[i];
                using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
                {
                    packetWriter.WriteId(Guid.NewGuid().ToString());
                    using (PolylineCesiumWriter polylineWriter = packetWriter.OpenPolylineProperty())
                    {
                        using (var materialWriter = polylineWriter.OpenMaterialProperty())
                            using (var colorWriter = materialWriter.OpenSolidColorProperty())
                            {
                                colorWriter.WriteColorProperty(m_color);
                            }

                        List <Cartographic> positions = new List <Cartographic>();
                        for (int x = 0; x < part.Count; x++)
                        {
                            positions.Add(part[x]);
                        }
                        polylineWriter.WritePositionsPropertyCartographicRadians(positions);
                    }
                }
            }
        }
예제 #5
0
        private static void PolylineCapacities(Shapefile shapefile, out int positionsCount, out int indicesCount)
        {
            int numberOfPositions = 0;
            int numberOfIndices   = 0;

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polyline)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolylineShape polylineShape = (PolylineShape)shape;

                for (int j = 0; j < polylineShape.Count; ++j)
                {
                    ShapePart part = polylineShape[j];

                    numberOfPositions += part.Count;
                    numberOfIndices   += (part.Count - 1) * 2;
                }
            }

            positionsCount = numberOfPositions;
            indicesCount   = numberOfIndices;
        }
예제 #6
0
        /// <summary>
        /// Writes the polyline to its <see cref="CzmlDocument"/>.
        /// </summary>
        public override void Write()
        {
            PolylineShape polyline = (PolylineShape)m_shape;

            for (int part = 0; part < polyline.Count; part++)
            {
                this.WritePacket(polyline[part]);
            }
        }
        private static VectorLayer ReadPolylineShapes(BinaryReader br, int shapeNum)
        {
            VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline);
            double      x, y;

            //PointD aPoint;
            for (int i = 0; i < shapeNum; i++)
            {
                //geolayer.getAttributeContainer().Add(ds.Tables[0].Rows[i][0]);      //read out the attribute step by step

                br.ReadBytes(12);

                //	 int pos = indexRecs[i].Offset+8;
                //	 bb0.position(pos);
                //	 stype = bb0.getInt();
                //	 if (stype!=nshapetype){
                //		 continue;
                //	 }

                PolylineShape aPL = new PolylineShape();
                Extent        extent;
                extent.minX = br.ReadDouble();
                extent.minY = br.ReadDouble();
                extent.maxX = br.ReadDouble();
                extent.maxY = br.ReadDouble();
                aPL.Extent  = extent;

                aPL.PartNum = br.ReadInt32();
                int numPoints = br.ReadInt32();
                aPL.parts = new int[aPL.PartNum];
                List <PointD> points = new List <PointD>();

                //firstly read out parts begin pos in file
                for (int j = 0; j < aPL.PartNum; j++)
                {
                    aPL.parts[j] = br.ReadInt32();
                }

                //read out coordinates
                for (int j = 0; j < numPoints; j++)
                {
                    x = br.ReadDouble();
                    y = br.ReadDouble();
                    PointD aPoint = new PointD();
                    aPoint.X = x;
                    aPoint.Y = y;
                    points.Add(aPoint);
                }
                aPL.Points = points;
                aLayer.ShapeList.Add(aPL);
            }

            //Create legend scheme
            aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
            return(aLayer);
        }
예제 #8
0
        /// <summary>
        /// 创建窗体
        /// </summary>
        /// <param name="native">方法库</param>
        public LevelWindow(INativeBase native)
        {
            Load(native, "LevelWindow", "levelWindow");
            RegisterEvents(m_window);
            m_chartLevels                 = GetChart("chartLevels");
            m_chartLevels.HScalePixel     = 20;
            m_chartLevels.HScaleFieldText = "日期";
            CTable dataSource = m_chartLevels.DataSource;

            dataSource.AddColumn(0);
            dataSource.AddColumn(1);
            dataSource.AddColumn(2);
            dataSource.AddColumn(3);
            dataSource.AddColumn(4);
            CDiv div = m_chartLevels.AddDiv();

            div.BackColor             = COLOR.ARGB(255, 255, 255);
            div.LeftVScale.ScaleColor = COLOR.ARGB(50, 105, 217);
            div.HScale.ScaleColor     = COLOR.ARGB(50, 105, 217);
            div.HGrid.GridColor       = COLOR.ARGB(50, 105, 217);
            div.HGrid.LineStyle       = 2;
            PolylineShape ps = new PolylineShape();

            ps.FieldName = 0;
            ps.FieldText = "开发";
            ps.FillColor = COLOR.ARGB(100, 50, 105, 217);
            ps.Color     = COLOR.ARGB(50, 105, 217);
            div.AddShape(ps);
            PolylineShape ps2 = new PolylineShape();

            ps2.FieldName = 3;
            ps2.FieldText = "研发";
            ps2.FillColor = COLOR.ARGB(100, 255, 80, 80);
            ps2.Color     = COLOR.ARGB(255, 80, 80);
            div.AddShape(ps2);
            PolylineShape ps3 = new PolylineShape();

            ps3.FieldName = 4;
            ps3.FieldText = "规范";
            ps3.FillColor = COLOR.ARGB(100, 80, 255, 80);
            ps3.Color     = COLOR.ARGB(80, 255, 80);
            div.AddShape(ps3);
            PolylineShape psTop = new PolylineShape();

            psTop.FieldName = 1;
            div.AddShape(psTop);
            PolylineShape psBottom = new PolylineShape();

            psBottom.FieldName = 2;
            div.AddShape(psBottom);
            m_gridLevels = GetGrid("gridLevels");
            m_gridLevels.RegisterEvent(new GridCellEvent(GridCellEditEnd), EVENTID.GRIDCELLEDITEND);
            BindLevels();
            BindChart();
        }
예제 #9
0
        public static Shape NewShapeForCancas(PolylineShape polylineShape)
        {
            Polyline polyline = new Polyline();

            foreach (var item in polylineShape.PointList)
            {
                polyline.Points.Add(item);
            }
            polyline.Stroke = new SolidColorBrush(polylineShape.Color);
            polyline.Margin = new Thickness(polylineShape.Margin.X, polylineShape.Margin.Y, 0, 0);

            return(polyline);
        }
예제 #10
0
        public void CreatePolyline()
        {
            List <Point> points = getListPoints();

            if (points.Count == 2)
            {
                PolylineShape polylineShape = new PolylineShape(genereteName("Polyline"), points);
                Shapes.Add(polylineShape);
                RemoveAllPoint();
                isNewPolyline = true;
            }
            else if (isNewPolyline)
            {
                (Shapes.Last(polyline => polyline is PolylineShape) as PolylineShape).AddPoint(points[0]);
                RemoveAllPoint();
            }
        }
예제 #11
0
        private void CreatePolylineNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            PolylineShape shape = new PolylineShape();

            shape.Points = new PointF[] {
                new PointF(0, 20), new PointF(-40, 25),
                new PointF(20, 5), new PointF(100, 0),
                new PointF(20, -5), new PointF(-40, -25),
                new PointF(0, -20)
            };

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.Yellow);
            shape.Name = "polylineNeedle";
            needleShape.Add(shape);
        }
예제 #12
0
 /// <summary>
 /// Writes a new polyline packet for each part of the shape.
 /// </summary>
 /// <param name="part">The <see cref="ShapePart"/> of the <see cref="PolylineShape"/> to write</param>
 private void WritePacket(ShapePart part)
 {
     using (PacketCesiumWriter packetWriter = m_document.CesiumStreamWriter.OpenPacket(m_document.CesiumOutputStream))
     {
         packetWriter.WriteId(Guid.NewGuid().ToString());
         using (PositionListCesiumWriter position = packetWriter.OpenVertexPositionsProperty())
         {
             PolylineShape       polyline  = (PolylineShape)m_shape;
             List <Cartographic> positions = new List <Cartographic>();
             for (int i = 0; i < part.Count; i++)
             {
                 positions.Add(part[i]);
             }
             position.WriteCartographicRadians(positions);
         }
         using (PolylineCesiumWriter polylineWriter = packetWriter.OpenPolylineProperty())
         {
             polylineWriter.WriteColorProperty(m_color);
         }
     }
 }
예제 #13
0
        /// <summary>
        /// 创建窗体
        /// </summary>
        /// <param name="native">方法库</param>
        public DialogWindow(INativeBase native)
        {
            Load(native, "DialogWindow", "dialogWindow");
            RegisterEvents(m_window);
            m_divDialogs = GetDiv("divDialogs");
            m_divDialogs.RegisterEvent(new ControlPaintEvent(PaintDiv), EVENTID.PAINT);
            m_gridDialogs = GetGrid("gridDialogs");
            m_gridDialogs.RegisterEvent(new GridCellEvent(GridCellEditEnd), EVENTID.GRIDCELLEDITEND);
            BindDialogs();

            m_chartLevels                 = GetChart("chartLevels");
            m_chartLevels.HScalePixel     = 20;
            m_chartLevels.HScaleFieldText = "日期";
            CTable dataSource = m_chartLevels.DataSource;

            dataSource.AddColumn(0);
            dataSource.AddColumn(1);
            CDiv div = m_chartLevels.AddDiv();

            div.BackColor             = COLOR.ARGB(255, 255, 255);
            div.LeftVScale.ScaleColor = COLOR.ARGB(50, 105, 217);
            div.HScale.ScaleColor     = COLOR.ARGB(50, 105, 217);
            div.HGrid.GridColor       = COLOR.ARGB(50, 105, 217);
            div.HGrid.LineStyle       = 2;
            PolylineShape ps = new PolylineShape();

            ps.FieldName = 0;
            ps.FieldText = "接待量";
            ps.FillColor = COLOR.ARGB(100, 50, 105, 217);
            ps.Color     = COLOR.ARGB(50, 105, 217);
            div.AddShape(ps);
            PolylineShape psBottom = new PolylineShape();

            psBottom.FieldName = 1;
            div.AddShape(psBottom);
            BindChart();
        }
예제 #14
0
        private void CreateComplexNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            PolylineShape basic = new PolylineShape(new PointF[] {
                new PointF(25, 20), new PointF(100, 0), new PointF(25, -20),
                new PointF(95, 0), new PointF(25, 20)
            });

            basic.Appearance.ContentBrush = new SolidBrushObject(Color.Azure);
            basic.Name = "basic";

            PolylineShape cap = new PolylineShape(new PointF[] {
                new PointF(100, 0), new PointF(105, 5),
                new PointF(110, 0), new PointF(105, -5)
            });

            cap.Appearance.ContentBrush = new SolidBrushObject(Color.BurlyWood);
            cap.Name = "cap";

            needleShape.AddRange(new BaseShape[] { basic, cap });
        }
예제 #15
0
        internal DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox, bool isSwitch)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            if (viewBox.HasValue)
            {
                grp.ClipGeometry = new RectangleGeometry(viewBox.Value);
            }

            foreach (Shape shape in elements)
            {
                if (isSwitch)
                {
                    if (grp.Children.Count > 0)
                    {
                        break;
                    }
                    if (!string.IsNullOrEmpty(shape.RequiredFeatures))
                    {
                        if (!SVGFeatures.Features.Contains(shape.RequiredFeatures))
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(shape.RequiredExtensions))
                        {
                            continue;
                        }
                    }
                }

                if (shape is AnimationBase)
                {
                    if (UseAnimations)
                    {
                        if (shape is AnimateTransform animateTransform)
                        {
                            if (animateTransform.Type == AnimateTransformType.Rotate)
                            {
                                var animation = new DoubleAnimation
                                {
                                    From     = double.Parse(animateTransform.From),
                                    To       = double.Parse(animateTransform.To),
                                    Duration = animateTransform.Duration
                                };
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                var r = new RotateTransform();
                                grp.Transform = r;
                                r.BeginAnimation(RotateTransform.AngleProperty, animation);
                            }
                        }
                        else if (shape is Animate animate)
                        {
                            var target = this.SVG.GetShape(animate.hRef);
                            var g      = target.geometryElement;
                            //todo : rework this all, generalize it!
                            if (animate.AttributeName == "r")
                            {
                                var animation = new DoubleAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;

                                g.BeginAnimation(EllipseGeometry.RadiusXProperty, animation);
                                g.BeginAnimation(EllipseGeometry.RadiusYProperty, animation);
                            }
                            else if (animate.AttributeName == "cx")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                            else if (animate.AttributeName == "cy")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(((EllipseGeometry)g).Center.X, double.Parse(_)))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                        }
                    }

                    continue;
                }

                if (shape is UseShape)
                {
                    UseShape useshape         = shape as UseShape;
                    Shape    currentUsedShape = this.SVG.GetShape(useshape.hRef);
                    if (currentUsedShape != null)
                    {
                        currentUsedShape.RealParent = useshape;
                        Shape        oldparent = currentUsedShape.Parent;
                        DrawingGroup subgroup;
                        if (currentUsedShape is Group)
                        {
                            subgroup = this.LoadGroup(((Group)currentUsedShape).Elements, null, false);
                        }
                        else
                        {
                            subgroup = this.LoadGroup(new[] { currentUsedShape }, null, false);
                        }
                        if (currentUsedShape.Clip != null)
                        {
                            subgroup.ClipGeometry = currentUsedShape.Clip.ClipGeometry;
                        }
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        if (useshape.Transform != null)
                        {
                            subgroup.Transform = new TransformGroup()
                            {
                                Children = new TransformCollection()
                                {
                                    subgroup.Transform, useshape.Transform
                                }
                            }
                        }
                        ;
                        grp.Children.Add(subgroup);
                        currentUsedShape.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null, false);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group groupShape)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null, groupShape.IsSwitch);
                    AddDrawingToGroup(grp, shape, subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape    r    = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X < 0 ? 0 : r.X, r.Y < 0 ? 0 : r.Y, r.X < 0 ? r.Width + r.X : r.Width, r.Y < 0 ? r.Height + r.Y : r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    var di = this.NewDrawingItem(shape, rect);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is LineShape)
                {
                    LineShape    r    = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    var          di   = this.NewDrawingItem(shape, line);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r    = shape as PolylineShape;
                    PathGeometry  path = new PathGeometry();
                    PathFigure    p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r    = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure   p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is CircleShape)
                {
                    CircleShape     r  = shape as CircleShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is EllipseShape)
                {
                    EllipseShape    r  = shape as EllipseShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is ImageShape)
                {
                    ImageShape   image = shape as ImageShape;
                    ImageDrawing i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    AddDrawingToGroup(grp, shape, i);
                    continue;
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                var di = this.NewDrawingItem(tspan, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                            else
                            {
                                var di = this.NewDrawingItem(shape, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                        }
                    }
                    continue;
                }
                if (shape is PathShape)
                {
                    PathShape  r         = shape as PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    PathShape.CurveTo          lastc = null;
                    PathShape.QuadraticCurveTo lastq = null;
                    Point        lastcirPoint        = new Point(0, 0);
                    PathGeometry path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(r.Data));
                    //PathGeometry path = new PathGeometry();

                    /*
                     * foreach (PathShape.PathElement element in r.Elements)
                     * {
                     *  bool isRelative = element.IsRelative;
                     *  if (element is PathShape.MoveTo)
                     *  {
                     *      p = new PathFigure();
                     *      p.IsClosed = r.ClosePath;
                     *      if (isRelative) p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                     *      else p.StartPoint = ((PathShape.MoveTo)element).Point;
                     *      lastPoint = p.StartPoint;
                     *      path.Figures.Add(p);
                     *      continue;
                     *  }
                     *  if (element is PathShape.LineTo)
                     *  {
                     *      PathShape.LineTo lineto = element as PathShape.LineTo;
                     *      foreach (Point point in lineto.Points)
                     *      {
                     *          if (isRelative)
                     *          {
                     *              Point newpoint = lastPoint + (Vector)point;
                     *              lastPoint = newpoint;
                     *              p.Segments.Add(new LineSegment(newpoint, true));
                     *          }
                     *          else
                     *          {
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Point) lastPoint = point;
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Horizontal) lastPoint = new Point(point.X, lastPoint.Y);
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Vertical) lastPoint = new Point(lastPoint.X, point.Y);
                     *              p.Segments.Add(new LineSegment(lastPoint, true));
                     *          }
                     *      }
                     *      continue;
                     *  }
                     *  if (element is PathShape.CurveTo)
                     *  {
                     *      PathShape.CurveTo c = element as PathShape.CurveTo;
                     *      Point startPoint = lastPoint;
                     *      BezierSegment s = new BezierSegment();
                     *      if (isRelative)
                     *      {
                     *          s.Point1 = lastPoint + (Vector)c.CtrlPoint1;
                     *
                     *          if (c.Command == 's')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                     *              double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *              //s.Point1 = lastctrlpoint;
                     *          }
                     *
                     *          s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                     *          s.Point3 = lastPoint + (Vector)c.Point;
                     *      }
                     *      else
                     *      {
                     *          if (c.Command == 's')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                     *              double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *          }
                     *          else s.Point1 = c.CtrlPoint1;
                     *          s.Point2 = c.CtrlPoint2;
                     *          s.Point3 = c.Point;
                     *      }
                     *      lastPoint = s.Point3;
                     *      p.Segments.Add(s);
                     *
                     *      lastc = c;
                     *      lastcirPoint = s.Point3;
                     *
                     *      //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                     *      //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                     *      continue;
                     *  }
                     *  if (element is PathShape.QuadraticCurveTo)
                     *  {
                     *      PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo;
                     *      Point startPoint = lastPoint;
                     *      QuadraticBezierSegment s = new QuadraticBezierSegment();
                     *      if (isRelative)
                     *      {
                     *          s.Point1 = lastPoint + (Vector)c.CtrlPoint1;
                     *
                     *          if (c.Command == 'q' && lastq != null) // fix for horse svg! needed ?? or is it wrong in SVG?
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                     *              double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *              //s.Point1 = lastctrlpoint;
                     *          }
                     *
                     *          s.Point2 = lastPoint + (Vector)c.Point;
                     *      }
                     *      else
                     *      {
                     *          if (c.Command == 'q')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                     *              double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *          }
                     *          else s.Point1 = c.CtrlPoint1;
                     *          s.Point2 = c.Point;
                     *      }
                     *      lastPoint = s.Point2;
                     *      p.Segments.Add(s);
                     *
                     *      lastq = c;
                     *      lastcirPoint = s.Point2;
                     *
                     *      //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                     *      //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                     *      continue;
                     *  }
                     *  if (element is PathShape.EllipticalArcTo)
                     *  {
                     *      PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                     *      ArcSegment s = new ArcSegment();
                     *      if (isRelative) s.Point = lastPoint + new Vector(c.X, c.Y);
                     *      else s.Point = new Point(c.X, c.Y);
                     *
                     *      s.Size = new Size(c.RX, c.RY);
                     *      s.RotationAngle = c.AxisRotation;
                     *      s.SweepDirection = SweepDirection.Counterclockwise;
                     *      if (c.Clockwise) s.SweepDirection = SweepDirection.Clockwise;
                     *      s.IsLargeArc = c.LargeArc;
                     *      lastPoint = s.Point;
                     *      p.Segments.Add(s);
                     *      continue;
                     *  }
                     * }
                     */
                    /*
                     * if (r.Transform != null)
                     *  path.Transform = r.Transform;
                     */
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Polyline"/> class.
 /// </summary>
 /// <param name="polyline">A PolylineShape object read from a shapefile.</param>
 /// <param name="document">The CzmlDocument to write to.</param>
 /// <param name="color">The polyline's color.</param>
 public Polyline(PolylineShape polyline, CzmlDocument document, Color color)
     : base(document, color)
 {
     m_shape = polyline;
 }
        private void SaveWMPFile()
        {
            SaveFileDialog SFDlg = new SaveFileDialog();

            SFDlg.Filter = "wmp File (*.wmp)|*.wmp";
            if (SFDlg.ShowDialog() == DialogResult.OK)
            {
                //ProgressBar
                toolStripProgressBar1.Visible = true;
                this.Cursor = Cursors.WaitCursor;

                string       aFile       = SFDlg.FileName;
                StreamWriter sw          = new StreamWriter(aFile);
                List <int>   selIndexes  = _currentLayer.GetSelectedShapeIndexes();
                bool         hasSelShape = _currentLayer.HasSelectedShapes();
                int          shpNum      = _currentLayer.ShapeNum;
                if (hasSelShape)
                {
                    shpNum = selIndexes.Count;
                }
                int i;
                switch (_currentLayer.ShapeType)
                {
                case ShapeTypes.Point:
                    sw.WriteLine("Point");
                    sw.WriteLine(shpNum.ToString());
                    PointShape aPS = new PointShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            if (aPS.Selected)
                            {
                                sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            }
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    else
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    break;

                case ShapeTypes.Polyline:
                    sw.WriteLine("Polyline");
                    int           shapeNum = 0;
                    PolylineShape aPLS     = new PolylineShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                            if (aPLS.Selected)
                            {
                                shapeNum += aPLS.PartNum;
                            }
                        }
                    }
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS      = (PolylineShape)_currentLayer.ShapeList[i];
                        shapeNum += aPLS.PartNum;
                    }
                    sw.WriteLine(shpNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPLS.Selected)
                            {
                                continue;
                            }
                        }
                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPLS.PartNum; p++)
                        {
                            if (p == aPLS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.PointNum - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.PointNum; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.parts[p + 1] - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;

                case ShapeTypes.Polygon:
                    sw.WriteLine("Polygon");
                    shapeNum = 0;
                    PolygonShape aPGS = new PolygonShape();
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }
                        shapeNum += aPGS.PartNum;
                    }
                    sw.WriteLine(shapeNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }

                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPGS.PartNum; p++)
                        {
                            if (p == aPGS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.PointNum - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.parts[p + 1] - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;
                }

                sw.Close();

                //Progressbar
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Visible = false;
                this.Cursor = Cursors.Default;
            }
        }
예제 #18
0
        /// <summary>
        /// Read WMP map
        /// </summary>
        /// <param name="aFile"></param>
        /// <returns></returns>
        public static VectorLayer ReadMapFile_WMP(string aFile)
        {
            StreamReader sr = new StreamReader(aFile);
            string       aLine;
            string       shapeType;

            string[]      dataArray;
            int           shapeNum;
            int           i, j, pNum;
            List <PointD> pList = new List <PointD>();
            PointD        aPoint;
            ArrayList     dataList   = new ArrayList();
            bool          IsTrue     = false;
            string        columnName = "Value";
            VectorLayer   aLayer     = new VectorLayer(ShapeTypes.Point);

            //Read shape type
            shapeType = sr.ReadLine().Trim();
            //Read shape number
            shapeNum = Convert.ToInt32(sr.ReadLine());
            switch (shapeType.ToLower())
            {
            case "point":
                aLayer = new VectorLayer(ShapeTypes.Point);
                aLayer.EditAddField(new DataColumn(columnName, typeof(int)));

                for (i = 0; i < shapeNum; i++)
                {
                    aLine     = sr.ReadLine();
                    dataArray = aLine.Split(',');
                    aPoint    = new PointD();
                    aPoint.X  = Convert.ToDouble(dataArray[0]);
                    aPoint.Y  = Convert.ToDouble(dataArray[1]);
                    pList.Add(aPoint);
                    PointShape aPS = new PointShape();
                    aPS.Value = i;
                    aPS.Point = aPoint;

                    int sNum = aLayer.ShapeNum;
                    if (aLayer.EditInsertShape(aPS, sNum))
                    {
                        aLayer.EditCellValue(columnName, sNum, i);
                    }
                }

                aLayer.LayerName     = Path.GetFileName(aFile);
                aLayer.FileName      = aFile;
                aLayer.LayerDrawType = LayerDrawType.Map;
                aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Black, 5);
                aLayer.Visible       = true;
                IsTrue = true;
                break;

            case "polyline":
                aLayer = new VectorLayer(ShapeTypes.Polyline);
                aLayer.EditAddField(new DataColumn(columnName, typeof(int)));

                for (i = 0; i < shapeNum; i++)
                {
                    pNum  = Convert.ToInt32(sr.ReadLine());
                    pList = new List <PointD>();
                    for (j = 0; j < pNum; j++)
                    {
                        aLine     = sr.ReadLine();
                        dataArray = aLine.Split(',');
                        aPoint    = new PointD();
                        aPoint.X  = Convert.ToDouble(dataArray[0]);
                        aPoint.Y  = Convert.ToDouble(dataArray[1]);
                        pList.Add(aPoint);
                    }
                    PolylineShape aPLS = new PolylineShape();
                    aPLS.value  = i;
                    aPLS.Extent = MIMath.GetPointsExtent(pList);
                    aPLS.Points = pList;

                    int sNum = aLayer.ShapeNum;
                    if (aLayer.EditInsertShape(aPLS, sNum))
                    {
                        aLayer.EditCellValue(columnName, sNum, i);
                    }
                }

                aLayer.LayerName     = Path.GetFileName(aFile);
                aLayer.FileName      = aFile;
                aLayer.LayerDrawType = LayerDrawType.Map;
                aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
                aLayer.Visible       = true;
                IsTrue = true;
                break;

            case "polygon":
                aLayer = new VectorLayer(ShapeTypes.Polygon);
                aLayer.EditAddField(new DataColumn(columnName, typeof(int)));

                ArrayList polygons = new ArrayList();
                for (i = 0; i < shapeNum; i++)
                {
                    pNum  = Convert.ToInt32(sr.ReadLine());
                    pList = new List <PointD>();
                    for (j = 0; j < pNum; j++)
                    {
                        aLine     = sr.ReadLine();
                        dataArray = aLine.Split(',');
                        aPoint    = new PointD();
                        aPoint.X  = Convert.ToDouble(dataArray[0]);
                        aPoint.Y  = Convert.ToDouble(dataArray[1]);
                        pList.Add(aPoint);
                    }
                    PolygonShape aPGS = new PolygonShape();
                    aPGS.lowValue  = i;
                    aPGS.highValue = i;
                    aPGS.Extent    = MIMath.GetPointsExtent(pList);
                    aPGS.Points    = pList;

                    int sNum = aLayer.ShapeNum;
                    if (aLayer.EditInsertShape(aPGS, sNum))
                    {
                        aLayer.EditCellValue(columnName, sNum, i);
                    }
                }

                aLayer.LayerName     = Path.GetFileName(aFile);
                aLayer.FileName      = aFile;
                aLayer.LayerDrawType = LayerDrawType.Map;
                aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polygon, Color.FromArgb(255, 251, 195), 1.0F);
                aLayer.Visible       = true;
                IsTrue = true;
                break;

            default:
                MessageBox.Show("Shape type is invalid!" + Environment.NewLine +
                                shapeType, "Error");
                IsTrue = false;
                break;
            }

            sr.Close();

            if (IsTrue)
            {
                return(aLayer);
            }
            else
            {
                return(null);
            }
        }
        private static void WriteRecord(BinaryWriter bw, int RecordNumber, object aShape, ShapeTypes aST)
        {
            int ContentLength, i;

            ContentLength = GetContentLength(aShape, aST);
            bw.Write(SwapByteOrder(RecordNumber));
            bw.Write(SwapByteOrder(ContentLength));
            bw.Write((int)aST);
            switch (aST)
            {
            case ShapeTypes.Point:
                PointShape aPS = (PointShape)aShape;
                bw.Write(aPS.Point.X);
                bw.Write(aPS.Point.Y);
                break;

            case ShapeTypes.Polyline:
                PolylineShape aPLS = (PolylineShape)aShape;
                bw.Write(aPLS.Extent.minX);
                bw.Write(aPLS.Extent.minY);
                bw.Write(aPLS.Extent.maxX);
                bw.Write(aPLS.Extent.maxY);
                bw.Write(aPLS.PartNum);
                bw.Write(aPLS.PointNum);
                for (i = 0; i < aPLS.PartNum; i++)
                {
                    bw.Write(aPLS.parts[i]);
                }
                for (i = 0; i < aPLS.PointNum; i++)
                {
                    bw.Write(((PointD)aPLS.Points[i]).X);
                    bw.Write(((PointD)aPLS.Points[i]).Y);
                }
                break;

            case ShapeTypes.PolylineZ:
                PolylineZShape aPLZS = (PolylineZShape)aShape;
                bw.Write(aPLZS.Extent.minX);
                bw.Write(aPLZS.Extent.minY);
                bw.Write(aPLZS.Extent.maxX);
                bw.Write(aPLZS.Extent.maxY);
                bw.Write(aPLZS.PartNum);
                bw.Write(aPLZS.PointNum);
                for (i = 0; i < aPLZS.PartNum; i++)
                {
                    bw.Write(aPLZS.parts[i]);
                }
                for (i = 0; i < aPLZS.PointNum; i++)
                {
                    bw.Write(((PointZ)aPLZS.Points[i]).X);
                    bw.Write(((PointZ)aPLZS.Points[i]).Y);
                }
                bw.Write(aPLZS.ZRange[0]);
                bw.Write(aPLZS.ZRange[1]);
                for (i = 0; i < aPLZS.PointNum; i++)
                {
                    bw.Write(aPLZS.ZArray[i]);
                }
                bw.Write(aPLZS.MRange[0]);
                bw.Write(aPLZS.MRange[1]);
                for (i = 0; i < aPLZS.PointNum; i++)
                {
                    bw.Write(aPLZS.MArray[i]);
                }

                break;

            case ShapeTypes.Polygon:
                PolygonShape aPGS = (PolygonShape)aShape;
                bw.Write(aPGS.Extent.minX);
                bw.Write(aPGS.Extent.minY);
                bw.Write(aPGS.Extent.maxX);
                bw.Write(aPGS.Extent.maxY);
                bw.Write(aPGS.PartNum);
                bw.Write(aPGS.PointNum);
                for (i = 0; i < aPGS.PartNum; i++)
                {
                    bw.Write(aPGS.parts[i]);
                }
                for (i = 0; i < aPGS.PointNum; i++)
                {
                    bw.Write(((PointD)aPGS.Points[i]).X);
                    bw.Write(((PointD)aPGS.Points[i]).Y);
                }
                break;
            }
        }
예제 #20
0
        /// <summary>
        /// Write Sufer BLN map file
        /// </summary>
        /// <param name="aFile">output file</param>
        /// <param name="shapes">shape list</param>
        public static void WriteMapFile_BLN(string aFile, List <Shape.Shape> shapes)
        {
            StreamWriter sw     = new StreamWriter(aFile);
            int          shpNum = shapes.Count;
            int          i;

            switch (shapes[0].ShapeType)
            {
            case ShapeTypes.Polyline:
                int           shapeNum = 0;
                PolylineShape aPLS     = new PolylineShape();
                for (i = 0; i < shpNum; i++)
                {
                    aPLS = (PolylineShape)shapes[i];
                    MeteoInfoC.PointD[] Pointps;
                    for (int p = 0; p < aPLS.PartNum; p++)
                    {
                        if (p == aPLS.PartNum - 1)
                        {
                            Pointps = new MeteoInfoC.PointD[aPLS.PointNum - aPLS.parts[p]];
                            for (int pp = aPLS.parts[p]; pp < aPLS.PointNum; pp++)
                            {
                                Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                            }
                        }
                        else
                        {
                            Pointps = new MeteoInfoC.PointD[aPLS.parts[p + 1] - aPLS.parts[p]];
                            for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++)
                            {
                                Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                            }
                        }
                        sw.WriteLine(Pointps.Length.ToString() + ",1");
                        foreach (MeteoInfoC.PointD aPoint in Pointps)
                        {
                            sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                        }
                        shapeNum += 1;
                    }
                }
                break;

            case ShapeTypes.Polygon:
                shapeNum = 0;
                PolygonShape aPGS = new PolygonShape();
                for (i = 0; i < shpNum; i++)
                {
                    aPGS = (PolygonShape)shapes[i];
                    MeteoInfoC.PointD[] Pointps;
                    for (int p = 0; p < aPGS.PartNum; p++)
                    {
                        if (p == aPGS.PartNum - 1)
                        {
                            Pointps = new MeteoInfoC.PointD[aPGS.PointNum - aPGS.parts[p]];
                            for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++)
                            {
                                Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                            }
                        }
                        else
                        {
                            Pointps = new MeteoInfoC.PointD[aPGS.parts[p + 1] - aPGS.parts[p]];
                            for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++)
                            {
                                Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                            }
                        }
                        sw.WriteLine(Pointps.Length.ToString() + ",1");
                        foreach (MeteoInfoC.PointD aPoint in Pointps)
                        {
                            sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                        }
                        shapeNum += 1;
                    }
                }
                break;
            }

            sw.Close();
        }
예제 #21
0
        /// <summary>
        /// Read Surfer BLN map
        /// </summary>
        /// <param name="aFile">file path</param>
        /// <returns>vector layer</returns>
        public static VectorLayer ReadMapFile_BLN(string aFile)
        {
            StreamReader sr = new StreamReader(aFile);
            string       aLine;

            string[]      dataArray;
            int           i, j, pNum;
            List <PointD> pList = new List <PointD>();
            PointD        aPoint;
            ArrayList     dataList   = new ArrayList();
            bool          IsTrue     = false;
            string        columnName = "Value";
            VectorLayer   aLayer     = new VectorLayer(ShapeTypes.Polyline);

            //Read data
            aLayer.EditAddField(new DataColumn(columnName, typeof(int)));
            aLine = sr.ReadLine();
            bool isComma = true;

            if (!aLine.Contains(","))
            {
                isComma = false;
            }

            i = 0;
            while (aLine != null)
            {
                if (isComma)
                {
                    pNum = int.Parse(aLine.Split(',')[0]);
                }
                else
                {
                    pNum = int.Parse(MIMath.SplitBySpace(aLine)[0]);
                }
                pList = new List <PointD>();
                for (j = 0; j < pNum; j++)
                {
                    aLine = sr.ReadLine();
                    if (isComma)
                    {
                        dataArray = aLine.Split(',');
                    }
                    else
                    {
                        dataArray = MIMath.SplitBySpace(aLine);
                    }
                    aPoint   = new PointD();
                    aPoint.X = Convert.ToDouble(dataArray[0]);
                    aPoint.Y = Convert.ToDouble(dataArray[1]);
                    pList.Add(aPoint);
                }
                PolylineShape aPLS = new PolylineShape();
                aPLS.value  = i;
                aPLS.Extent = MIMath.GetPointsExtent(pList);
                aPLS.Points = pList;
                i          += 1;

                int sNum = aLayer.ShapeNum;
                if (aLayer.EditInsertShape(aPLS, sNum))
                {
                    aLayer.EditCellValue(columnName, sNum, i);
                }

                aLine = sr.ReadLine();
            }

            aLayer.LayerName     = Path.GetFileName(aFile);
            aLayer.FileName      = aFile;
            aLayer.LayerDrawType = LayerDrawType.Map;
            aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
            aLayer.Visible       = true;
            IsTrue = true;

            sr.Close();

            if (IsTrue)
            {
                return(aLayer);
            }
            else
            {
                return(null);
            }
        }
예제 #22
0
        /// <summary>
        /// Read GrADS map
        /// </summary>
        /// <param name="aFile"></param>
        /// <returns></returns>
        public static VectorLayer ReadMapFile_GrADS(string aFile)
        {
            FileStream   fs = new FileStream(aFile, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            int          i, lineNum;
            byte         b;
            Int16        N, lType;
            double       lon, lat;

            byte[] bytes;

            PointD        aPoint;
            List <PointD> pList = new List <PointD>();

            VectorLayer aLayer     = new VectorLayer(ShapeTypes.Polyline);
            string      columnName = "Value";
            DataColumn  aDC        = new DataColumn(columnName, typeof(int));

            aLayer.EditAddField(aDC);

            lineNum = 0;
            do
            {
                b = br.ReadByte();    // 1-data, 2-skip
                if (Convert.ToString(b) == "2")
                {
                    br.ReadBytes(18);
                    continue;
                }
                b     = br.ReadByte(); // Line type: country, river ...
                lType = Convert.ToInt16(b);
                b     = br.ReadByte(); // Point number
                N     = Convert.ToInt16(b);
                for (i = 0; i < N; i++)
                {
                    bytes = br.ReadBytes(3);    //Longitude
                    int val = bytes[0] << 16 | bytes[1] << 8 | bytes[2];
                    lon = val / 10000.0;

                    bytes = br.ReadBytes(3);    //Latitude
                    val   = bytes[0] << 16 | bytes[1] << 8 | bytes[2];
                    lat   = val / 10000.0 - 90.0;

                    aPoint   = new PointD();
                    aPoint.X = lon;
                    aPoint.Y = lat;
                    pList.Add(aPoint);
                }
                if (pList.Count > 1)
                {
                    //if (N < 255)
                    //{
                    PolylineShape aPolyline = new PolylineShape();
                    aPolyline.value    = lineNum;
                    aPolyline.Points   = pList;
                    aPolyline.Extent   = MIMath.GetPointsExtent(pList);
                    aPolyline.PartNum  = 1;
                    aPolyline.parts    = new int[1];
                    aPolyline.parts[0] = 0;

                    int shapeNum = aLayer.ShapeNum;
                    if (aLayer.EditInsertShape(aPolyline, shapeNum))
                    {
                        aLayer.EditCellValue(columnName, shapeNum, lineNum);
                    }

                    lineNum++;
                    //}
                }
                pList = new List <PointD>();
            } while (br.BaseStream.Position < br.BaseStream.Length);

            br.Close();
            fs.Close();

            aLayer.LayerName     = Path.GetFileName(aFile);
            aLayer.FileName      = aFile;
            aLayer.LayerDrawType = LayerDrawType.Map;
            aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
            aLayer.Visible       = true;

            return(aLayer);
        }
예제 #23
0
        private DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            if (viewBox.HasValue)
            {
                grp.ClipGeometry = new RectangleGeometry(viewBox.Value);
            }

            foreach (Shape shape in elements)
            {
                if (shape is UseShape)
                {
                    UseShape useshape = shape as UseShape;
                    Group    group    = this.SVG.GetShape(useshape.hRef) as Group;
                    if (group != null)
                    {
                        Shape oldparent = group.Parent;
                        group.Parent = useshape; // this to get proper style propagated
                        DrawingGroup subgroup = this.LoadGroup(group.Elements, null);
                        if (group.Clip != null)
                        {
                            subgroup.ClipGeometry = group.Clip.ClipGeometry;
                        }
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        grp.Children.Add(subgroup);
                        group.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null);
                    if (shape.Clip != null)
                    {
                        subgroup.ClipGeometry = shape.Clip.ClipGeometry;
                    }
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    AddDrawingToGroup(grp, shape, subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape    r    = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    var di = this.NewDrawingItem(shape, rect);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is LineShape)
                {
                    LineShape    r    = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    var          di   = this.NewDrawingItem(shape, line);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r    = shape as PolylineShape;
                    PathGeometry  path = new PathGeometry();
                    PathFigure    p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r    = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure   p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is CircleShape)
                {
                    CircleShape     r  = shape as CircleShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is EllipseShape)
                {
                    EllipseShape    r  = shape as EllipseShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is ImageShape)
                {
                    ImageShape   image = shape as ImageShape;
                    ImageDrawing i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    AddDrawingToGroup(grp, shape, i);
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                var di = this.NewDrawingItem(tspan, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                            else
                            {
                                var di = this.NewDrawingItem(shape, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                        }
                    }
                }
                if (shape is PathShape)
                {
                    PathShape  r         = shape as PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    PathShape.CurveTo          lastc = null;
                    PathShape.QuadraticCurveTo lastq = null;
                    Point lastcirPoint = new Point(0, 0);

                    PathGeometry path = new PathGeometry();
                    foreach (PathShape.PathElement element in r.Elements)
                    {
                        bool isRelative = element.IsRelative;
                        if (element is PathShape.MoveTo)
                        {
                            p          = new PathFigure();
                            p.IsClosed = r.ClosePath;
                            if (isRelative)
                            {
                                p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                            }
                            else
                            {
                                p.StartPoint = ((PathShape.MoveTo)element).Point;
                            }
                            lastPoint = p.StartPoint;
                            path.Figures.Add(p);
                            continue;
                        }
                        if (element is PathShape.LineTo)
                        {
                            PathShape.LineTo lineto = element as PathShape.LineTo;
                            foreach (Point point in lineto.Points)
                            {
                                if (isRelative)
                                {
                                    Point newpoint = lastPoint + (Vector)point;
                                    lastPoint = newpoint;
                                    p.Segments.Add(new LineSegment(newpoint, true));
                                }
                                else
                                {
                                    if (lineto.PositionType == PathShape.LineTo.eType.Point)
                                    {
                                        lastPoint = point;
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Horizontal)
                                    {
                                        lastPoint = new Point(point.X, lastPoint.Y);
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Vertical)
                                    {
                                        lastPoint = new Point(lastPoint.X, point.Y);
                                    }
                                    p.Segments.Add(new LineSegment(lastPoint, true));
                                }
                            }
                            continue;
                        }
                        if (element is PathShape.CurveTo)
                        {
                            PathShape.CurveTo c          = element as PathShape.CurveTo;
                            Point             startPoint = lastPoint;
                            BezierSegment     s          = new BezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                                s.Point3 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.CtrlPoint2;
                                s.Point3 = c.Point;
                            }
                            lastPoint = s.Point3;
                            p.Segments.Add(s);

                            lastc        = c;
                            lastcirPoint = s.Point3;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.QuadraticCurveTo)
                        {
                            PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo;
                            Point startPoint             = lastPoint;
                            QuadraticBezierSegment s     = new QuadraticBezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.Point;
                            }
                            lastPoint = s.Point2;
                            p.Segments.Add(s);

                            lastq        = c;
                            lastcirPoint = s.Point2;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.EllipticalArcTo)
                        {
                            PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                            ArcSegment s = new ArcSegment();
                            if (isRelative)
                            {
                                s.Point = lastPoint + new Vector(c.X, c.Y);
                            }
                            else
                            {
                                s.Point = new Point(c.X, c.Y);
                            }

                            s.Size           = new Size(c.RX, c.RY);
                            s.RotationAngle  = c.AxisRotation;
                            s.SweepDirection = SweepDirection.Counterclockwise;
                            if (c.Clockwise)
                            {
                                s.SweepDirection = SweepDirection.Clockwise;
                            }
                            s.IsLargeArc = c.LargeArc;
                            lastPoint    = s.Point;
                            p.Segments.Add(s);
                            continue;
                        }
                    }

                    /*
                     * if (r.Transform != null)
                     *  path.Transform = r.Transform;
                     */
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
        private void SaveGrADSMapFile()
        {
            SaveFileDialog SFDlg = new SaveFileDialog();

            //SFDlg.Filter = "wmp File (*.wmp)|*.wmp";
            if (SFDlg.ShowDialog() == DialogResult.OK)
            {
                //ProgressBar
                toolStripProgressBar1.Visible = true;
                this.Cursor = Cursors.WaitCursor;

                string aFile       = SFDlg.FileName;
                bool   hasSelShape = _currentLayer.HasSelectedShapes();
                int    shpNum      = _currentLayer.ShapeNum;
                if (hasSelShape)
                {
                    shpNum = _currentLayer.GetSelectedShapeIndexes().Count;
                }
                int i;
                switch (_currentLayer.ShapeType)
                {
                case ShapeTypes.Polyline:
                    List <PolylineShape> polylines = new List <PolylineShape>();
                    PolylineShape        aPLS      = new PolylineShape();
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPLS.Selected)
                            {
                                continue;
                            }
                        }

                        if (frmMain.CurrentWin.MapDocument.ActiveMapFrame.MapView.Projection.IsLonLatMap)
                        {
                            if (aPLS.Extent.minX < 0 && aPLS.Extent.maxX > 0)
                            {
                                polylines.AddRange(frmMain.CurrentWin.MapDocument.ActiveMapFrame.MapView.Projection.CutPolyLineShapeLon(0, aPLS));
                            }
                            else
                            {
                                polylines.Add(aPLS);
                            }
                        }
                        else
                        {
                            polylines.Add(aPLS);
                        }

                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    MapDataManage.WriteMapFile_GrADS(aFile, polylines);
                    break;

                case ShapeTypes.Polygon:
                    List <PolygonShape> polygons = new List <PolygonShape>();
                    PolygonShape        aPGS     = new PolygonShape();
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }
                        if (frmMain.CurrentWin.MapDocument.ActiveMapFrame.MapView.Projection.IsLonLatMap)
                        {
                            if (aPGS.Extent.minX < 0 && aPGS.Extent.maxX > 0)
                            {
                                polygons.AddRange(frmMain.CurrentWin.MapDocument.ActiveMapFrame.MapView.Projection.CutPolygonShapeLon(0, aPGS));
                            }
                            else
                            {
                                polygons.Add(aPGS);
                            }
                        }
                        else
                        {
                            polygons.Add(aPGS);
                        }

                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    MapDataManage.WriteMapFile_GrADS(aFile, polygons);
                    break;
                }

                //Progressbar
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Visible = false;
                this.Cursor = Cursors.Default;
            }
        }
예제 #25
0
        public void TestPolylineShapeType()
        {
            PolylineShape line = new PolylineShape(1, m_metadata, m_extent, m_parts, m_positions);

            Assert.AreEqual(ShapeType.Polyline, line.ShapeType);
        }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Polyline"/> class.
 /// </summary>
 /// <param name="polyline">A PolylineShape object read from a shapefile.</param>
 /// <param name="document">The CzmlDocument to write to.</param>
 /// <param name="color">The polyline's color.</param>
 public Polyline(PolylineShape polyline, CzmlDocument document, Color color)
     : base(document, color)
 {
     m_shape = polyline;
 }
예제 #27
0
 public void TestPolylinePositions()
 {
     PolylineShape line = new PolylineShape(1, m_metadata, m_extent, m_parts, m_positions);
     Assert.AreEqual(line[0][0], new Cartographic(0.0, 0.0, 0.0));
     Assert.AreEqual(line[0][1], new Cartographic(Constants.RadiansPerDegree, Constants.RadiansPerDegree, 0.0));
 }
예제 #28
0
 public void TestPolylineShapeType()
 {
     PolylineShape line = new PolylineShape(1, m_metadata, m_extent, m_parts, m_positions);
     Assert.AreEqual(ShapeType.Polyline, line.ShapeType);
 }
예제 #29
0
        public PolylineShapefile(
            Shapefile shapefile,
            Context context,
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);
            Verify.ThrowIfNull(appearance);

            _polyline = new OutlinedPolylineTexture();

            int positionsCount = 0;
            int indicesCount   = 0;

            PolylineCapacities(shapefile, out positionsCount, out indicesCount);

            VertexAttributeDoubleVector3 positionAttribute     = new VertexAttributeDoubleVector3("position", positionsCount);
            VertexAttributeRGBA          colorAttribute        = new VertexAttributeRGBA("color", positionsCount);
            VertexAttributeRGBA          outlineColorAttribute = new VertexAttributeRGBA("outlineColor", positionsCount);
            IndicesUnsignedInt           indices = new IndicesUnsignedInt(indicesCount);

            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Polyline)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                PolylineShape polylineShape = (PolylineShape)shape;

                for (int j = 0; j < polylineShape.Count; ++j)
                {
                    ShapePart part = polylineShape[j];

                    for (int i = 0; i < part.Count; ++i)
                    {
                        Vector2D point = part[i];

                        positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))));
                        colorAttribute.AddColor(appearance.PolylineColor);
                        outlineColorAttribute.AddColor(appearance.PolylineOutlineColor);

                        if (i != 0)
                        {
                            indices.Values.Add((uint)positionAttribute.Values.Count - 2);
                            indices.Values.Add((uint)positionAttribute.Values.Count - 1);
                        }
                    }
                }
            }

            Mesh mesh = new Mesh();

            mesh.PrimitiveType = PrimitiveType.Lines;
            mesh.Attributes.Add(positionAttribute);
            mesh.Attributes.Add(colorAttribute);
            mesh.Attributes.Add(outlineColorAttribute);
            mesh.Indices = indices;
            _polyline.Set(context, mesh);
            _polyline.Width        = appearance.PolylineWidth;
            _polyline.OutlineWidth = appearance.PolylineOutlineWidth;
        }
예제 #30
0
        /// <summary>
        /// Read MICAPS map
        /// </summary>
        /// <param name="aFile">file name</param>
        public static VectorLayer ReadMapFile_MICAPS(string aFile)
        {
            StreamReader sr = new StreamReader(aFile);
            string       aLine;

            string[]      dataArray;
            int           i, LastNonEmpty, lineNum, pNum;
            int           lType, isClose;
            List <PointD> pList = new List <PointD>();
            //PointD aPoint;
            ArrayList     dataList = new ArrayList();
            PolylineShape aPolyline;

            VectorLayer aLayer     = new VectorLayer(ShapeTypes.Polyline);
            string      columnName = "Value";
            DataColumn  aDC        = new DataColumn(columnName, typeof(int));

            aLayer.EditAddField(aDC);

            lineNum = 0;
            lType   = 0;
            isClose = 0;
            aLine   = sr.ReadLine().Trim();
            if (aLine.Substring(0, 7) != "March 9")
            {
                MessageBox.Show("Data format is wrong!" + Environment.NewLine +
                                "Need MICAPS (March 9) data!", "Error");
                return(null);
            }
            aLine = sr.ReadLine();
            while (aLine != null)
            {
                aLine = sr.ReadLine();
                if (aLine == null)
                {
                    break;
                }
                dataArray    = aLine.Split();
                LastNonEmpty = -1;
                dataList.Clear();
                for (i = 0; i < dataArray.Length; i++)
                {
                    if (dataArray[i] != string.Empty)
                    {
                        LastNonEmpty++;
                        dataList.Add(dataArray[i]);
                    }
                }

                if (dataList.Count != 2)
                {
                    pNum    = Convert.ToInt32(dataList[0]);
                    lType   = Convert.ToInt32(dataList[1]);
                    isClose = Convert.ToInt32(dataList[2]);
                    if (pList.Count > 0)
                    {
                        //if (isClose == 1)
                        //{
                        aPolyline          = new PolylineShape();
                        aPolyline.value    = lineNum;
                        aPolyline.Points   = pList;
                        aPolyline.Extent   = MIMath.GetPointsExtent(pList);
                        aPolyline.PartNum  = 1;
                        aPolyline.parts    = new int[1];
                        aPolyline.parts[0] = 0;

                        int shapeNum = aLayer.ShapeNum;
                        if (aLayer.EditInsertShape(aPolyline, shapeNum))
                        {
                            aLayer.EditCellValue(columnName, shapeNum, lineNum);
                        }

                        lineNum++;
                        //}
                        pList.Clear();
                    }
                }
                else
                {
                    PointD aPoint = new PointD();
                    aPoint.X = Convert.ToDouble(dataList[0]);
                    aPoint.Y = Convert.ToDouble(dataList[1]);
                    pList.Add(aPoint);
                }
            }
            //if (isClose == 1)
            //{
            aPolyline        = new PolylineShape();
            aPolyline.value  = lineNum;
            aPolyline.Extent = MIMath.GetPointsExtent(pList);
            aPolyline.Points = pList;

            int sNum = aLayer.ShapeNum;

            if (aLayer.EditInsertShape(aPolyline, sNum))
            {
                aLayer.EditCellValue(columnName, sNum, lineNum);
            }


            sr.Close();

            aLayer.LayerName     = Path.GetFileName(aFile);
            aLayer.FileName      = aFile;
            aLayer.LayerDrawType = LayerDrawType.Map;
            aLayer.LegendScheme  = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
            aLayer.Visible       = true;

            return(aLayer);
        }