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);
        }
Esempio n. 2
0
        public void TestPolylineZShapeType()
        {
            double[]       zValues  = new double[] { 1.0, 2.0 };
            double[]       measures = new double[] { 0.0, 0.0 };
            PolylineZShape line     = new PolylineZShape(1, m_metadata, m_extent, m_parts, m_positions, 1.0, 2.0, zValues, 0.0, 0.0, measures);

            Assert.AreEqual(ShapeType.PolylineZ, line.ShapeType);
        }
Esempio n. 3
0
        public void TestPolylineZPositions()
        {
            double[]       zValues  = new double[] { 1.0, 2.0 };
            double[]       measures = new double[] { 0.0, 0.0 };
            PolylineZShape line     = new PolylineZShape(1, m_metadata, m_extent, m_parts, m_positions, 1.0, 2.0, zValues, 0.0, 0.0, measures);

            Assert.AreEqual(line[0][0], new Cartographic(0.0, 0.0, 1.0));
            Assert.AreEqual(line[0][1], new Cartographic(Constants.RadiansPerDegree, Constants.RadiansPerDegree, 2.0));
        }
        public void TestPolylineZValues()
        {
            Rectangular[] positions = new Rectangular[] {
                new Rectangular(0.0, 0.0),
                new Rectangular(1.0, 1.0),
                new Rectangular(2.0, 2.0),
                new Rectangular(3.0, 3.0),
            };

            double[]           zValues = new double[] { 0.0, 1.0, 2.0, 3.0 };
            CartographicExtent extent  = new CartographicExtent(0.0, 0.0, 3.0, 3.0);

            int[]    parts    = new int[] { 0 };
            double[] measures = new double[] { 0.0, 0.0, 0.0, 0.0 };

            PolylineZShape polylineZShape = new PolylineZShape(0, new StringDictionary(), extent, parts, positions, 1.0, 8.0, zValues, 0.0, 0.0, measures);
            Polyline       polyline       = new Polyline(polylineZShape, m_document, Color.Blue);

            polyline.Write();
            string result = m_stringWriter.ToString();

            Assert.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(result, m_polylinePattern));
        }
        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;
            }
        }
        private static VectorLayer ReadPolylineZShapes(BinaryReader br, int shapeNum)
        {
            VectorLayer aLayer = new VectorLayer(ShapeTypes.PolylineZ);
            double      x, y;

            //PointD aPoint;
            for (int i = 0; i < shapeNum; i++)
            {
                br.ReadBytes(12);

                //Read bounding box
                PolylineZShape aPL = new PolylineZShape();
                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 position 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;

                ////Read Z
                //aPL.ZRange[0] = br.ReadDouble();
                //aPL.ZRange[1] = br.ReadDouble();
                //aPL.ZArray = new double[aPL.numPoints];
                //for (int j = 0; j < aPL.numPoints; j++)
                //    aPL.ZArray[j] = br.ReadDouble();

                ////Read measure
                //aPL.MRange[0] = br.ReadDouble();
                //aPL.MRange[1] = br.ReadDouble();
                //aPL.MArray = new double[aPL.numPoints];
                //for (int j = 0; j < aPL.numPoints; j++)
                //    aPL.MArray[j] = br.ReadDouble();

                //Read Z
                double   zmin   = br.ReadDouble();
                double   zmax   = br.ReadDouble();
                double[] zArray = new double[numPoints];
                for (int j = 0; j < numPoints; j++)
                {
                    zArray[j] = br.ReadDouble();
                }

                //Read measure
                double   mmin   = br.ReadDouble();
                double   mmax   = br.ReadDouble();
                double[] mArray = new double[numPoints];
                for (int j = 0; j < numPoints; j++)
                {
                    mArray[j] = br.ReadDouble();
                }

                //Get pointZ list
                List <PointD> pointZs = new List <PointD>();
                for (int j = 0; j < numPoints; j++)
                {
                    pointZs.Add(new PointZ(points[j].X, points[j].Y, zArray[j], mArray[j]));
                }

                aPL.Points = pointZs;
                aLayer.ShapeList.Add(aPL);
            }

            //Create legend scheme
            aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F);
            return(aLayer);
        }