示例#1
0
        private void WriteShapeMultiPointRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            byte[]          byteArray;
            ShapeMultiPoint mulPoint;
            Int32           contentLength;

            if (_currentShxRecondPosition != 0)
            {
                _fsShxFile.Seek(_currentShxRecondPosition, SeekOrigin.Begin);
            }
            if (_currentShpRecondPosition != 0)
            {
                _fsMainFile.Seek(_currentShpRecondPosition, SeekOrigin.Begin);
            }
            for (int i = 0; i < vfs.Length; i++)
            {
                mulPoint      = vfs[i].Geometry as ShapeMultiPoint;
                contentLength = (mulPoint.Points.Length * 16 + 48) / 2;

                byteArray = BitConverter.GetBytes(_featuresCount + i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes(contentLength);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(_offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                _offset += contentLength;

                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MinX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MinY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MaxX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MaxY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Points.Length);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                foreach (ShapePoint sp in mulPoint.Points)
                {
                    byteArray = BitConverter.GetBytes(sp.X);
                    _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                    byteArray = BitConverter.GetBytes(sp.Y);
                    _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                }
            }
            _currentShpRecondPosition = _fsMainFile.Position;
            _currentShxRecondPosition = _fsShxFile.Position;
        }
示例#2
0
        private void WriteShapePointRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            Int32 Offset = 50;

            byte[]     byteArray;
            ShapePoint point;


            for (int i = 0; i < vfs.Length; i++)
            {
                point = vfs[i].Geometry as ShapePoint;

                byteArray = BitConverter.GetBytes(i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes(14);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                ////
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(Offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                Offset += 14;
                ////
                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(point.X);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(point.Y);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            }
        }
示例#3
0
        private void WriteShapeMultiPointRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            Int32 Offset = 50;

            byte[]          byteArray;
            ShapeMultiPoint mulPoint;
            Int32           contentLength;

            for (int i = 0; i < vfs.Length; i++)
            {
                mulPoint      = vfs[i].Geometry as ShapeMultiPoint;
                contentLength = (mulPoint.Points.Length * 16 + 48) / 2;

                byteArray = BitConverter.GetBytes(i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes(contentLength);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                ////
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(Offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                Offset += contentLength;
                ////

                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MinX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MinY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MaxX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Envelope.MaxY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(mulPoint.Points.Length);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                foreach (ShapePoint sp in mulPoint.Points)
                {
                    byteArray = BitConverter.GetBytes(sp.X);
                    _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                    byteArray = BitConverter.GetBytes(sp.Y);
                    _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                }
            }
        }
示例#4
0
        private void WriteShapePointRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            byte[]     byteArray;
            ShapePoint point;

            if (_currentShxRecondPosition != 0)
            {
                _fsShxFile.Seek(_currentShxRecondPosition, SeekOrigin.Begin);
            }
            if (_currentShpRecondPosition != 0)
            {
                _fsMainFile.Seek(_currentShpRecondPosition, SeekOrigin.Begin);
            }
            for (int i = 0; i < vfs.Length; i++)
            {
                point = vfs[i].Geometry as ShapePoint;

                byteArray = BitConverter.GetBytes(_featuresCount + i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes(10);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(_offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                _offset += 14;

                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(point.X);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(point.Y);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            }
            _currentShpRecondPosition = _fsMainFile.Position;
            _currentShxRecondPosition = _fsShxFile.Position;
        }
示例#5
0
        private void WriteFileHeader(Feature[] features)
        {
            if (_isFirstWrite)
            {
                byte[]   byteArray;
                Envelope env = features[0].Geometry.Envelope;
                for (int i = 1; i < features.Length; i++)
                {
                    env.UnionWith(features[i].Geometry.Envelope);
                }
                _currentEnvelope = env;

                byteArray = BitConverter.GetBytes(9994);
                int byteArrayValue = ToLocalEndian.ToInt32FromBig(byteArray);
                _bwMainFile.Write(byteArrayValue);
                _bwShxFile.Write(byteArrayValue);

                byteArray = new byte[20];
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);
                //
                byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                //
                _bwMainFile.Write(1000);
                _bwShxFile.Write(1000);

                _bwMainFile.Write((int)_shapeType);
                _bwShxFile.Write((int)_shapeType);

                byteArray = BitConverter.GetBytes(env.MinX);
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);

                byteArray = BitConverter.GetBytes(env.MinY);
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);

                byteArray = BitConverter.GetBytes(env.MaxX);
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);

                byteArray = BitConverter.GetBytes(env.MaxY);
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);

                byteArray = new byte[32];
                _bwMainFile.Write(byteArray);
                _bwShxFile.Write(byteArray);
                _isFirstWrite = false;
            }
            else
            {
                byte[]   byteArray;
                Envelope env = features[0].Geometry.Envelope;
                for (int i = 1; i < features.Length; i++)
                {
                    env.UnionWith(features[i].Geometry.Envelope);
                }
                if (_currentEnvelope != null)
                {
                    env.UnionWith(_currentEnvelope);
                }
                _currentEnvelope = env;
                _fsMainFile.Seek(24, SeekOrigin.Begin);
                _fsShxFile.Seek(24, SeekOrigin.Begin);

                byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                ////
                _fsMainFile.Seek(8, SeekOrigin.Current);
                _fsShxFile.Seek(8, SeekOrigin.Current);

                byteArray = BitConverter.GetBytes(env.MinX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(env.MinY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(env.MaxX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(env.MaxY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            }
        }
示例#6
0
        private void WriteShapePolygonRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            byte[]       byteArray;
            ShapePolygon polygon;
            Int32        contentLength;
            Int32        pointsNum = 0;
            Int32        index     = 0;

            if (_currentShxRecondPosition != 0)
            {
                _fsShxFile.Seek(_currentShxRecondPosition, SeekOrigin.Begin);
            }
            if (_currentShpRecondPosition != 0)
            {
                _fsMainFile.Seek(_currentShpRecondPosition, SeekOrigin.Begin);
            }
            for (int i = 0; i < vfs.Length; i++)
            {
                polygon = vfs[i].Geometry as ShapePolygon;

                pointsNum     = 0;
                index         = 0;
                contentLength = (44 + polygon.Rings.Length * 4) / 2;
                foreach (ShapeRing part in polygon.Rings)
                {
                    contentLength += part.Points.Length * 8;
                    pointsNum     += part.Points.Length;
                }
                byteArray = BitConverter.GetBytes(_featuresCount + i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes(_offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                _offset += contentLength + 4;

                byteArray = BitConverter.GetBytes(contentLength);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MinX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MinY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MaxX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MaxY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Rings.Length);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(pointsNum);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                foreach (ShapeRing sr in polygon.Rings)
                {
                    byteArray = BitConverter.GetBytes(index);
                    _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));
                    index += sr.Points.Length;
                }
                foreach (ShapeRing sr in polygon.Rings)
                {
                    foreach (ShapePoint sp in sr.Points)
                    {
                        byteArray = BitConverter.GetBytes(sp.X);
                        _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                        byteArray = BitConverter.GetBytes(sp.Y);
                        _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                    }
                }
            }
            _currentShpRecondPosition = _fsMainFile.Position;
            _currentShxRecondPosition = _fsShxFile.Position;
        }
示例#7
0
        private void WriteVectorDataToFiles(Feature[] features)
        {
            byte[] byteArray;

            Envelope env = new Envelope(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);

            foreach (Feature vf in features)
            {
                env.UnionWith(vf.Geometry.Envelope);
            }

            ////write main file
            //write main file and shx file header
            byteArray = BitConverter.GetBytes(9994);
            _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

            byteArray = new byte[20];
            _bwMainFile.Write(byteArray);
            _bwShxFile.Write(byteArray);

            ////
            byteArray = BitConverter.GetBytes(CalculateMainfileLengthInByte(features) / 2);
            _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
            byteArray = BitConverter.GetBytes(CalculateShxfileLenthInByte(features) / 2);
            _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
            ////

            byteArray = BitConverter.GetBytes(1000);
            _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

            byteArray = BitConverter.GetBytes((int)_shapeType);
            _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));


            byteArray = BitConverter.GetBytes(env.MinX);
            _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

            byteArray = BitConverter.GetBytes(env.MinY);
            _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

            byteArray = BitConverter.GetBytes(env.MaxX);
            _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

            byteArray = BitConverter.GetBytes(env.MaxY);
            _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
            _bwShxFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

            byteArray = new byte[32];
            _bwMainFile.Write(byteArray);
            _bwShxFile.Write(byteArray);

            //write main file and Shx file records

            switch (_shapeType)
            {
            case enumShapeType.Point:
                WriteShapePointRecords(features);
                break;

            case enumShapeType.MultiPoint:
                WriteShapeMultiPointRecords(features);
                break;

            case enumShapeType.Polyline:
                WriteShapePolylineRecords(features);
                break;

            case enumShapeType.Polygon:
                WriteShapePolygonRecords(features);
                break;

            default:
                break;
            }


            ////write prj file,leave it now,no spec

            CloseVectorDataFiles();
        }
