private void AddChildrenToMap(TreeNode e) { e.Nodes.OfType <TreeNode>().ToList().ForEach(x => AddChildrenToMap(x)); GISDataset ds = null; if (e.Tag is GISDataset) { ds = e.Tag as GISDataset; } else if (e.Tag is ProjectView) { ((ProjectView)e.Tag).Layers.ForEach(x => AddChildrenToMap(x.LayerNode)); } if (ds is GISDataset) { GISDataset layer = (GISDataset)e.Tag; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(e); FileInfo symbology = GetSymbology(layer); string def_query = ds is Vector ? ((Vector)ds).DefinitionQuery : string.Empty; ArcMapUtilities.AddToMap(layer, layer.Name, parentGrpLyr, GetPrecedingLayers(e), symbology, transparency: layer.Transparency, definition_query: def_query); Cursor.Current = Cursors.Default; } }
private void AddChildrenToMap(TreeNode e) { e.Nodes.OfType <TreeNode>().ToList().ForEach(x => AddChildrenToMap(x)); if (e.Tag is GISLayer) { GISLayer layer = (GISLayer)e.Tag; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(e); ArcMapUtilities.AddToMap(layer.FilePath, layer.Name, parentGrpLyr); } }
public void OnClose(object sender, EventArgs e) { try { TreeNode nodProject = treProject.SelectedNode; ArcMapUtilities.RemoveGroupLayer(nodProject.Text, false); treProject.SelectedNode.Remove(); } catch (Exception ex) { } }
public void OnAddWMSToMap(object sender, EventArgs e) { TreeNode selNode = treProject.SelectedNode; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(selNode, NodeInsertModes.Add); ProjectTree.WMSLayer layer = (ProjectTree.WMSLayer)selNode.Tag; try { ArcMapUtilities.AddWMSTopMap(layer.Name, layer.URL, parentGrpLyr); } catch (Exception ex) { MessageBox.Show(string.Format("Error adding the Web Mapping Service to the map: {0}", ex.Message), Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void OnAddGISToMap(object sender, EventArgs e) { TreeNode selNode = treProject.SelectedNode; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(selNode); GISLayer layer = (GISLayer)selNode.Tag; FileInfo symbology = GetSymbology(layer); try { ArcMapUtilities.AddToMap(layer.FilePath, layer.Name, parentGrpLyr, symbology); } catch (Exception ex) { MessageBox.Show(string.Format("{0}\n\n{1}", ex.Message, layer.FilePath.FullName), "Error Adding Dataset To Map", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public IGroupLayer BuildArcMapGroupLayers(TreeNode node, NodeInsertModes topLevelMode = NodeInsertModes.Insert) { IGroupLayer parentGrpLyr = null; if (node.Parent is TreeNode) { parentGrpLyr = BuildArcMapGroupLayers(node.Parent, topLevelMode); } if (node.Tag is GISLayer || node.Tag is ProjectTree.WMSLayer) { return(parentGrpLyr); } else { return(ArcMapUtilities.GetGroupLayer(node.Text, parentGrpLyr, topLevelMode)); } }
public void CloseAllProjects() { // Detect if project is already in tree and simply select the node and return; List <TreeNode> projects = new List <TreeNode>(); foreach (TreeNode rootNod in treProject.Nodes) { if (rootNod.Tag is RaveProject) { projects.Add(rootNod); // Remove the project from the map. SearchRecursive = False // will ensure it only looks at the top level of the map ToC ArcMapUtilities.RemoveGroupLayer(rootNod.Text, false); } } foreach (TreeNode rootNod in projects) { rootNod.Remove(); } }
public void OnAddGISToMap(object sender, EventArgs e) { TreeNode selNode = treProject.SelectedNode; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(selNode); GISDataset layer = (GISDataset)selNode.Tag; FileInfo symbology = GetSymbology(layer); string def_query = layer is Vector ? ((Vector)layer).DefinitionQuery : string.Empty; try { ArcMapUtilities.AddToMap(layer, layer.Name, parentGrpLyr, GetPrecedingLayers(selNode), symbology, transparency: layer.Transparency, definition_query: def_query); } catch (Exception ex) { MessageBox.Show(string.Format("{0}\n\n{1}", ex.Message, layer.Path.FullName), "Error Adding Dataset To Map", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } }
public static ILayer AddToMap(FileSystemDataset dataset, string sLayerName, IGroupLayer pGroupLayer, List <string> precedingLayers, FileInfo fiSymbologyLayerFile = null, bool bAddToMapIfPresent = false, short transparency = 0, string definition_query = "") { if (!dataset.Exists) { return(null); } // Only add if it doesn't exist already ILayer pResultLayer = GetLayerBySource(dataset.Path); if ((pResultLayer is ILayer && string.Compare(pResultLayer.Name, sLayerName, true) == 0) && !bAddToMapIfPresent) { return(pResultLayer); } // Confirm that the symbology layer file exists if (fiSymbologyLayerFile != null && !fiSymbologyLayerFile.Exists) { Exception ex = new Exception("A symbology layer file was provided, but the file does not exist"); ex.Data["Data Source"] = dataset.Path.FullName; ex.Data["Layer file"] = fiSymbologyLayerFile.FullName; throw ex; } IWorkspace pWorkspace = GetWorkspace(dataset); switch (dataset.WorkspaceType) { case FileSystemDataset.GISDataStorageTypes.RasterFile: IRasterDataset pRDS = ((IRasterWorkspace)pWorkspace).OpenRasterDataset(Path.GetFileName(dataset.Path.FullName)); IRasterLayer pRLResult = new RasterLayer(); pRLResult.CreateFromDataset(pRDS); pResultLayer = pRLResult; break; case FileSystemDataset.GISDataStorageTypes.CAD: string sFile = Path.GetFileName(Path.GetDirectoryName(dataset.Path.FullName)); string sFC = sFile + ":" + Path.GetFileName(dataset.Path.FullName); IFeatureClass pFC = ((IFeatureWorkspace)pWorkspace).OpenFeatureClass(sFC); pResultLayer = new FeatureLayer(); ((IFeatureLayer)pResultLayer).FeatureClass = pFC; break; case FileSystemDataset.GISDataStorageTypes.ShapeFile: IFeatureWorkspace pWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(dataset); IFeatureClass pShapeFile = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(dataset.Path.FullName)); pResultLayer = new FeatureLayer(); ((IFeatureLayer)pResultLayer).FeatureClass = pShapeFile; break; case FileSystemDataset.GISDataStorageTypes.TIN: ITin pTIN = ((ITinWorkspace)pWorkspace).OpenTin(System.IO.Path.GetFileName(dataset.Path.FullName)); pResultLayer = new TinLayer(); ((ITinLayer)pResultLayer).Dataset = pTIN; pResultLayer.Name = dataset.Name; break; case FileSystemDataset.GISDataStorageTypes.GeoPackage: IFeatureWorkspace pGPKGWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(dataset); IFeatureClass pGPKGFC = pGPKGWS.OpenFeatureClass(System.IO.Path.GetFileName(dataset.Path.FullName)); pResultLayer = new FeatureLayer(); ((IFeatureLayer)pResultLayer).FeatureClass = pGPKGFC; break; default: Exception ex = new Exception("Unhandled GIS dataset type"); ex.Data["FullPath Path"] = dataset.Path.FullName; ex.Data["Storage Type"] = dataset.WorkspaceType.ToString(); throw ex; } if (!string.IsNullOrEmpty(sLayerName)) { pResultLayer.Name = sLayerName; } try { ApplySymbology(pResultLayer, fiSymbologyLayerFile); } catch (Exception ex) { if (ex.Message.ToLower().Contains("symbology")) { System.Diagnostics.Debug.Print(ex.Message); // DO Nothing } else { throw; } } try { if (pResultLayer is IFeatureLayer && !string.IsNullOrEmpty(definition_query)) { ApplyDefinitionquery((IFeatureLayer)pResultLayer, definition_query); } } catch (Exception ex) { if (ex.Message.ToLower().Contains("symbology")) { System.Diagnostics.Debug.Print(ex.Message); // DO Nothing } else { throw; } } if (transparency > 0) { ILayerEffects pLayerEffects = (ILayerEffects)pResultLayer; pLayerEffects.Transparency = transparency; } if (pGroupLayer == null) { ((IMapLayers)ArcMap.Document.FocusMap).InsertLayer(pResultLayer, false, 0); } else { int layerIndex = 0; foreach (string name in precedingLayers) { // Try and find the preceding layer already in the hierarchy ICompositeLayer pCompositeLayer = (ICompositeLayer)pGroupLayer; for (int i = 0; i <= pCompositeLayer.Count - 1; i++) { if (string.Compare(pCompositeLayer.Layer[i].Name, name, true) == 0) { layerIndex++; } } } ((IMapLayers)ArcMap.Document.FocusMap).InsertLayerInGroup(pGroupLayer, pResultLayer, false, layerIndex); } ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.Refresh(); ArcMap.Document.CurrentContentsView.Refresh(null); return(pResultLayer); }
public static ILayer AddToMap(FileSystemInfo fiFullPath, string sLayerName, IGroupLayer pGroupLayer, FileInfo fiSymbologyLayerFile = null, bool bAddToMapIfPresent = false) { if (!fiFullPath.Exists) { return(null); } // Only add if it doesn't exist already ILayer pResultLayer = GetLayerBySource(fiFullPath); if ((pResultLayer is ILayer && string.Compare(pResultLayer.Name, sLayerName, true) == 0) && !bAddToMapIfPresent) { return(pResultLayer); } // Confirm that the symbology layer file exists if (fiSymbologyLayerFile != null && !fiSymbologyLayerFile.Exists) { Exception ex = new Exception("A symbology layer file was provided, but the file does not exist"); ex.Data["Data Source"] = fiFullPath.FullName; ex.Data["Layer file"] = fiSymbologyLayerFile.FullName; throw ex; } GISDataStorageTypes eStorageType = GetWorkspaceType(fiFullPath.FullName); IWorkspace pWorkspace = GetWorkspace(fiFullPath); switch (eStorageType) { case GISDataStorageTypes.RasterFile: IRasterDataset pRDS = ((IRasterWorkspace)pWorkspace).OpenRasterDataset(fiFullPath.Name); IRasterLayer pRLResult = new RasterLayer(); pRLResult.CreateFromDataset(pRDS); pResultLayer = pRLResult; break; case GISDataStorageTypes.CAD: string sFile = Path.GetFileName(Path.GetDirectoryName(fiFullPath.FullName)); string sFC = sFile + ":" + Path.GetFileName(fiFullPath.FullName); IFeatureClass pFC = ((IFeatureWorkspace)pWorkspace).OpenFeatureClass(sFC); pResultLayer = new FeatureLayer(); ((IFeatureLayer)pResultLayer).FeatureClass = pFC; break; case GISDataStorageTypes.ShapeFile: IFeatureWorkspace pWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(fiFullPath); IFeatureClass pShapeFile = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(fiFullPath.FullName)); pResultLayer = new FeatureLayer(); ((IFeatureLayer)pResultLayer).FeatureClass = pShapeFile; break; case GISDataStorageTypes.TIN: ITin pTIN = ((ITinWorkspace)pWorkspace).OpenTin(fiFullPath.FullName); pResultLayer = new TinLayer(); ((ITinLayer)pResultLayer).Dataset = pTIN; pResultLayer.Name = fiFullPath.Name; break; default: Exception ex = new Exception("Unhandled GIS dataset type"); ex.Data["FullPath Path"] = fiFullPath.FullName; ex.Data["Storage Type"] = eStorageType.ToString(); throw ex; } if (!string.IsNullOrEmpty(sLayerName)) { pResultLayer.Name = sLayerName; } ApplySymbology(pResultLayer, fiSymbologyLayerFile); if (pGroupLayer == null) { ((IMapLayers)ArcMap.Document.FocusMap).InsertLayer(pResultLayer, true, 0); } else { ((IMapLayers)ArcMap.Document.FocusMap).InsertLayerInGroup(pGroupLayer, pResultLayer, true, 0); } ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.Refresh(); ArcMap.Document.CurrentContentsView.Refresh(null); return(pResultLayer); }