/// <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.");
            }
            int pos = 0;

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

            file.Write(int.Parse(Enum.Format(typeof(ShapeType), _shapeType, "d")));
            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
            //file.setLittleEndianMode(false);//well they may not be unused forever...
            for (int i = 0; i < 4; i++)
            {
                file.Write(0.0);                //Skip unused part of header
                pos += 8;
            }
            Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled, "Header pos:" + pos);
        }
Exemple #2
0
        /// <summary>
        /// Writes a shapefile header to the given stream;
        /// </summary>
        /// <param name="writer">The binary writer to use.</param>
        public void Write(BigEndianBinaryWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (_fileLength == -1)
            {
                throw new InvalidOperationException("The header properties need to be set before writing the header record.");
            }

            writer.WriteIntBE(_fileCode);

            for (int i = 0; i < 5; i++)
            {
                writer.WriteIntBE(0);                   // Skip unused part of header
            }

            writer.WriteIntBE(_fileLength);
            writer.Write(_version);
            writer.Write((int)_shapeType);

            // Write the bounding box
            writer.Write(_bounds.getMinX());
            writer.Write(_bounds.getMinY());
            writer.Write(_bounds.getMaxX());
            writer.Write(_bounds.getMaxY());

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

            Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled, "Header position: " + writer.BaseStream.Position);
        }
		/// <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.");
			}
			int pos = 0;
			//file.setLittleEndianMode(false);
			file.WriteIntBE(_fileCode);
			pos += 4;
			for (int i = 0; i < 5; i++)
			{
				file.WriteIntBE(0);//Skip unused part of header
				pos += 4;
			}
			file.WriteIntBE(_fileLength);
			pos += 4;
			//file.setLittleEndianMode(true);
			file.Write(_version);
			pos += 4;
			
			file.Write(int.Parse(Enum.Format(typeof(ShapeType),_shapeType,"d")));
			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
			//file.setLittleEndianMode(false);//well they may not be unused forever...
			for (int i = 0; i < 4; i++)
			{
				file.Write(0.0);//Skip unused part of header
				pos += 8;
			}
			Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled,"Header pos:"+pos);
		}
Exemple #4
0
        /// <summary>
        /// Writes a shapefile header to the given stream;
        /// </summary>
        /// <param name="writer">The binary writer to use.</param>
        public void Write(BigEndianBinaryWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (_fileLength == -1)
            {
                throw new InvalidOperationException("The header properties need to be set before writing the header record.");
            }

            writer.WriteIntBE(_fileCode);

            for (int i = 0; i < 5; i++)
            {
                writer.WriteIntBE(0);	// Skip unused part of header
            }

            writer.WriteIntBE(_fileLength);
            writer.Write(_version);
            writer.Write((int)_shapeType);

            // Write the bounding box
            writer.Write(_bounds.getMinX());
            writer.Write(_bounds.getMinY());
            writer.Write(_bounds.getMaxX());
            writer.Write(_bounds.getMaxY());

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

            Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled, "Header position: " + writer.BaseStream.Position);
        }