示例#8
0
        private void WriteShapePolygonRecords(Feature[] vfs)
        {
            //the fist record offset in 16-bit word
            Int32 Offset = 50;

            byte[]       byteArray;
            ShapePolygon polygon;
            Int32        contentLength;
            Int32        pointsNum = 0;
            Int32        index     = 0;

            for (int i = 0; i < vfs.Length; i++)
            {
                polygon = vfs[i].Geometry as ShapePolygon;

                pointsNum     = 0;
                index         = 0;
                contentLength = (44 + polygon.Rings.Length * 4) / 2;
                foreach (ShapeRing part in polygon.Rings)
                {
                    contentLength += part.Points.Length * 8;
                    pointsNum     += part.Points.Length;
                }



                byteArray = BitConverter.GetBytes(i + 1);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                ////
                byteArray = BitConverter.GetBytes(Offset);
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));
                Offset += contentLength + 4;
                ////


                byteArray = BitConverter.GetBytes(contentLength);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                ////
                _bwShxFile.Write(ToLocalEndian.ToInt32FromBig(byteArray));

                ////

                byteArray = BitConverter.GetBytes((int)_shapeType);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MinX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MinY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MaxX);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Envelope.MaxY);
                _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(polygon.Rings.Length);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                byteArray = BitConverter.GetBytes(pointsNum);
                _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));

                foreach (ShapeRing sr in polygon.Rings)
                {
                    byteArray = BitConverter.GetBytes(index);
                    _bwMainFile.Write(ToLocalEndian.ToInt32FromLittle(byteArray));
                    index += sr.Points.Length;
                }
                foreach (ShapeRing sr in polygon.Rings)
                {
                    foreach (ShapePoint sp in sr.Points)
                    {
                        byteArray = BitConverter.GetBytes(sp.X);
                        _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));

                        byteArray = BitConverter.GetBytes(sp.Y);
                        _bwMainFile.Write(ToLocalEndian.ToInt64FromLittle(byteArray));
                    }
                }
            }
        }