protected ShapefileWriter(string path, ShapefileHeader header, FileMode fileMode, FileAccess fileAccess)
        {
            _writerShape = new BinaryWriter(new FileStream(path, fileMode, fileAccess));
            _writerIndex = new BinaryWriter(new FileStream(Path.ChangeExtension(path, ".shx"), fileMode, fileAccess));

            _header = header;
        }
        public static ShapefileHeader Read(BinaryReader reader)
        {
            ShapefileHeader header = new ShapefileHeader();

            int fileType = reader.ReadInt32BE();
            if (fileType != 9994)
                throw new Exception("The first four bytes of this file indicate this is not a shape file.");

            // skip 5 unsed bytes
            reader.BaseStream.Seek(20L, SeekOrigin.Current);

            header.FileLength = reader.ReadInt32BE();

            int version = reader.ReadInt32();
            if (version != 1000)
                throw new Exception("Shapefile is not the proper version");

            header.ShapeType = (ShapefileGeometryType)reader.ReadInt32();

            double[] coords = new double[4];
            for (int i = 0; i < 4; i++)
                coords[i] = reader.ReadDouble();
            header.Bounds = new Envelope(coords[0], coords[2], coords[1], coords[3]);

            // Skip to end of header
            reader.BaseStream.Seek(100L, SeekOrigin.Begin);

            return header;
        }
        public static ShapefileWriter Create(string path, ShapefileHeader header)
        {
            ShapefileWriter writer = new ShapefileWriter(path, header, FileMode.CreateNew, FileAccess.Write);

            writer._writerShape.BaseStream.Seek(100L, SeekOrigin.Begin);
            writer._writerIndex.BaseStream.Seek(100L, SeekOrigin.Begin);

            writer._recordNumber = 1;
            writer._filePos = 50;

            return writer;
        }
        public static ShapefileDataWriter Create(string path, DbfHeader dbfHeader, ShapefileHeader shapeHeader)
        {
            ShapefileDataWriter writer = new ShapefileDataWriter(path, shapeHeader, FileMode.CreateNew, FileAccess.Write);

            writer._writerShape.BaseStream.Seek(100L, SeekOrigin.Begin);
            writer._writerIndex.BaseStream.Seek(100L, SeekOrigin.Begin);

            writer._dbf = DbfFile.Create(Path.ChangeExtension(path, ".dbf"), dbfHeader);
            writer._currentRecord = new DbfRecord(dbfHeader);

            writer._recordNumber = 1;
            writer._filePos = 50;

            return writer;
        }
Esempio n. 5
0
        public static ShapefileHeader Read(BinaryReader reader)
        {
            ShapefileHeader header = new ShapefileHeader();

            int fileType = reader.ReadInt32BE();

            if (fileType != 9994)
            {
                throw new Exception("The first four bytes of this file indicate this is not a shape file.");
            }

            // skip 5 unsed bytes
            reader.BaseStream.Seek(20L, SeekOrigin.Current);

            header.FileLength = reader.ReadInt32BE();

            int version = reader.ReadInt32();

            if (version != 1000)
            {
                throw new Exception("Shapefile is not the proper version");
            }

            header.ShapeType = (ShapefileGeometryType)reader.ReadInt32();

            double[] coords = new double[4];
            for (int i = 0; i < 4; i++)
            {
                coords[i] = reader.ReadDouble();
            }
            header.Bounds = new Envelope(coords[0], coords[2], coords[1], coords[3]);

            // Skip to end of header
            reader.BaseStream.Seek(100L, SeekOrigin.Begin);

            return(header);
        }
 protected ShapefileDataWriter(string path, ShapefileHeader shapeHeader, FileMode fileMode, FileAccess fileAccess)
     : base(path, shapeHeader, fileMode, fileAccess)
 {
 }
        private void Write(ShapefileHeader header, BinaryWriter stream, int fileLength)
        {
            stream.BaseStream.Seek(0, SeekOrigin.Begin);

            stream.WriteBE(9994);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(0);
            stream.WriteBE(fileLength);
            stream.Write(1000);
            stream.Write((int)header.ShapeType);
            stream.Write(header.Bounds.Minimum.X);
            stream.Write(header.Bounds.Minimum.Y);
            stream.Write(header.Bounds.Maximum.X);
            stream.Write(header.Bounds.Maximum.Y);
        }
 protected ShapefileDataWriter(string path, ShapefileHeader shapeHeader, FileMode fileMode, FileAccess fileAccess)
     : base(path, shapeHeader, fileMode, fileAccess)
 {
 }