예제 #1
0
        public static SHPObj BuildObject(byte[] bytes)
        {
            int       iType     = BitConverter.ToInt32(bytes, 0);
            ShapeType shapeType = (ShapeType)Enum.ToObject(typeof(ShapeType), iType);
            SHPObj    obj       = new SHPObj(shapeType);

            int numPoints, numParts;

            double[] box;
            Point[]  points;
            int[]    parts;

            switch (shapeType)
            {
            case ShapeType.Point:
                obj.Shape = BuildPoint(bytes, 4);
                break;

            case ShapeType.MultiPoint:
                box       = BuildBox(bytes, 4);
                numPoints = BitConverter.ToInt32(bytes, 36);
                points    = BuildPoints(bytes, 40, numPoints);
                obj.Shape = new MultiPoint(box, numPoints, points);
                break;

            case ShapeType.PolyLine:
                box       = BuildBox(bytes, 4);
                numParts  = BitConverter.ToInt32(bytes, 36);
                numPoints = BitConverter.ToInt32(bytes, 40);
                parts     = BuildParts(bytes, 44, numParts);
                points    = BuildPoints(bytes, 44 + 4 * numParts, numPoints);
                obj.Shape = new PolyLine(box, numParts, numPoints, parts, points);
                break;

            case ShapeType.Polygon:
                box       = BuildBox(bytes, 4);
                numParts  = BitConverter.ToInt32(bytes, 36);
                numPoints = BitConverter.ToInt32(bytes, 40);
                parts     = BuildParts(bytes, 44, numParts);
                points    = BuildPoints(bytes, 44 + 4 * numParts, numPoints);
                obj.Shape = new Polygon(box, numParts, numPoints, parts, points);
                break;
            }

            return(obj);
        }
예제 #2
0
        public static SHPObj BuildObject(byte[] bytes)
        {
            int iType = BitConverter.ToInt32(bytes, 0);
            ShapeType shapeType = (ShapeType)Enum.ToObject(typeof(ShapeType), iType);
            SHPObj obj = new SHPObj(shapeType);

            int numPoints, numParts;
            double[] box;
            Point[] points;
            int[] parts;

            switch (shapeType)
            {
                case ShapeType.Point:
                    obj.Shape = BuildPoint(bytes, 4);
                    break;
                case ShapeType.MultiPoint:
                    box = BuildBox(bytes, 4);
                    numPoints = BitConverter.ToInt32(bytes, 36);
                    points = BuildPoints(bytes, 40, numPoints);
                    obj.Shape = new MultiPoint(box, numPoints, points);
                    break;
                case ShapeType.PolyLine:
                    box = BuildBox(bytes, 4);
                    numParts = BitConverter.ToInt32(bytes, 36);
                    numPoints = BitConverter.ToInt32(bytes, 40);
                    parts = BuildParts(bytes, 44, numParts);
                    points = BuildPoints(bytes, 44 + 4 * numParts, numPoints);
                    obj.Shape = new PolyLine(box, numParts, numPoints, parts, points);
                    break;
                case ShapeType.Polygon:
                    box = BuildBox(bytes, 4);
                    numParts = BitConverter.ToInt32(bytes, 36);
                    numPoints = BitConverter.ToInt32(bytes, 40);
                    parts = BuildParts(bytes, 44, numParts);
                    points = BuildPoints(bytes, 44 + 4 * numParts, numPoints);
                    obj.Shape = new Polygon(box, numParts, numPoints, parts, points);
                    break;
            }

            return obj;
        }