示例#1
0
 public static ShapeHeader MergeShapeHeader(ShapeHeader shapeHeader1, ShapeHeader shapeHeader2)
 {
     // Two shapefiles after merge relive one header.
     shapeHeader1.fileLenth   = shapeHeader1.fileLenth + shapeHeader2.fileLenth - 50;
     shapeHeader1.boundingBox = MergeBoundingBox(shapeHeader1.boundingBox, shapeHeader2.boundingBox);
     return(shapeHeader1);
 }
示例#2
0
        public static void MergerManyShapeFile(String[] files, string TargetFile, BackgroundWorker worker, DoWorkEventArgs e)
        {
            if (File.Exists(TargetFile))
            {
                File.Delete(TargetFile);
            }

            File.Copy(files[0], TargetFile, true);
            FileStream   fileStream1   = new FileStream(TargetFile, FileMode.Open, FileAccess.ReadWrite);
            BinaryReader binaryReader1 = new BinaryReader(fileStream1);
            BinaryWriter binaryWriter  = new BinaryWriter(fileStream1);
            ShapeHeader  shapeHeader1  = new ShapeHeader();

            shapeHeader1 = ShapeFucntion.ReadShapeHeader(binaryReader1);
            Record record = new Record();

            while (binaryReader1.BaseStream.Position < binaryReader1.BaseStream.Length)
            {
                record = ShapeFucntion.ReadRecord(binaryReader1);
            }
            int recordNum = record.recordNumber;

            for (int i = 1; i < files.Length; i++)
            {
                FileStream   fileStream2   = new FileStream(files[i], FileMode.Open, FileAccess.Read);
                BinaryReader binaryReader2 = new BinaryReader(fileStream2);
                ShapeHeader  shapeHeader2  = new ShapeHeader();
                shapeHeader2 = ShapeFucntion.ReadShapeHeader(binaryReader2);
                shapeHeader1 = ShapeFucntion.MergeShapeHeader(shapeHeader1, shapeHeader2);

                while (binaryReader2.BaseStream.Position < binaryReader2.BaseStream.Length)
                {
                    recordNum++;
                    record = ShapeFucntion.ReadRecord(binaryReader2);
                    record.recordNumber = recordNum;
                    ShapeFucntion.WriteRecord(record, binaryWriter);
                }
                binaryReader2.Close();
                fileStream2.Close();

                //  Thread.Sleep(500);
                worker.ReportProgress(i * 100 / (files.Length - 1));
                if (worker.CancellationPending)
                {
                    fileStream1.Seek(0, SeekOrigin.Begin);
                    ShapeFucntion.WriteShapeHeader(shapeHeader1, binaryWriter);
                    binaryReader1.Close();
                    binaryWriter.Close();
                    fileStream1.Close();
                    e.Cancel = true;
                    return;
                }
            }
            fileStream1.Seek(0, SeekOrigin.Begin);
            ShapeFucntion.WriteShapeHeader(shapeHeader1, binaryWriter);
            binaryReader1.Close();
            binaryWriter.Close();
            fileStream1.Close();
        }
示例#3
0
        public static void MergerManyShapeFile(String[] files, string TargetFile, ContorlValue contorlValue, Refresh refreshProBar)
        {
            if (File.Exists(TargetFile))
            {
                File.Delete(TargetFile);
            }
            contorlValue.Invoke(0, files.Length - 1);
            File.Copy(files[0], TargetFile, true);
            FileStream   fileStream1   = new FileStream(TargetFile, FileMode.Open, FileAccess.ReadWrite);
            BinaryReader binaryReader1 = new BinaryReader(fileStream1);
            BinaryWriter binaryWriter  = new BinaryWriter(fileStream1);
            ShapeHeader  shapeHeader1  = new ShapeHeader();

            shapeHeader1 = ShapeFucntion.ReadShapeHeader(binaryReader1);
            Record record = new Record();

            while (binaryReader1.BaseStream.Position < binaryReader1.BaseStream.Length)
            {
                record = ShapeFucntion.ReadRecord(binaryReader1);
            }
            int recordNum = record.recordNumber;

            for (int i = 1; i < files.Length; i++)
            {
                FileStream   fileStream2   = new FileStream(files[i], FileMode.Open, FileAccess.Read);
                BinaryReader binaryReader2 = new BinaryReader(fileStream2);
                ShapeHeader  shapeHeader2  = new ShapeHeader();
                shapeHeader2 = ShapeFucntion.ReadShapeHeader(binaryReader2);
                shapeHeader1 = ShapeFucntion.MergeShapeHeader(shapeHeader1, shapeHeader2);

                while (binaryReader2.BaseStream.Position < binaryReader2.BaseStream.Length)
                {
                    recordNum++;
                    record = ShapeFucntion.ReadRecord(binaryReader2);
                    record.recordNumber = recordNum;
                    ShapeFucntion.WriteRecord(record, binaryWriter);
                }
                binaryReader2.Close();
                fileStream2.Close();
                refreshProBar.Invoke(i);
                Thread.Sleep(500);
            }
            fileStream1.Seek(0, SeekOrigin.Begin);
            ShapeFucntion.WriteShapeHeader(shapeHeader1, binaryWriter);
            binaryReader1.Close();
            binaryWriter.Close();
            fileStream1.Close();
        }
示例#4
0
        public static void WriteShapeHeader(ShapeHeader shapeHeader, BinaryWriter binaryWriter)
        {
            // Write int32 using big Endian.
            WriteInt32UsingBigEndian(shapeHeader.fileCode, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.unUsed1, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.unUsed2, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.unUsed3, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.unUsed4, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.unUsed5, binaryWriter);
            WriteInt32UsingBigEndian(shapeHeader.fileLenth, binaryWriter);

            // Write int32  using little Endian.
            binaryWriter.Write(shapeHeader.fileVerion);
            binaryWriter.Write(shapeHeader.shapeType);
            WriteBoundingBox(shapeHeader.boundingBox, binaryWriter);
        }
示例#5
0
        public static ShapeHeader ReadShapeHeader(BinaryReader binaryReader)
        {
            ShapeHeader shapeHeader = new ShapeHeader();

            //// Read int32 using big Endian.
            shapeHeader.fileCode  = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.unUsed1   = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.unUsed2   = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.unUsed3   = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.unUsed4   = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.unUsed5   = ReadInt32UsingBigEndian(binaryReader);
            shapeHeader.fileLenth = ReadInt32UsingBigEndian(binaryReader);

            ////Read int32  using little Endian.
            shapeHeader.fileVerion  = binaryReader.ReadInt32();
            shapeHeader.shapeType   = binaryReader.ReadInt32();
            shapeHeader.boundingBox = ReadBoundingBox(binaryReader);
            return(shapeHeader);
        }