示例#1
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();
        }
示例#2
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();
        }