private void BuildFileList() { _fileList.Clear(); IFeatureLayer featureLayer = ((CustomLayer)cbo_layers.SelectedItem).FeatureLayer(); IFeatureClass featureClass = ((CustomLayer)cbo_layers.SelectedItem).FeatureClass(); if (rb_all.Checked) { IFeatureCursor cursor = featureClass.Search(null, false); IFields fields = cursor.Fields; int fieldIndex = _utilitiesArcMap.FindField(featureClass, cbo_fieldname.Text); IFeature feature = cursor.NextFeature(); while (feature != null) { //string fileName = Utilities.Utilities_General.AddPrefixAndSuffixToFileName(Convert.ToString(feature.get_Value(fieldIndex)), txb_prefix.Text, txb_suffix.Text); string fileName = Convert.ToString(feature.get_Value(fieldIndex)); if (!_fileList.ContainsKey(fileName)) { _fileList.Add(fileName, false); } feature = cursor.NextFeature(); } } if (rb_selected.Checked) { IFeatureSelection selection = featureLayer as IFeatureSelection; IEnumIDs IDs = selection.SelectionSet.IDs; IDs.Reset(); int oid = IDs.Next(); while (oid != -1) { IFeature feature = featureClass.GetFeature(oid); if (feature != null) { int fieldIndex = _utilitiesArcMap.FindField(featureClass, cbo_fieldname.Text); string fileName = Convert.ToString(feature.get_Value(fieldIndex)); if (!_fileList.ContainsKey(fileName)) { _fileList.Add(fileName, false); } oid = IDs.Next(); } } } }
internal void LoadFile(int X, int Y) { if (CheckRequirments()) { try { ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = (_application.Document as IMxDocument).ActiveView.ScreenDisplay; ESRI.ArcGIS.Geometry.IPoint point = screenDisplay.DisplayTransformation.ToMapPoint(X, Y); ESRI.ArcGIS.Carto.IFeatureLayer tilefeaturelayer = _utilitiesArcMap.FeatureLayer(cboTileIndex.Text); IFeatureClass tilefeatureclass = tilefeaturelayer.FeatureClass; ISpatialFilter spatialfilter = new SpatialFilter(); spatialfilter.GeometryField = tilefeatureclass.ShapeFieldName; spatialfilter.Geometry = point; spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor tilefeaturecursor = tilefeatureclass.Search(spatialfilter, false); IFeature tilefeature = null; while ((tilefeature = tilefeaturecursor.NextFeature()) != null) { object obj = tilefeature.get_Value(_utilitiesArcMap.FindField(tilefeature, this.cboNameField.Text)); if (obj != DBNull.Value) { string tilename = obj.ToString(); LoadFile(txbFileWorkspace.Text + "\\" + tilename + "."); break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void ApplyDomainNull() { if (CheckRequirements()) { try { IFeatureLayer featureLayer = _utilities.FeatureLayer(cboFeatureLayer.Text); IFeatureClass featureClass = featureLayer.FeatureClass; IFeatureSelection featureSelection = featureLayer as IFeatureSelection; IEnumIDs enumIDs = featureSelection.SelectionSet.IDs; int fieldIndex = _utilities.FindField(featureClass, cboField.Text); enumIDs.Reset(); _editor.StartOperation(); int intOID = enumIDs.Next(); while (intOID != -1) { IFeature feature = featureClass.GetFeature(intOID); if (feature != null) { feature.set_Value(fieldIndex, System.DBNull.Value); feature.Store(); } intOID = enumIDs.Next(); } _activeView.Refresh(); _editor.StopOperation("Update Class Type"); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { MessageBox.Show("Shapefiles Don't Accept Null"); } } }
private bool CheckRequirements() { if (!groupCorner.Controls.OfType <RadioButton>().Any(x => x.Checked)) { MessageBox.Show("Select A Corner", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (!groupDirection.Controls.OfType <RadioButton>().Any(x => x.Checked)) { MessageBox.Show("Select A Direction", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } try { if (_utilitiesArcMap == null) { _mxdocument = (IMxDocument)_application.Document; _map = _mxdocument.FocusMap; _activeView = _mxdocument.ActiveView; if (_utilitiesArcMap == null) { _utilitiesArcMap = new Utilities_ArcMap(_map); } } if (this.cbo_FeatureLayers.Items.Count == 0) { MessageBox.Show("Add a layer to inspect to the table of contents", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } IFeatureLayer featureLayer = _utilitiesArcMap.FeatureLayer((cbo_FeatureLayers.Text)); if (featureLayer == null) { MessageBox.Show("Feature Layer Failed To Load", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { MessageBox.Show("Feature Class Failed To Load", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ILayer layer = _utilitiesArcMap.Layer(this.cbo_FeatureLayers.Text); int inspectionfieldindex = _utilitiesArcMap.FindField(layer, "rsi_index"); if (inspectionfieldindex < 0) { MessageBox.Show("Add 'rsi_index' field, short integer!", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } _editor = _utilitiesArcMap.GetEditorFromArcMap(_application as IMxApplication); if (_editor == null) { MessageBox.Show("Editor version of ArcMap required.", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (_editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show("Start an edit session first.", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
private void btnOKNext_Click(object sender, EventArgs e) { if (!CheckRequirements()) { return; } IFeatureLayer buildingslayer = _utilitiesArcMap.FeatureLayer(this.cboBuildingLayer.Text); try { if (buildingslayer != null) { int indexField = _utilitiesArcMap.FindField(buildingslayer, "rsi_index"); int inspectionfieldindex = _utilitiesArcMap.FindField(buildingslayer, "rsi"); IFeatureClass buildingsfeatureclass = buildingslayer.FeatureClass; IFeatureSelection buildingsfeatureselection = buildingslayer as IFeatureSelection; if (buildingsfeatureselection.SelectionSet.Count > 0) { Update(1, buildingslayer); } IFeatureCursor featurecursor = null; IQueryFilter queryfilter = new QueryFilterClass(); queryfilter.WhereClause = "\"rsi\" IS NULL"; if (indexField > -1) { queryfilter.SubFields = "rsi_index"; IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryfilter; queryFilterDef.PostfixClause = "ORDER BY rsi_index"; } featurecursor = buildingsfeatureclass.Search(queryfilter, false); IFeature feature = null; while ((feature = featurecursor.NextFeature()) != null) { IPolygon polygon = feature.Shape as IPolygon; IPolyline polyline = feature.Shape as IPolyline; if ((polygon != null) || (polyline != null)) { buildingsfeatureselection.Clear(); buildingsfeatureselection.Add(feature); buildingsfeatureselection.SelectionChanged(); IEnumGeometry enumgeometry = new EnumFeatureGeometryClass(); IEnumGeometryBind enumgeometrybind = enumgeometry as IEnumGeometryBind; enumgeometrybind.BindGeometrySource(null, buildingsfeatureselection.SelectionSet); IGeometryFactory geometryfactory = new GeometryEnvironmentClass(); IGeometry geometry = geometryfactory.CreateGeometryFromEnumerator(enumgeometry); IEnvelope envelope = geometry.Envelope; double scale = tb_scale.Value / 100.0; envelope.Expand(scale, scale, true); _activeView.Extent = envelope; _activeView.Refresh(); GetStatus(); return; } IPoint point = feature.Shape as IPoint; if (point != null) { buildingsfeatureselection.Clear(); buildingsfeatureselection.Add(feature); buildingsfeatureselection.SelectionChanged(); IEnvelope envelope = _activeView.Extent; envelope.CenterAt(point); _activeView.Extent = envelope; double scale = tb_scale.Value; _map.MapScale = scale; _activeView.Refresh(); GetStatus(); return; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { //_restartreport = false; } }
private bool CheckRequirments() { if (String.IsNullOrEmpty(cbo_TileIndex.Text)) { Utilities_MessageBox.ErrorBox("Initialize Tool Settings", MB_TITLE); return(false); } if (String.IsNullOrEmpty(cbo_FieldName.Text)) { Utilities_MessageBox.ErrorBox("Select Field", MB_TITLE); return(false); } if (String.IsNullOrEmpty(txb_FileWorkspace.Text)) { Utilities_MessageBox.ErrorBox("Select File Workspace", MB_TITLE); return(false); } try { IFeatureLayer featureLayer = _utilitiesArcMap.FeatureLayer(cbo_TileIndex.Text); if (featureLayer == null) { return(false); } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return(false); } IFields fields = featureClass.Fields; if (!(_utilitiesArcMap.FindField(featureClass, cbo_FieldName.Text) > -1)) { return(false); } if (rb_selected.Checked == false && rb_all.Checked == false) { Utilities_MessageBox.ErrorBox("Select A File Loading Method", MB_TITLE); return(false); } // If selected file loading method check if anything is selected if (rb_selected.Checked) { IFeatureSelection featureSelection = featureLayer as IFeatureSelection; if (featureSelection.SelectionSet.Count == 0) { Utilities_MessageBox.ErrorBox("Select At Least One Feature", MB_TITLE); return(false); } } if (!Directory.Exists(txb_FileWorkspace.Text)) { Utilities_MessageBox.ErrorBox("File Workspace Is Invalid", MB_TITLE); return(false); } return(true); } catch (Exception ex) { Utilities_MessageBox.ErrorBox(ex.Message, MB_TITLE); } return(false); }