public void OnGISBrowseVector(System.Windows.Forms.TextBox txt, naru.ui.PathEventArgs e, GCDConsoleLib.GDalGeometryType.SimpleTypes geometryType) { System.IO.DirectoryInfo dir = null; string FCName = string.Empty; if (e.Path is System.IO.FileInfo) { dir = e.Path.Directory; FCName = System.IO.Path.GetFileNameWithoutExtension(e.Path.FullName); } ArcMapBrowse.BrowseGISTypes eType = ArcMapBrowse.BrowseGISTypes.Any; switch (geometryType) { case GCDConsoleLib.GDalGeometryType.SimpleTypes.Point: eType = ArcMapBrowse.BrowseGISTypes.Point; break; case GCDConsoleLib.GDalGeometryType.SimpleTypes.LineString: eType = ArcMapBrowse.BrowseGISTypes.Line; break; case GCDConsoleLib.GDalGeometryType.SimpleTypes.Polygon: eType = ArcMapBrowse.BrowseGISTypes.Polygon; break; } GCDConsoleLib.Vector result = ArcMapBrowse.BrowseOpenVector(e.FormTitle, dir, FCName, eType, e.hWndParent); if (result is GCDConsoleLib.Vector) { txt.Text = result.GISFileInfo.FullName; } }
private void InputShapeFileChanged(object sender, naru.ui.PathEventArgs e) { Cursor = Cursors.WaitCursor; GCDConsoleLib.Vector shapeFile = ucPolygon.SelectedItem; // Use the ShapeFile file name if the user hasn't specified one yet if (string.IsNullOrEmpty(txtName.Text)) { txtName.Text = Path.GetFileNameWithoutExtension(shapeFile.GISFileInfo.FullName); } Cursor = Cursors.Default; cmdOK.Select(); }
public static GCDConsoleLib.Vector BrowseOpenVector(string formTitle, System.IO.DirectoryInfo diWorkspace, string sFCName, BrowseGISTypes eType, IntPtr hParentWindowHandle) { IGxDialog pGxDialog = new GxDialogClass(); IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog; switch (eType) { case BrowseGISTypes.Point: pFilterCol.AddFilter(new GxFilterPointFeatureClasses(), true); break; case BrowseGISTypes.Line: pFilterCol.AddFilter(new GxFilterPolylineFeatureClasses(), true); break; case BrowseGISTypes.Polygon: pFilterCol.AddFilter(new GxFilterPolygonFeatureClasses(), true); break; default: pFilterCol.AddFilter(new GxFilterFeatureClasses(), true); break; } IEnumGxObject pEnumGx = null; IGxObject pGxObject = null; pGxDialog.RememberLocation = true; pGxDialog.AllowMultiSelect = false; pGxDialog.Title = formTitle; pGxDialog.ButtonCaption = "Select"; if (diWorkspace != null && diWorkspace.Exists) { object existingDirectory = diWorkspace.FullName; pGxDialog.set_StartingLocation(ref existingDirectory); } pGxDialog.Name = sFCName; GCDConsoleLib.Vector gResult = null; try { if (pGxDialog.DoModalOpen(hParentWindowHandle.ToInt32(), out pEnumGx)) { pGxObject = pEnumGx.Next(); sFCName = pGxObject.BaseName; gResult = new GCDConsoleLib.Vector(new System.IO.FileInfo(pGxObject.FullName)); } } catch (Exception ex) { throw new Exception("Error attempting to browse for vector GIS data source", ex); } return(gResult); }
private void InputShapeFileChanged(object sender, naru.ui.PathEventArgs e) { if (ucPolyline.SelectedItem == null) { return; } Cursor = Cursors.WaitCursor; GCDConsoleLib.Vector shapeFile = ucPolyline.SelectedItem; // Use the ShapeFile file name if the user hasn't specified one yet if (string.IsNullOrEmpty(txtName.Text)) { txtName.Text = naru.os.File.RemoveDangerousCharacters(System.IO.Path.GetFileNameWithoutExtension(shapeFile.GISFileInfo.FullName)); } cboLabel.DataSource = shapeFile.Fields.Values.Where(x => x.Type.Equals(GCDConsoleLib.GDalFieldType.StringField)).ToList <GCDConsoleLib.VectorField>(); List <GCDConsoleLib.VectorField> distanceFields = shapeFile.Fields.Values.Where(x => x.Type.Equals(GCDConsoleLib.GDalFieldType.RealField)).ToList <GCDConsoleLib.VectorField>(); cboDistance.DataSource = distanceFields; // Help the user by finding default distance field try { string[] defaults = { "Distance", "Station" }; foreach (string strField in defaults) { if (distanceFields.Any(x => string.Compare(x.Name, strField, true) == 0)) { cboDistance.SelectedIndex = distanceFields.IndexOf(distanceFields.First(x => string.Compare(x.Name, strField, true) == 0)); break; } } } catch (Exception ex) { Console.WriteLine("Error attempting to auto-select the profile route distance field: " + ex.Message); } Cursor = Cursors.Default; }
private void InputShapeFileChanged(object sender, naru.ui.PathEventArgs e) { cboField.DataSource = null; if (ucPolygon.SelectedItem == null) { return; } Cursor = Cursors.WaitCursor; GCDConsoleLib.Vector shapeFile = ucPolygon.SelectedItem; // Use the ShapeFile file name if the user hasn't specified one yet if (string.IsNullOrEmpty(txtName.Text)) { txtName.Text = Path.GetFileNameWithoutExtension(shapeFile.GISFileInfo.FullName); } cboField.DataSource = shapeFile.Fields.Values.Where(x => x.Type.Equals(GCDConsoleLib.GDalFieldType.StringField)).ToList <GCDConsoleLib.VectorField>(); Cursor = Cursors.Default; }
public static bool ValidateShapeFile(GCDCore.UserInterface.UtilityForms.ucVectorInput ucInput) { if (!(ucInput.SelectedItem is GCDConsoleLib.Vector)) { MessageBox.Show("You must choose a mask ShapeFile to continue.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); ucInput.Select(); return(false); } // Should be safe after Validate call above GCDConsoleLib.Vector shp = ucInput.SelectedItem; // Validate that hte user actually chose a POLYGON ShapeFile if (shp.GeometryType.SimpleType != GCDConsoleLib.GDalGeometryType.SimpleTypes.Polygon) { MessageBox.Show(string.Format("The selected ShapeFile appears to be of {0} geometry type. Only polygon ShapeFiles can be used as masks.", shp.GeometryType.SimpleType), "Invalid Geometry Type", MessageBoxButtons.OK, MessageBoxIcon.Information); ucInput.Select(); return(false); } return(true); }
private bool ValidateForm() { // Sanity check to prevent empty names txtName.Text = txtName.Text.Trim(); if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("You must provide a name for the profile route.", "Missing Name", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } if (!ProjectManager.Project.IsProfileRouteNameUnique(txtName.Text, ProfileRoute)) { MessageBox.Show("This project already contains a mask with this name. Please choose a unique name.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Select(); return(false); } if (ProfileRoute == null) { if (!(ucPolyline.SelectedItem is GCDConsoleLib.Vector)) { MessageBox.Show("You must choose a ShapeFile to continue.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); ucPolyline.Select(); return(false); } // Should be safe after Validate call above GCDConsoleLib.Vector shp = ucPolyline.SelectedItem; // Validate that hte user actually chose a POLYGON ShapeFile if (shp.GeometryType.SimpleType != GCDConsoleLib.GDalGeometryType.SimpleTypes.LineString) { MessageBox.Show(string.Format("The selected ShapeFile appears to be of {0} geometry type. Only polyline ShapeFiles can be used as profile routes.", shp.GeometryType.SimpleType), "Invalid Geometry Type", MessageBoxButtons.OK, MessageBoxIcon.Information); ucPolyline.Select(); return(false); } if (!UserInterface.SurveyLibrary.GISDatasetValidation.DSHasSpatialRef(ucPolyline.SelectedItem, "feature class", "feature classes") || !UserInterface.SurveyLibrary.GISDatasetValidation.DSHorizUnitsMatchProject(ucPolyline.SelectedItem, "feature class", "feature classes")) { ucPolyline.Select(); return(false); } if (!SurveyLibrary.GISDatasetValidation.DSSpatialRefMatchesProject(ucPolyline.SelectedItem)) { string msg = string.Format( "{0}{1}{0}If you believe that these projections are the same (or equivalent) choose \"Yes\" to continue anyway. Otherwise choose \"No\" to abort.", Environment.NewLine, SurveyLibrary.GISDatasetValidation.SpatialRefNoMatchString(ucPolyline.SelectedItem, "raster", "rasters")); DialogResult result = MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result == DialogResult.No) { ucPolyline.Select(); return(false); } } return(true); } if (cboDistance.SelectedIndex < 0) { MessageBox.Show("You must select a floating point field in the ShapeFile that provides distance values or uncheck the distance checkbox.", "Missing Distance Field", MessageBoxButtons.OK, MessageBoxIcon.Information); cboDistance.Select(); return(false); } if (chkLabel.Checked) { if (cboLabel.SelectedIndex < 0) { MessageBox.Show("You must select a text field in the ShapeFile that provides profile route labels or uncheck the label checkbox.", "Missing Label Field", MessageBoxButtons.OK, MessageBoxIcon.Information); cboLabel.Select(); return(false); } } if (ucPolyline == null) { if (ucPolyline.SelectedItem.Features.Values.Any(x => x.IsNull(cboDistance.Text))) { MessageBox.Show(string.Format("One or more features in the ShapeFile have null or invalid values in the {0} field. A valid distance field must possess valid floating point values for all features.", cboDistance.Text), "Invalid Distance Values", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } } return(true); }
public void InitializeExisting(string sNoun, GCDConsoleLib.Vector vector) { base.InitializeExisting(sNoun, vector.GISFileInfo, ProjectManager.Project.GetRelativePath(vector.GISFileInfo)); GeometryType = vector.GeometryType.SimpleType; }