private bool LoopLayerEditing(ICompositeLayer layer) { bool rbc = false; ICompositeLayer cplayer = layer as ICompositeLayer; ILayer tmplayer = null; for (int j = 0; j < cplayer.Count; j++) { tmplayer = cplayer.get_Layer(j); if (tmplayer is ICompositeLayer) { rbc = LoopLayerEditing(tmplayer as ICompositeLayer); } else if (tmplayer is IFeatureLayer && (tmplayer as IFeatureLayer).FeatureClass != null) { IDatasetEdit dsEdit = (tmplayer as IFeatureLayer).FeatureClass as IDatasetEdit; rbc = dsEdit.IsBeingEdited(); } if (rbc == true) { break; } } return(rbc); }
/// <summary> /// Handles the Click event of the buttonCalculate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void buttonCalculate_Click(object sender, EventArgs e) { IFeatureClass featureClass = this.FeatureLayer.FeatureClass; IDataset dataset = (IDataset)featureClass; IDatasetEdit datasetEdit = (IDatasetEdit)dataset; bool versionedWorkspace = false; IWorkspace workspace = dataset.Workspace; if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { IVersionedObject versionedObject = (IVersionedObject)dataset; versionedWorkspace = versionedObject.IsRegisteredAsVersioned; } IEditor editor = (IEditor)this.ArcMapApplication.FindExtensionByName("ESRI Object Editor"); if (versionedWorkspace && editor.EditState.Equals(esriEditState.esriStateNotEditing)) { MessageBox.Show("You must be in an edit session when editing versioned feature classes.", "Geohash Calculator", MessageBoxButtons.OK); } else if (versionedWorkspace && editor.EditState.Equals(esriEditState.esriStateEditing) && !datasetEdit.IsBeingEdited()) { MessageBox.Show("You must be editing the same workspace as the highlighted layer.", "Geohash Calculator", MessageBoxButtons.OK); } else { Stack <int> objectIDs = this.GetObjectIds(); if (objectIDs.Count > 0) { int fieldIndex = featureClass.FindField(comboBoxFields.Text); if (fieldIndex > -1) { int c = 0; foreach (int objectID in objectIDs) { c++; toolStripStatusLabel.Text = "Calculating " + c.ToString() + " of " + objectIDs.Count.ToString() + " features."; statusStrip.Refresh(); IFeature feature = featureClass.GetFeature(objectID); IGeometry geometry = (IGeometry)feature.Shape; string currentGeohashValue = "<Null>"; if (!System.DBNull.Value.Equals(feature.get_Value(fieldIndex))) { currentGeohashValue = feature.get_Value(fieldIndex).ToString(); } if (geometry is IPoint) { IPoint point = (IPoint)geometry; string geohash = Umbriel.ArcMap.Editor.Util.Geohasher.CreateGeohash(point, 13); if (!currentGeohashValue.Equals(geohash)) { if (versionedWorkspace) { editor.StartOperation(); } feature.set_Value(fieldIndex, geohash); feature.Store(); if (versionedWorkspace) { editor.StopOperation("Update Geohash Field."); } } else { toolStripStatusLabel.Text = "-- Same geohash. No Update Required --"; this.statusStrip.Refresh(); } } Application.DoEvents(); if (this.CancelCalculation) { break; } } if (this.CancelCalculation) { toolStripStatusLabel.Text = "-- Calculation Halted --"; } else { toolStripStatusLabel.Text = "-- Calculate Finished --"; } } } else { MessageBox.Show("There are no features to calculate.", "Geohash Calculator", MessageBoxButtons.OK); } } }
public bool isFeatureClassEdit(IFeatureClass pFeatureClass) { IDatasetEdit pDataEdit = pFeatureClass as IDatasetEdit; return(pDataEdit.IsBeingEdited()); }