示例#1
0
        public static void MergeManyShpFile(string[] sourceFiles, String saveFileName, BackgroundWorker worker, DoWorkEventArgs e)
        {
            BinaryReader binaryReader1   = null;
            FileStream   fileStreamRead  = null;
            FileStream   fileStreamWrite = null;

            fileStreamWrite = new FileStream(saveFileName, FileMode.Create, FileAccess.Write);
            BinaryWriter  binaryWriter       = new BinaryWriter(fileStreamWrite);
            Record        record             = new Record();
            int           recordLastNum      = 0;
            ShpFileHeader shpFileHeaderTatal = new ShpFileHeader();
            ShpFileHeader shpFileHeaderRead  = new ShpFileHeader();

            for (int i = 0; i < sourceFiles.Length; i++)
            {
                fileStreamRead    = new FileStream(sourceFiles[i], FileMode.Open, FileAccess.Read, FileShare.None);
                binaryReader1     = new BinaryReader(fileStreamRead);
                shpFileHeaderRead = ShapeFileFunction.ReadShpFileHeader(binaryReader1);
                if (i == 0)
                {
                    ShapeFileFunction.WriteShpFileHeader(shpFileHeaderRead, binaryWriter);
                    shpFileHeaderTatal = shpFileHeaderRead;
                }
                else
                {
                    shpFileHeaderTatal = ShapeFileFunction.MergeShpHeader(shpFileHeaderTatal, shpFileHeaderRead);
                }
                while (binaryReader1.BaseStream.Position < binaryReader1.BaseStream.Length)
                {
                    record           = ShapeFileFunction.ReadRecord(binaryReader1);
                    record.recordNum = recordLastNum++;
                    ShapeFileFunction.WriteRecord(record, binaryWriter);
                }
                binaryReader1.Close();
                fileStreamRead.Close();
                worker.ReportProgress(i * 100 / (sourceFiles.Length - 1));
                //  Thread.Sleep(200);
                if (worker.CancellationPending)
                {
                    fileStreamWrite.Seek(0, SeekOrigin.Begin);
                    WriteShpFileHeader(shpFileHeaderTatal, binaryWriter);
                    binaryWriter.Close();
                    fileStreamWrite.Close();
                    e.Cancel = true;
                    return;
                }
            }

            fileStreamWrite.Seek(0, SeekOrigin.Begin);
            WriteShpFileHeader(shpFileHeaderTatal, binaryWriter);
            binaryWriter.Close();
            fileStreamWrite.Close();
        }
示例#2
0
        public static void MergeShpRecord(BinaryReader binaryReader1, BinaryReader binaryReader2, BinaryWriter binaryWriter)
        {
            Record record = new Record();

            while (binaryReader1.BaseStream.Position < binaryReader1.BaseStream.Length)
            {
                record = ShapeFileFunction.ReadRecord(binaryReader1);
                ShapeFileFunction.WriteRecord(record, binaryWriter);
            }
            int recordLastNum = record.recordNum;

            while (binaryReader2.BaseStream.Position < binaryReader2.BaseStream.Length)
            {
                record           = ShapeFileFunction.ReadRecord(binaryReader2);
                record.recordNum = recordLastNum + record.recordNum;
                ShapeFileFunction.WriteRecord(record, binaryWriter);
            }
        }
        public static void MergeManyShpFile(string[] sourceFiles, String saveFileName, ContorlMinAndMaxValue contorlMinAndMaxValue, RefreshValue refreshValue)
        {
            BinaryReader binaryReader1   = null;
            FileStream   fileStreamRead  = null;
            FileStream   fileStreamWrite = null;

            fileStreamWrite = new FileStream(saveFileName, FileMode.Create, FileAccess.Write);
            BinaryWriter  binaryWriter       = new BinaryWriter(fileStreamWrite);
            Record        record             = new Record();
            int           recordLastNum      = 0;
            ShpFileHeader shpFileHeaderTatal = new ShpFileHeader();
            ShpFileHeader shpFileHeaderRead  = new ShpFileHeader();

            contorlMinAndMaxValue(0, sourceFiles.Length - 1);
            for (int i = 0; i < sourceFiles.Length; i++)
            {
                fileStreamRead    = new FileStream(sourceFiles[i], FileMode.Open, FileAccess.Read, FileShare.None);
                binaryReader1     = new BinaryReader(fileStreamRead);
                shpFileHeaderRead = ShapeFileFunction.ReadShpFileHeader(binaryReader1);
                if (i == 0)
                {
                    ShapeFileFunction.WriteShpFileHeader(shpFileHeaderRead, binaryWriter);
                    shpFileHeaderTatal = shpFileHeaderRead;
                }
                else
                {
                    shpFileHeaderTatal = ShapeFileFunction.MergeShpHeader(shpFileHeaderTatal, shpFileHeaderRead);
                }
                while (binaryReader1.BaseStream.Position < binaryReader1.BaseStream.Length)
                {
                    record           = ShapeFileFunction.ReadRecord(binaryReader1);
                    record.recordNum = recordLastNum++;
                    ShapeFileFunction.WriteRecord(record, binaryWriter);
                }
                binaryReader1.Close();
                fileStreamRead.Close();
                Thread.Sleep(500);
                refreshValue(i);
            }
            fileStreamWrite.Seek(0, SeekOrigin.Begin);
            WriteShpFileHeader(shpFileHeaderTatal, binaryWriter);
            binaryWriter.Close();
            fileStreamWrite.Close();
        }