/// <summary> /// Determine the location of the layer file for this GIS item /// </summary> /// <remarks> /// The following locations will be searched in order for a /// file with the name SYMBOLOGY_KEY.lyr /// /// 1. ProjectFolder /// 2. %APPDATA%\RAVE\Symbology\esri\MODEL /// 3. %APPDATA%\RAVE\Symbology\esrsi\Shared /// 4. SOFTWARE_DEPLOYMENT\Symbology\esri\MODEL /// 5. SOFTWARE_DEPLOYMENT\Symbology\esri\Shared /// /// </remarks> private FileInfo GetSymbology(GISDataset layer) { if (string.IsNullOrEmpty(layer.SymbologyKey)) { return(null); } string appDataFolder = Path.Combine(ucProjectExplorer.AppDataFolder.FullName, Properties.Resources.AppDataSymbologyFolder); string deployFolder = Path.Combine(ucProjectExplorer.DeployFolder.FullName, Properties.Resources.AppDataSymbologyFolder); List <string> SearchFolders = new List <string>() { layer.Project.Folder.FullName, Path.Combine(appDataFolder, layer.Project.ProjectType), Path.Combine(appDataFolder, Properties.Resources.AppDataSymbologySharedFolder), Path.Combine(deployFolder, layer.Project.ProjectType), Path.Combine(deployFolder, Properties.Resources.AppDataSymbologySharedFolder), }; foreach (string folder in SearchFolders) { if (Directory.Exists(folder)) { string path = Path.ChangeExtension(Path.Combine(folder, layer.SymbologyKey), "lyr"); if (File.Exists(path)) { return(new FileInfo(path)); } } } return(null); }
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; } }
/// <summary> /// Validate that the dataset spatial reference matches that of the project /// </summary> /// <param name="gisDS"></param> /// <returns></returns> public static bool DSSpatialRefMatchesProject(GISDataset gisDS) { Projection referenceProjection = GetProjectProjection(); if (referenceProjection != null && !referenceProjection.IsSame(gisDS.Proj)) { return(false); } return(true); }
/// <summary> /// Just a helper to build us a string for when we ask the user if we want to override the projection (force or reproject) /// </summary> /// <param name="gisDS"></param> /// <param name="sTypeSingle"></param> /// <param name="sTypePlural"></param> /// <returns></returns> public static string SpatialRefNoMatchString(GISDataset gisDS, string sTypeSingle, string sTypePlural) { Projection referenceProjection = GetProjectProjection(); string msg = string.Format("The coordinate system of the selected {1}:{0}{0}{2}{0}{0} does not match that of the GCD project:{0}{0}{3}{0}{0}" + "All {4} within a GCD project must have the identical coordinate system. However, small discrepencies in coordinate system names might cause" + "the two coordinate systems to appear different.", Environment.NewLine, sTypeSingle, gisDS.Proj.PrettyWkt, referenceProjection.PrettyWkt, sTypePlural); return(msg); }
/// <summary> /// This is the non-optional projection check. This does the function above but then only gives a warning, not a yes/no chooser /// /// IN THEORY THIS SHOULD NEVER TRIGGER SINCE WE'RE SO CAREFUL NOT TO IMPORT ANY BAD PROJECTIONS /// </summary> /// <param name="gisDS"></param> /// <returns></returns> public static bool DSSpatialRefMatchesProjectWithMsgbox(GISDataset gisDS, string sTypeSingle, string sTypePlural) { if (DSSpatialRefMatchesProject(gisDS)) { string msg = string.Format( "{0}{1}{0} Projections must match exactly.", Environment.NewLine, GISDatasetValidation.SpatialRefNoMatchString(gisDS, sTypeSingle, sTypePlural)); MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }
public void OnGISSource(object sender, EventArgs e) { try { TreeNode selNode = treProject.SelectedNode; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(selNode); GISDataset layer = (GISDataset)selNode.Tag; if (layer.HasWarehouseRefernce) { System.Diagnostics.Process.Start(layer.WarehouseReference.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Determining Source Project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Verify that the horizontal units match those of the project. /// </summary> /// <param name="gisDS"></param> /// <param name="sTypeSingle"></param> /// <param name="sTypePlural"></param> /// <returns></returns> public static bool DSHorizUnitsMatchProject(GISDataset gisDS, string sTypeSingle, string sTypePlural) { if (ProjectManager.Project.Units.HorizUnit != gisDS.Proj.HorizontalUnit) { string msg = string.Format("The horizontal units of the {0} ({1}) do not match those of the GCD project ({2}).", sTypeSingle, gisDS.Proj.HorizontalUnit.ToString(), ProjectManager.Project.Units.HorizUnit.ToString()); if (ProjectManager.Project.DEMSurveys.Count < 1) { msg += " You can change the GCD project horizontal units by canceling this form and opening the GCD project properties form."; } msg += " Choose \"Yes\" to continue anyway. Otherwise choose \"No\" to abort."; DialogResult result = MessageBox.Show(msg, "HorizontalUnits Mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result == DialogResult.No) { return(false); } } return(true); }
public void OnGISMetadata(object sender, EventArgs e) { try { TreeNode selNode = treProject.SelectedNode; IGroupLayer parentGrpLyr = BuildArcMapGroupLayers(selNode); GISDataset layer = (GISDataset)selNode.Tag; if (layer.Metadata != null && layer.Metadata.Count > 0) { MetaData.frmMetaData frm = new MetaData.frmMetaData(string.Format("{0} Layer", layer.Name), layer.Metadata); frm.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Viewing Layer Metadata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Validate that the dataset has a spatial reference /// </summary> /// <param name="gisDS"></param> /// <param name="sTypeSingle"></param> /// <param name="sTypePlural"></param> /// <returns></returns> public static bool DSHasSpatialRef(GISDataset gisDS, string sTypeSingle, string sTypePlural) { if (gisDS.Proj.PrettyWkt.ToLower().Contains("unknown")) { string msg = string.Format("The selected {0} appears to be missing a spatial reference. All GCD {0} must possess a spatial reference and it must be the same spatial reference for all GIS datasets in a GCD project.", sTypeSingle); Projection referenceProjection = GetProjectProjection(); if (referenceProjection != null) { msg += string.Format(" If the selected {0} exists in the GCD project coordinate system ({1}), but the coordinate system has not yet been defined for the {0}, then" + " use the ArcToolbox 'Define Projection' geoprocessing tool in the 'Data Management -> Projection & Transformations' Toolbox to correct the problem with the selected {0} by defining the coordinate system as:" + "{2}{2}{1}{2}{2}Then try importing it into the GCD again.", sTypeSingle, referenceProjection.PrettyWkt, Environment.NewLine); } MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
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; } }