示例#1
0
        private static /*int*/ void WriteRecordToFile(BigEndianBinaryWriter shpBinaryWriter,
                                                      BigEndianBinaryWriter shxBinaryWriter, ShapeHandler handler, IGeometry body, int oid)
        {
            if (body == null || body.IsEmpty)
            {
                WriteNullShapeRecord(shpBinaryWriter, shxBinaryWriter, oid);
                return;
            }

            // Get the length of each record (in bytes)
            var recordLength = handler.ComputeRequiredLengthInWords(body);

            // Get the position in the stream
            var pos = shpBinaryWriter.BaseStream.Position;

            shpBinaryWriter.WriteIntBE(oid);
            shpBinaryWriter.WriteIntBE(recordLength);

            // update shapefile index (position in words, 1 word = 2 bytes)
            var posWords = pos / 2;

            if (shxBinaryWriter != null)
            {
                shxBinaryWriter.WriteIntBE((int)posWords);
                shxBinaryWriter.WriteIntBE(recordLength);
            }

            handler.Write(body, shpBinaryWriter, body.Factory);
            /*return recordLength;*/
        }
示例#2
0
        private static void WriteNullShapeRecord(BigEndianBinaryWriter shpBinaryWriter,
                                                 BigEndianBinaryWriter shxBinaryWriter, int oid)
        {
            const int recordLength = 12;

            // Update shapefile index (position in words, 1 word = 2 bytes)
            var posWords = shpBinaryWriter.BaseStream.Position / 2;

            if (shxBinaryWriter != null)
            {
                shxBinaryWriter.WriteIntBE((int)posWords);
                shxBinaryWriter.WriteIntBE(recordLength);
            }

            // Add shape
            shpBinaryWriter.WriteIntBE(oid);
            shpBinaryWriter.WriteIntBE(recordLength);
            shpBinaryWriter.Write((int)ShapeGeometryType.NullShape);
        }
示例#3
0
        /// <summary>
        /// Writes a shapefile header to the given stream;
        /// </summary>
        /// <param name="file">The binary writer to use.</param>
        public void Write(BigEndianBinaryWriter file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (_fileLength == -1)
            {
                throw new InvalidOperationException("The header properties need to be set before writing the header record.");
            }
            var pos = 0;

            file.WriteIntBE(_fileCode);
            pos += 4;
            for (var i = 0; i < 5; i++)
            {
                file.WriteIntBE(0);//Skip unused part of header
                pos += 4;
            }
            file.WriteIntBE(_fileLength);
            pos += 4;
            file.Write(_version);
            pos += 4;

            var format = EnumUtility.Format(typeof(ShapeGeometryType), _shapeType, "d");

            file.Write(int.Parse(format));

            pos += 4;
            // Write the bounding box
            file.Write(_bounds.MinX);
            file.Write(_bounds.MinY);
            file.Write(_bounds.MaxX);
            file.Write(_bounds.MaxY);
            pos += 8 * 4;

            // Skip remaining unused bytes
            for (int i = 0; i < 4; i++)
            {
                file.Write(0.0); // Skip unused part of header
                pos += 8;
            }
        }