private void BindChild(TreeNode fNode) { string path = fNode.Name; if (path == null || !Directory.Exists(path)) { return; } DirectoryInfo fDir = new DirectoryInfo(path); FileSystemInfo[] finfos = fDir.GetFileSystemInfos(); SpatialReferenceFile spatialRefFile; foreach (FileSystemInfo f in finfos) { spatialRefFile = new SpatialReferenceFile(); string type = f.GetType().ToString(); TreeNode node = new TreeNode(); node.Name = f.FullName; //将文件的完整路径保存在节点的名字中 if ("System.IO.DirectoryInfo" == type) //是文件夹才递归调用自己 { spatialRefFile.IsPrjFile = false; node.Tag = spatialRefFile; node.ImageIndex = 0; node.SelectedImageIndex = 2; node.Text = f.Name; //将文件的名字保存在节点的文本显示中 fNode.Nodes.Add(node); BindChild(node); } else { if (!f.Name.Contains(".prj")) { continue; } if (f.Name.Substring(f.Name.LastIndexOf('.')) != ".prj") { continue; } node.Text = f.Name.Remove(f.Name.LastIndexOf('.')); spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(f.FullName); //是否能成功解析prj文件 spatialRefFile.IsPrjFile = true; node.Tag = spatialRefFile; node.ImageIndex = 1; node.SelectedImageIndex = 1; fNode.Nodes.Add(node); } } }
private void InitSpatialRefTree() { TreeNode root = new TreeNode(); root.Text = @"地理坐标系统"; string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "坐标系统\\预定义\\地理坐标系统"); root.Name = path; SpatialReferenceFile spatialRefFile = new SpatialReferenceFile(); spatialRefFile.IsPrjFile = false; root.Tag = spatialRefFile; tvSpatialRefTree.Nodes.Add(root); BindChild(root); tvSpatialRefTree.Nodes[0].Expand(); }
/// <summary> /// 解析坐标系统文件夹,并添加到树中 /// </summary> /// <param name="fNode"></param> private void BindChild(TreeNode fNode) { string path = fNode.Name; if (path == null || !Directory.Exists(path)) { return; } string[] paths = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); SpatialReferenceFile spatialRefFile; for (int i = 0; i < paths.Length; i++) { string subPath = paths[i]; TreeNode node = new TreeNode(); node.Name = subPath; spatialRefFile = new SpatialReferenceFile(); spatialRefFile.IsPrjFile = false; node.Tag = spatialRefFile; node.ImageIndex = 0; node.SelectedImageIndex = 2; node.Text = Path.GetFileNameWithoutExtension(subPath); fNode.Nodes.Add(node); BindChild(node); } for (int i = 0; i < files.Length; i++) { string subFile = files[i]; string fileExt = Path.GetExtension(subFile); if (fileExt != ".prj") { continue; } TreeNode node = new TreeNode(); node.Name = subFile; node.Text = Path.GetFileNameWithoutExtension(subFile); spatialRefFile = new SpatialReferenceFile(); spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(subFile); spatialRefFile.IsPrjFile = true; node.Tag = spatialRefFile; node.ImageIndex = 1; node.SelectedImageIndex = 1; fNode.Nodes.Add(node); } }
/// <summary> /// 将新建的空间参考添加到左侧树节点中 /// </summary> private void AddToTreeView() { SpatialReferenceFile newSpatialRefFile = new SpatialReferenceFile(); newSpatialRefFile.SpatialReference = _spatialReference; newSpatialRefFile.IsPrjFile = true; //建立新的节点 TreeNode newNode = new TreeNode(); newNode.Tag = newSpatialRefFile; newNode.Text = newSpatialRefFile.SpatialReference.Name; newNode.ImageIndex = 1; newNode.SelectedImageIndex = 1; TreeNodeCollection nodes = tvSpatialRefNames.Nodes[0].Nodes; AddToSpecificNode(nodes, newNode); tvSpatialRefNames.SelectedNode = newNode; }