Example #1
0
        public static void MergeManyShpFile(string[] filenames, string tempfile, string TargetFile)
        {
            ShpFunction.MergeShp(filenames[0], filenames[1], tempfile);
            string temp = "";

            for (int i = 2; i < filenames.Length; i++)
            {
                ShpFunction.MergeShp(filenames[i], tempfile, TargetFile);
                temp       = tempfile;
                tempfile   = TargetFile;
                TargetFile = temp;
            }
            File.Delete(tempfile);
        }
        public static void MergeManyShpFile(string[] filenames, string TargetFile)
        {
            string Temp1    = TargetFile.Substring(TargetFile.LastIndexOf("\\"), TargetFile.Length - TargetFile.LastIndexOf("\\"));
            string tempfile = TargetFile.Replace(Temp1, "") + "\\Tempfile.shp";

            ShpFunction.MergeShp(filenames[0], filenames[1], tempfile);
            string temp = "";

            for (int i = 2; i < filenames.Length; i++)
            {
                ShpFunction.MergeShp(filenames[i], tempfile, TargetFile);
                temp       = tempfile;
                tempfile   = TargetFile;
                TargetFile = temp;
            }
            File.Copy(tempfile, TargetFile, true);
            File.Delete(tempfile);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            TextFileName  = textBox2.Text.Trim();
            TextFileName1 = textBox3.Text.Trim();
            SaveFileDialog sfd = new SaveFileDialog();                                             //string localFilePath, fileNameExt, newFileName, FilePath;

            sfd.Filter           = "Shp文件|*.shp";                                                  //设置文件类型
            sfd.FilterIndex      = 1;                                                              //设置默认文件类型显示顺序
            sfd.RestoreDirectory = true;                                                           //保存对话框是否记忆上次打开的目录
            if (sfd.ShowDialog() == DialogResult.OK)                                               //点了保存按钮进入
            {
                localFilePath = sfd.FileName.ToString();                                           //获得文件路径
                string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
            }
            TextFileName2 = localFilePath;
            if (!File.Exists(TextFileName) && !File.Exists(TextFileName1)) // 首先判断,文件是否已经存在
            {
                MessageBox.Show(TextFileName + "文件不存在!");                  // 如果文件不存在,那么提示无法读取!
                return;
            }
            ShpFunction.MergeShp(TextFileName, TextFileName1, TextFileName2);
            MessageBox.Show("合并成功!");
        }
Example #4
0
        private void button6_Click(object sender, EventArgs e)
        {
            string foldPath            = "";
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.Description = "请选择文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                foldPath = dialog.SelectedPath;
                MessageBox.Show("已选择文件夹:" + foldPath, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }//获取文件夹名字

            string[] filenames = Directory.GetFiles(foldPath);  //获取该文件夹下面的所有文件名

            SaveFileDialog sfd = new SaveFileDialog();                                             //string localFilePath, fileNameExt, newFileName, FilePath;

            sfd.Filter           = "Shp文件|*.shp";                                                  //设置文件类型
            sfd.FilterIndex      = 1;                                                              //设置默认文件类型显示顺序
            sfd.RestoreDirectory = true;                                                           //保存对话框是否记忆上次打开的目录
            if (sfd.ShowDialog() == DialogResult.OK)                                               //点了保存按钮进入
            {
                localFilePath = sfd.FileName.ToString();                                           //获得文件路径
                string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
            }
            TextFileName2 = localFilePath;
            TextFileName1 = "d:\\hhhh.shp";
            string temp = "";

            for (int i = 0; i < filenames.Length; i++)
            {
                File.Delete(TextFileName2);
                ShpFunction.MergeShp(filenames[i], TextFileName1, TextFileName2);
                temp          = TextFileName1;
                TextFileName1 = TextFileName2;
                TextFileName2 = temp;
            }
        }