예제 #1
0
        private void CreateToOneShp(DataGridViewRowCollection rows)
        {
            var shpInfos = new List <ShpSourceInfo>();
            var shpDir   = this.txtShpDir.Text.Trim();

            for (int i = 0; i < rows.Count; i++)
            {
                try
                {
                    var path = rows[i].Cells["colFilePath2"].Value.ToString();
                    if (File.Exists(path))
                    {
                        var           projInfo = RedLineManager.GetProjInfoFromTxt(path);
                        ShpSourceInfo shpInfo  = null;
                        foreach (var info in shpInfos)
                        {
                            if (info.Wkid == projInfo.Wkid)
                            {
                                shpInfo = info; break;
                            }
                        }
                        Layer      layer;
                        DataSource dataSource;
                        if (shpInfo == null)
                        {
                            var shpName = $"DH{projInfo.ProjZone}_{projInfo.Wkid}_{DateTime.Now:yyyy_MM_dd_HH_mm_ss}.shp";
                            var shpPath = Path.Combine(shpDir, shpName);
                            dataSource = RedLineManager.CreateShapefileSource(shpPath);
                            layer      = RedLineManager.CreateRedLineLayer(dataSource, projInfo.Wkid, shpPath);
                            shpInfo    = new ShpSourceInfo {
                                Wkid = projInfo.Wkid, ShpPath = shpPath
                            };
                            shpInfos.Add(shpInfo);
                        }
                        else
                        {
                            var shpPath = shpInfo.ShpPath;
                            dataSource = Ogr.Open(shpPath, 1);
                            layer      = dataSource.GetLayerByName(Path.GetFileNameWithoutExtension(shpPath));
                        }
                        RedLineManager.ToLayer(projInfo, layer);
                        rows[i].Cells["colResultPath2"].Value = shpInfo.ShpPath;
                        rows[i].Cells["colResult2"].Value     = "成功";
                    }
                }
                catch (Exception ex)
                {
                    rows[i].Cells["colResult2"].Value = ex.Message.Contains("GDAL_DATA")
                        ? "失败:要确保正常txt转shapefile,请将本工具放置在不含中文的目录中(" + ex.Message + "),且勿删除Data文件夹"
                        : "失败:" + ex.Message;
                }
                this.progressBar1.Value++;
                Application.DoEvents();
            }
        }