private void UpdatePolygons(string oldMapUnitName, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit theNewDmuEntry) { // Find polygons that use the old MapUnit MapUnitPolysAccess polysFinder = new MapUnitPolysAccess(m_theWorkspace); polysFinder.AddMapUnitPolys("MapUnit = '" + oldMapUnitName + "'"); try { // A second poly access class to do the updating MapUnitPolysAccess polysUpdater = new MapUnitPolysAccess(m_theWorkspace); // Loop through them and update foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> anEntry in polysFinder.MapUnitPolysDictionary) { // Get the Polygon polysUpdater.AddMapUnitPolys("MapUnitPolys_ID = '" + anEntry.Value.MapUnitPolys_ID + "'"); MapUnitPolysAccess.MapUnitPoly aPoly = polysUpdater.MapUnitPolysDictionary[anEntry.Value.MapUnitPolys_ID]; // Set new values aPoly.MapUnit = theNewDmuEntry.MapUnit; aPoly.Label = theNewDmuEntry.Label; // Update it polysUpdater.UpdateMapUnitPoly(aPoly); } // Save changes polysUpdater.SaveMapUnitPolys(); // Refresh the Active View IFeatureLayer mapUnitPolysLayer = commonFunctions.FindFeatureLayer(m_theWorkspace, "MapUnitPolys"); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, mapUnitPolysLayer, null); } catch (Exception err) { MessageBox.Show(err.Message); } }
private void assignMapUnit(ISelectionSet theSelection, IFeatureLayer mapUnitPolysLayer, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit dmuEntry) { // Pass the selected features into a cursor that we can iterate through ICursor theCursor; theSelection.Search(null, false, out theCursor); string mupIdField = mapUnitPolysLayer.DisplayField; int IdFld = theCursor.FindField(mupIdField); // Build the Where Clause to get these features by looping through the cursor string sqlWhereClause = mupIdField + " = '"; IRow theRow = theCursor.NextRow(); while (theRow != null) { sqlWhereClause += theRow.get_Value(IdFld) + "' OR " + mupIdField + " = '"; theRow = theCursor.NextRow(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(theCursor); // If we didn't add anything to the where clause, bail if (sqlWhereClause == mupIdField + " = '") { return; } // Cleanup the where clause sqlWhereClause = sqlWhereClause.Remove(sqlWhereClause.Length - (" OR " + mupIdField + " = '").Length); // Get the MapUnitPolys MapUnitPolysAccess polysAccess = new MapUnitPolysAccess(m_theWorkspace, mapUnitPolysLayer.Name); polysAccess.AddMapUnitPolys(sqlWhereClause); //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Data Access Issue: I actually have to pass the dictionary into another object. // If I don't, once the first record is updated, the dictionary is changed. // Then the foreach loop fails, because what it is looping through was adjusted. // Not very happy with this. //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Sort using Linq syntax var sortedPolys = ( from entry in polysAccess.MapUnitPolysDictionary select entry); MapUnitPolysAccess secondPolysAccess = new MapUnitPolysAccess(m_theWorkspace, mapUnitPolysLayer.Name); try { // Cycle through the MapUnitPolys and update the MapUnit and Label attributes foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> anEntry in sortedPolys) { // Get the MapUnitPoly object secondPolysAccess.AddMapUnitPolys(mupIdField + " = '" + anEntry.Value.MapUnitPolys_ID + "'"); MapUnitPolysAccess.MapUnitPoly aPoly = secondPolysAccess.MapUnitPolysDictionary[anEntry.Value.MapUnitPolys_ID]; // Change the appropriate values aPoly.MapUnit = dmuEntry.MapUnit; aPoly.Label = dmuEntry.Label; // Update the Poly secondPolysAccess.UpdateMapUnitPoly(aPoly); } } catch (Exception err) { MessageBox.Show(err.Message); } // Save updates secondPolysAccess.SaveMapUnitPolys(); // Update the active view ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, mapUnitPolysLayer, null); }
private void ApplyFeatureTemplates() { // Get a reference to the selected FeatureTemplate IEditor3 templateEditor = ArcMap.Editor as IEditor3; IEditTemplate theCurrentTemplate = templateEditor.CurrentTemplate; // If they didn't select a template, they'll need to if (theCurrentTemplate == null) { MessageBox.Show("No FeatureTemplate was selected.", "NCGMP Tools"); return; } // Find out what FeatureClass the selected template belongs to, and what its geometry is IFeatureClass templateFC = ((IFeatureLayer)theCurrentTemplate.Layer).FeatureClass; switch (templateFC.ShapeType) { case esriGeometryType.esriGeometryPolyline: // Look for feature selected in line FeatureClasses #region ContactsAndFaults IFeatureLayer contactsAndFaultsFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "ContactsAndFaults"); if (contactsAndFaultsFL != null) { // Found ContactsAndFaults. Check for a selection IFeatureSelection selectedFeatures = contactsAndFaultsFL as IFeatureSelection; if (selectedFeatures.SelectionSet.Count > 0) { // ContactsAndFaults were selected. Pass the selection into a cursor. ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet; ICursor theCursor; featureSelectionSet.Search(null, false, out theCursor); IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor; // Some variables to declare before the loops int idFld = theFeatureCursor.FindField("ContactsAndFaults_ID"); IFeature theFeature; string thisId; // Construct a dummy feature to get attributes from IFeature dummyFeature = templateFC.CreateFeature(); theCurrentTemplate.SetDefaultValues(dummyFeature); string ExistenceConfidence = dummyFeature.get_Value(templateFC.FindField("ExistenceConfidence")).ToString(); string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString(); string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString(); double LocationConfidenceMeters; bool result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("LocationConfidenceMeters")).ToString(), out LocationConfidenceMeters); string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString(); string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(); string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString(); int IsConcealed = 0; if (contactsAndFaultsFL.FeatureClass.Equals(templateFC) == true) { result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("IsConcealed")).ToString(), out IsConcealed); } // Destroy the dummy feature - must happen within an edit operation ArcMap.Editor.StartOperation(); dummyFeature.Delete(); ArcMap.Editor.StopOperation("Remove Dummy Feature"); //Is the FeatureTemplate also for ContactsAndFaults? switch (contactsAndFaultsFL.FeatureClass.Equals(templateFC)) { case true: // Update the features to the FeatureTemplate ContactsAndFaultsAccess ContactsAndFaultsUpdater = new ContactsAndFaultsAccess(m_theWorkspace); theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the ContactsAndFaults feature to update thisId = theFeature.get_Value(idFld).ToString(); ContactsAndFaultsUpdater.AddContactsAndFaults("ContactsAndFaults_ID = '" + thisId + "'"); ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = ContactsAndFaultsUpdater.ContactsAndFaultsDictionary[thisId]; // Assign values from the FeatureTemplate thisContactsAndFault.ExistenceConfidence = ExistenceConfidence; thisContactsAndFault.IdentityConfidence = IdentityConfidence; thisContactsAndFault.Label = Label; thisContactsAndFault.LocationConfidenceMeters = LocationConfidenceMeters; thisContactsAndFault.Notes = Notes; thisContactsAndFault.Symbol = Symbol; thisContactsAndFault.Type = Type; thisContactsAndFault.IsConcealed = IsConcealed; // Update the feature ContactsAndFaultsUpdater.UpdateContactsAndFault(thisContactsAndFault); // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } // Save changes ContactsAndFaultsUpdater.SaveContactsAndFaults(); break; case false: // Copy the features into the templateFC using the selected template as a guide // Build DataAccess Classes for target FeatureClasses OtherLinesAccess OtherLinesInserter = new OtherLinesAccess(m_theWorkspace); // Find the target FeatureClass Name string tableName = (templateFC as IDataset).Name; // Parse the table name in order to strip out unneccessary bits of SDE tables ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace; string parsedDbName, parsedOwnerName, parsedTableName; nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName); // Will need to remove the selected feature from ContactsAndFaults ContactsAndFaultsAccess ContactsAndFaultsRemover = new ContactsAndFaultsAccess(m_theWorkspace); // Loop through the selected ContactsAndFaults theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the ContactsAndFaults feature to remove thisId = theFeature.get_Value(idFld).ToString(); ContactsAndFaultsRemover.AddContactsAndFaults("ContactsAndFaults_ID = '" + thisId + "'"); ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = ContactsAndFaultsRemover.ContactsAndFaultsDictionary[thisId]; // Setup attributes string DataSourceID = thisContactsAndFault.DataSourceID; IPolyline Shape = thisContactsAndFault.Shape; // Create the new feature in the template FeatureClass switch (parsedTableName) { case "OtherLines": // Insert the new OtherLines OtherLinesInserter.NewOtherLine(Type, LocationConfidenceMeters, ExistenceConfidence, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape); OtherLinesInserter.SaveOtherLines(); // Clear out the dictionary so lines don't get added more than once. OtherLinesInserter.ClearOtherLines(); // Delete the old one ContactsAndFaultsRemover.DeleteContactsAndFaults(thisContactsAndFault); break; default: // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully. break; } // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } break; } } } #endregion #region OtherLines IFeatureLayer OtherLinesFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OtherLines"); if (OtherLinesFL != null) { // Found OtherLines. Check for a selection IFeatureSelection selectedFeatures = OtherLinesFL as IFeatureSelection; if (selectedFeatures.SelectionSet.Count > 0) { // OtherLines were selected. Pass the selection into a cursor. ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet; ICursor theCursor; featureSelectionSet.Search(null, false, out theCursor); IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor; // Some variables to declare before the loops int idFld = theFeatureCursor.FindField("OtherLines_ID"); IFeature theFeature; string thisId; // Construct a dummy feature to get attributes from IFeature dummyFeature = templateFC.CreateFeature(); theCurrentTemplate.SetDefaultValues(dummyFeature); string ExistenceConfidence = dummyFeature.get_Value(templateFC.FindField("ExistenceConfidence")).ToString(); string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString(); string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString(); double LocationConfidenceMeters; bool result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("LocationConfidenceMeters")).ToString(), out LocationConfidenceMeters); string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString(); string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(); string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString(); int IsConcealed = 0; if (templateFC.Equals(commonFunctions.OpenFeatureClass(m_theWorkspace, "ContactsAndFaults")) == true) { result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("IsConcealed")).ToString(), out IsConcealed); } // Destroy the dummy feature - must happen within an edit operation ArcMap.Editor.StartOperation(); dummyFeature.Delete(); ArcMap.Editor.StopOperation("Remove Dummy Feature"); //Is the FeatureTemplate also for OtherLines? switch (OtherLinesFL.FeatureClass.Equals(templateFC)) { case true: // Update the features to the FeatureTemplate OtherLinesAccess OtherLinesUpdater = new OtherLinesAccess(m_theWorkspace); theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the OtherLines feature to update thisId = theFeature.get_Value(idFld).ToString(); OtherLinesUpdater.AddOtherLines("OtherLines_ID = '" + thisId + "'"); OtherLinesAccess.OtherLine thisOtherLine = OtherLinesUpdater.OtherLinesDictionary[thisId]; // Assign values from the FeatureTemplate thisOtherLine.ExistenceConfidence = ExistenceConfidence; thisOtherLine.IdentityConfidence = IdentityConfidence; thisOtherLine.Label = Label; thisOtherLine.LocationConfidenceMeters = LocationConfidenceMeters; thisOtherLine.Notes = Notes; thisOtherLine.Symbol = Symbol; thisOtherLine.Type = Type; // Update the feature OtherLinesUpdater.UpdateOtherLine(thisOtherLine); // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } // Save changes OtherLinesUpdater.SaveOtherLines(); break; case false: // Copy the features into the templateFC using the selected template as a guide // Build DataAccess Classes for target FeatureClasses ContactsAndFaultsAccess ContactsAndFaultsInserter = new ContactsAndFaultsAccess(m_theWorkspace); // Find the target FeatureClass Name string tableName = (templateFC as IDataset).Name; // Parse the table name in order to strip out unneccessary bits of SDE tables ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace; string parsedDbName, parsedOwnerName, parsedTableName; nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName); // Will need to remove the selected feature from OtherLines OtherLinesAccess OtherLinesRemover = new OtherLinesAccess(m_theWorkspace); // Loop through the selected OtherLines theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the OtherLines feature to remove thisId = theFeature.get_Value(idFld).ToString(); OtherLinesRemover.AddOtherLines("OtherLines_ID = '" + thisId + "'"); OtherLinesAccess.OtherLine thisOtherLine = OtherLinesRemover.OtherLinesDictionary[thisId]; // Setup attributes string DataSourceID = thisOtherLine.DataSourceID; IPolyline Shape = thisOtherLine.Shape; // Create the new feature in the template FeatureClass switch (parsedTableName) { case "ContactsAndFaults": // Insert the new OtherLines ContactsAndFaultsInserter.NewContactsAndFault(Type, IsConcealed, LocationConfidenceMeters, ExistenceConfidence, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape); ContactsAndFaultsInserter.SaveContactsAndFaults(); // Clear out the dictionary so lines don't get added more than once. ContactsAndFaultsInserter.ClearContactsAndFaults(); // Delete the old one OtherLinesRemover.DeleteOtherLines(thisOtherLine); break; default: // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully. break; } // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } break; } } } #endregion break; case esriGeometryType.esriGeometryPoint: // Look for features selected in point FeatureClasses // Note: I don't care about FeatureTemplates in Station or Sample featureclasses. #region OrientationDataPoints IFeatureLayer OrientationDataPointsFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OrientationDataPoints"); if (OrientationDataPointsFL != null) { // Found OrientationDataPoints. Check for a selection IFeatureSelection selectedFeatures = OrientationDataPointsFL as IFeatureSelection; if (selectedFeatures.SelectionSet.Count > 0) { // OrientationDataPoints were selected. Pass the selection into a cursor. ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet; ICursor theCursor; featureSelectionSet.Search(null, false, out theCursor); IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor; // Some variables to declare before the loops int idFld = theFeatureCursor.FindField("OrientationDataPoints_ID"); IFeature theFeature; string thisId; // Construct a dummy feature to get attributes from IFeature dummyFeature = templateFC.CreateFeature(); theCurrentTemplate.SetDefaultValues(dummyFeature); string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString(); string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString(); string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString(); int PlotAtScale; bool result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("PlotAtScale")).ToString(), out PlotAtScale); double OrientationConfidenceDegrees; result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("OrientationConfidenceDegrees")).ToString(), out OrientationConfidenceDegrees); string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString(); int Symbol; result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(), out Symbol); // Destroy the dummy feature - must happen within an edit operation ArcMap.Editor.StartOperation(); dummyFeature.Delete(); ArcMap.Editor.StopOperation("Remove Dummy Feature"); //Is the FeatureTemplate also for OrientationDataPoints? switch (OrientationDataPointsFL.FeatureClass.Equals(templateFC)) { case true: // Update the features to the FeatureTemplate OrientationDataPointsAccess OrientationDataPointsUpdater = new OrientationDataPointsAccess(m_theWorkspace); theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the OrientationDataPoints feature to update thisId = theFeature.get_Value(idFld).ToString(); OrientationDataPointsUpdater.AddOrientationDataPoints("OrientationDataPoints_ID = '" + thisId + "'"); OrientationDataPointsAccess.OrientationDataPoint thisOrientationDataPoint = OrientationDataPointsUpdater.OrientationDataPointsDictionary[thisId]; // Assign values from the FeatureTemplate thisOrientationDataPoint.Type = Type; thisOrientationDataPoint.IdentityConfidence = IdentityConfidence; thisOrientationDataPoint.Label = Label; thisOrientationDataPoint.PlotAtScale = PlotAtScale; thisOrientationDataPoint.OrientationConfidenceDegrees = OrientationConfidenceDegrees; thisOrientationDataPoint.Notes = Notes; thisOrientationDataPoint.Symbol = Symbol; // Update the feature OrientationDataPointsUpdater.UpdateOrientationDataPoint(thisOrientationDataPoint); // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } // Save changes OrientationDataPointsUpdater.SaveOrientationDataPoints(); break; case false: // User needs to select an appropriate feature template MessageBox.Show("Please select a FeatureTemplate appropriate for the type of features you've selected" + Environment.NewLine + "You've selected some Orientation Data on the map but have not selected a structural FeatureTemplate."); break; } } } #endregion break; case esriGeometryType.esriGeometryPolygon: // Look for features selected in polygon FeatureClasses #region MapUnitPolys IFeatureLayer MapUnitPolysFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "MapUnitPolys"); if (MapUnitPolysFL != null) { // Found MapUnitPolys. Check for a selection IFeatureSelection selectedFeatures = MapUnitPolysFL as IFeatureSelection; if (selectedFeatures.SelectionSet.Count > 0) { // MapUnitPolys were selected. Pass the selection into a cursor. ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet; ICursor theCursor; featureSelectionSet.Search(null, false, out theCursor); IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor; // Some variables to declare before the loops int idFld = theFeatureCursor.FindField("MapUnitPolys_ID"); IFeature theFeature; string thisId; // Construct a dummy feature to get attributes from IFeature dummyFeature = templateFC.CreateFeature(); theCurrentTemplate.SetDefaultValues(dummyFeature); string MapUnit = dummyFeature.get_Value(templateFC.FindField("MapUnit")).ToString(); string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString(); string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString(); string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString(); string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(); // Destroy the dummy feature - must happen within an edit operation ArcMap.Editor.StartOperation(); dummyFeature.Delete(); ArcMap.Editor.StopOperation("Remove Dummy Feature"); //Is the FeatureTemplate also for MapUnitPolys? switch (MapUnitPolysFL.FeatureClass.Equals(templateFC)) { case true: // Update the features to the FeatureTemplate MapUnitPolysAccess MapUnitPolysUpdater = new MapUnitPolysAccess(m_theWorkspace); theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the MapUnitPolys feature to update thisId = theFeature.get_Value(idFld).ToString(); MapUnitPolysUpdater.AddMapUnitPolys("MapUnitPolys_ID = '" + thisId + "'"); MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = MapUnitPolysUpdater.MapUnitPolysDictionary[thisId]; // Assign values from the FeatureTemplate thisMapUnitPoly.MapUnit = MapUnit; thisMapUnitPoly.IdentityConfidence = IdentityConfidence; thisMapUnitPoly.Label = Label; thisMapUnitPoly.Notes = Notes; thisMapUnitPoly.Symbol = Symbol; // Update the feature MapUnitPolysUpdater.UpdateMapUnitPoly(thisMapUnitPoly); // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } // Save changes MapUnitPolysUpdater.SaveMapUnitPolys(); break; case false: // Copy the features into the templateFC using the selected template as a guide // Build DataAccess Classes for target FeatureClasses OverlayPolysAccess OverlayPolysInserter = new OverlayPolysAccess(m_theWorkspace); // Find the target FeatureClass Name string tableName = (templateFC as IDataset).Name; // Parse the table name in order to strip out unneccessary bits of SDE tables ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace; string parsedDbName, parsedOwnerName, parsedTableName; nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName); // Will need to remove the selected feature from MapUnitPolys MapUnitPolysAccess MapUnitPolysRemover = new MapUnitPolysAccess(m_theWorkspace); // Loop through the selected MapUnitPolys theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the MapUnitPolys feature to remove thisId = theFeature.get_Value(idFld).ToString(); MapUnitPolysRemover.AddMapUnitPolys("MapUnitPolys_ID = '" + thisId + "'"); MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = MapUnitPolysRemover.MapUnitPolysDictionary[thisId]; // Setup attributes string DataSourceID = thisMapUnitPoly.DataSourceID; IPolygon Shape = thisMapUnitPoly.Shape; // Create the new feature in the template FeatureClass switch (parsedTableName) { case "OverlayPolys": // Insert the new OtherLines OverlayPolysInserter.NewOverlayPoly(MapUnit, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape); OverlayPolysInserter.SaveOverlayPolys(); // Clear out the dictionary so lines don't get added more than once. OverlayPolysInserter.ClearOverlayPolys(); // Delete the old one MapUnitPolysRemover.DeleteMapUnitPolys(thisMapUnitPoly); break; default: // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully. break; } // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } break; } } } #endregion #region OverlayPolys IFeatureLayer OverlayPolysFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OverlayPolys"); if (OverlayPolysFL != null) { // Found OverlayPolys. Check for a selection IFeatureSelection selectedFeatures = OverlayPolysFL as IFeatureSelection; if (selectedFeatures.SelectionSet.Count > 0) { // OverlayPolys were selected. Pass the selection into a cursor. ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet; ICursor theCursor; featureSelectionSet.Search(null, false, out theCursor); IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor; // Some variables to declare before the loops int idFld = theFeatureCursor.FindField("OverlayPolys_ID"); IFeature theFeature; string thisId; // Construct a dummy feature to get attributes from IFeature dummyFeature = templateFC.CreateFeature(); theCurrentTemplate.SetDefaultValues(dummyFeature); string MapUnit = dummyFeature.get_Value(templateFC.FindField("MapUnit")).ToString(); string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString(); string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString(); string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString(); string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(); // Destroy the dummy feature - must happen within an edit operation ArcMap.Editor.StartOperation(); dummyFeature.Delete(); ArcMap.Editor.StopOperation("Remove Dummy Feature"); //Is the FeatureTemplate also for OverlayPolys? switch (OverlayPolysFL.FeatureClass.Equals(templateFC)) { case true: // Update the features to the FeatureTemplate OverlayPolysAccess OverlayPolysUpdater = new OverlayPolysAccess(m_theWorkspace); theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the OverlayPolys feature to update thisId = theFeature.get_Value(idFld).ToString(); OverlayPolysUpdater.AddOverlayPolys("OverlayPolys_ID = '" + thisId + "'"); OverlayPolysAccess.OverlayPoly thisOverlayPoly = OverlayPolysUpdater.OverlayPolysDictionary[thisId]; // Assign values from the FeatureTemplate thisOverlayPoly.MapUnit = MapUnit; thisOverlayPoly.IdentityConfidence = IdentityConfidence; thisOverlayPoly.Label = Label; thisOverlayPoly.Notes = Notes; thisOverlayPoly.Symbol = Symbol; // Update the feature OverlayPolysUpdater.UpdateOverlayPoly(thisOverlayPoly); // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } // Save changes OverlayPolysUpdater.SaveOverlayPolys(); break; case false: // Copy the features into the templateFC using the selected template as a guide // Build DataAccess Classes for target FeatureClasses MapUnitPolysAccess MapUnitPolysInserter = new MapUnitPolysAccess(m_theWorkspace); // Find the target FeatureClass Name string tableName = (templateFC as IDataset).Name; // Parse the table name in order to strip out unneccessary bits of SDE tables ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace; string parsedDbName, parsedOwnerName, parsedTableName; nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName); // Will need to remove the selected feature from OverlayPolys OverlayPolysAccess OverlayPolysRemover = new OverlayPolysAccess(m_theWorkspace); // Loop through the selected OverlayPolys theFeature = theFeatureCursor.NextFeature(); while (theFeature != null) { // Find the OverlayPolys feature to remove thisId = theFeature.get_Value(idFld).ToString(); OverlayPolysRemover.AddOverlayPolys("OverlayPolys_ID = '" + thisId + "'"); OverlayPolysAccess.OverlayPoly thisOverlayPoly = OverlayPolysRemover.OverlayPolysDictionary[thisId]; // Setup attributes string DataSourceID = thisOverlayPoly.DataSourceID; IPolygon Shape = thisOverlayPoly.Shape; // Create the new feature in the template FeatureClass switch (parsedTableName) { case "MapUnitPolys": // Insert the new OtherLines MapUnitPolysInserter.NewMapUnitPoly(MapUnit, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape); MapUnitPolysInserter.SaveMapUnitPolys(); // Clear out the dictionary so lines don't get added more than once. MapUnitPolysInserter.ClearMapUnitPolys(); // Delete the old one OverlayPolysRemover.DeleteOverlayPolys(thisOverlayPoly); break; default: // This would happen if there's some other polygon featuretemplate selected. Just need to exit gracefully. break; } // Increment the cursor theFeature = theFeatureCursor.NextFeature(); } break; } } } #endregion break; } }
private void UpdateDataSources(Dictionary<string, object> dataAccessClasses) { // Get the Data Source to set string dataSourceID = commonFunctions.GetCurrentDataSourceID(); // Bail if there isn't one if (dataSourceID == null) { return; } // Get DataAccess Classes to perform updates MapUnitPolysAccess mapUnitPolysAccess = new MapUnitPolysAccess(m_theWorkspace); OverlayPolysAccess OverlayPolysAccess = new OverlayPolysAccess(m_theWorkspace); ContactsAndFaultsAccess ContactsAndFaultsAccess = new ContactsAndFaultsAccess(m_theWorkspace); OtherLinesAccess OtherLinesAccess = new OtherLinesAccess(m_theWorkspace); StationPointsAccess StationPointsAccess = new StationPointsAccess(m_theWorkspace); SamplePointsAccess SamplePointsAccess = new SamplePointsAccess(m_theWorkspace); OrientationDataPointsAccess OrientationDataPointsAccess = new OrientationDataPointsAccess(m_theWorkspace); GlossaryAccess GlossaryAccess = new GlossaryAccess(m_theWorkspace); NotesAccess NotesAccess = new NotesAccess(m_theWorkspace); RelatedDocumentsAccess RelatedDocumentsAccess = new RelatedDocumentsAccess(m_theWorkspace); DescriptionOfMapUnitsAccess DescriptionOfMapUnitsAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); // Loop through the dictionary foreach (KeyValuePair<string, object> anEntry in dataAccessClasses) { // What table does this come from? switch (anEntry.Key) { case "MapUnitPolys": // Loop through the records in the data access object that comes in MapUnitPolysAccess thisMapUnitPolysAccess = (MapUnitPolysAccess)anEntry.Value; foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> MapUnitPolysToUpdate in thisMapUnitPolysAccess.MapUnitPolysDictionary) { MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = (MapUnitPolysAccess.MapUnitPoly)MapUnitPolysToUpdate.Value; thisMapUnitPoly.DataSourceID = dataSourceID; mapUnitPolysAccess.UpdateMapUnitPoly(thisMapUnitPoly); } mapUnitPolysAccess.SaveMapUnitPolys(); break; case "OverlayPolys": OverlayPolysAccess thisOverlayPolysAccess = (OverlayPolysAccess)anEntry.Value; foreach (KeyValuePair<string, OverlayPolysAccess.OverlayPoly> OverlayPolysToUpdate in thisOverlayPolysAccess.OverlayPolysDictionary) { OverlayPolysAccess.OverlayPoly thisOverlayPoly = (OverlayPolysAccess.OverlayPoly)OverlayPolysToUpdate.Value; thisOverlayPoly.DataSourceID = dataSourceID; OverlayPolysAccess.UpdateOverlayPoly(thisOverlayPoly); } OverlayPolysAccess.SaveOverlayPolys(); break; case "ContactsAndFaults": ContactsAndFaultsAccess thisContactsAndFaultsAccess = (ContactsAndFaultsAccess)anEntry.Value; foreach (KeyValuePair<string, ContactsAndFaultsAccess.ContactsAndFault> ContactsAndFaultsToUpdate in thisContactsAndFaultsAccess.ContactsAndFaultsDictionary) { ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = (ContactsAndFaultsAccess.ContactsAndFault)ContactsAndFaultsToUpdate.Value; thisContactsAndFault.DataSourceID = dataSourceID; ContactsAndFaultsAccess.UpdateContactsAndFault(thisContactsAndFault); } ContactsAndFaultsAccess.SaveContactsAndFaults(); break; case "OtherLines": OtherLinesAccess thisOtherLinesAccess = (OtherLinesAccess)anEntry.Value; foreach (KeyValuePair<string, OtherLinesAccess.OtherLine> OtherLinesToUpdate in thisOtherLinesAccess.OtherLinesDictionary) { OtherLinesAccess.OtherLine thisOtherLine = (OtherLinesAccess.OtherLine)OtherLinesToUpdate.Value; thisOtherLine.DataSourceID = dataSourceID; OtherLinesAccess.UpdateOtherLine(thisOtherLine); } OtherLinesAccess.SaveOtherLines(); break; case "StationPoints": StationPointsAccess thisStationPointsAccess = (StationPointsAccess)anEntry.Value; foreach (KeyValuePair<string, StationPointsAccess.StationPoint> StationPointsToUpdate in thisStationPointsAccess.StationPointsDictionary) { StationPointsAccess.StationPoint thisStationPoint = (StationPointsAccess.StationPoint)StationPointsToUpdate.Value; thisStationPoint.DataSourceID = dataSourceID; StationPointsAccess.UpdateStationPoint(thisStationPoint); } StationPointsAccess.SaveStationPoints(); break; case "SamplePoints": SamplePointsAccess thisSamplePointsAccess = (SamplePointsAccess)anEntry.Value; foreach (KeyValuePair<string, SamplePointsAccess.SamplePoint> SamplePointsToUpdate in thisSamplePointsAccess.SamplePointsDictionary) { SamplePointsAccess.SamplePoint thisSamplePoint = (SamplePointsAccess.SamplePoint)SamplePointsToUpdate.Value; thisSamplePoint.DataSourceID = dataSourceID; SamplePointsAccess.UpdateSamplePoint(thisSamplePoint); } SamplePointsAccess.SaveSamplePoints(); break; case "OrientationDataPoints": OrientationDataPointsAccess thisOrientationDataPointsAccess = (OrientationDataPointsAccess)anEntry.Value; foreach (KeyValuePair<string, OrientationDataPointsAccess.OrientationDataPoint> OrientationDataPointsToUpdate in thisOrientationDataPointsAccess.OrientationDataPointsDictionary) { OrientationDataPointsAccess.OrientationDataPoint thisOrientationDataPoint = (OrientationDataPointsAccess.OrientationDataPoint)OrientationDataPointsToUpdate.Value; thisOrientationDataPoint.DataSourceID = dataSourceID; OrientationDataPointsAccess.UpdateOrientationDataPoint(thisOrientationDataPoint); } OrientationDataPointsAccess.SaveOrientationDataPoints(); break; case "Glossary": GlossaryAccess thisGlossaryAccess = (GlossaryAccess)anEntry.Value; foreach (KeyValuePair<string, GlossaryAccess.Glossary> GlossaryToUpdate in thisGlossaryAccess.GlossaryDictionary) { GlossaryAccess.Glossary thisGlossary = (GlossaryAccess.Glossary)GlossaryToUpdate.Value; thisGlossary.DefinitionSourceID = dataSourceID; GlossaryAccess.UpdateGlossary(thisGlossary); } GlossaryAccess.SaveGlossary(); break; case "Notes": NotesAccess thisNotesAccess = (NotesAccess)anEntry.Value; foreach (KeyValuePair<string, NotesAccess.Note> NotesToUpdate in thisNotesAccess.NotesDictionary) { NotesAccess.Note thisNote = (NotesAccess.Note)NotesToUpdate.Value; thisNote.DataSourceID = dataSourceID; NotesAccess.UpdateNote(thisNote); } NotesAccess.SaveNotes(); break; case "RelatedDocuments": RelatedDocumentsAccess thisRelatedDocumentsAccess = (RelatedDocumentsAccess)anEntry.Value; foreach (KeyValuePair<string, RelatedDocumentsAccess.RelatedDocument> RelatedDocumentsToUpdate in thisRelatedDocumentsAccess.RelatedDocumentsDictionary) { RelatedDocumentsAccess.RelatedDocument thisRelatedDocument = (RelatedDocumentsAccess.RelatedDocument)RelatedDocumentsToUpdate.Value; thisRelatedDocument.DataSourceID = dataSourceID; RelatedDocumentsAccess.UpdateRelatedDocument(thisRelatedDocument); } RelatedDocumentsAccess.SaveRelatedDocuments(); break; case "DescriptionOfMapUnits": DescriptionOfMapUnitsAccess thisDescriptionOfMapUnitsAccess = (DescriptionOfMapUnitsAccess)anEntry.Value; foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> DescriptionOfMapUnitsToUpdate in thisDescriptionOfMapUnitsAccess.DescriptionOfMapUnitsDictionary) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDescriptionOfMapUnit = (DescriptionOfMapUnitsAccess.DescriptionOfMapUnit)DescriptionOfMapUnitsToUpdate.Value; thisDescriptionOfMapUnit.DescriptionSourceID = dataSourceID; DescriptionOfMapUnitsAccess.UpdateDescriptionOfMapUnit(thisDescriptionOfMapUnit); } DescriptionOfMapUnitsAccess.SaveDescriptionOfMapUnits(); break; } } }
private void UpdateDataSources(Dictionary<string, object> dataAccessClasses) { // Get the Data Source to set string dataSourceID = commonFunctions.GetCurrentDataSourceID(); // Bail if there isn't one if (dataSourceID == null) { return; } // Get DataAccess Classes to perform updates MapUnitPolysAccess mapUnitPolysAccess = new MapUnitPolysAccess(m_theWorkspace); DataSourcePolysAccess dataSourcePolysAccess = new DataSourcePolysAccess(m_theWorkspace); OtherPolysAccess OtherPolysAccess = new OtherPolysAccess(m_theWorkspace); ContactsAndFaultsAccess ContactsAndFaultsAccess = new ContactsAndFaultsAccess(m_theWorkspace); GeologicLinesAccess GeologicLinesAccess = new GeologicLinesAccess(m_theWorkspace); StationsAccess StationsAccess = new StationsAccess(m_theWorkspace); GenericSamplesAccess GenericSamplesAccess = new GenericSamplesAccess(m_theWorkspace); OrientationPointsAccess OrientationPointsAccess = new OrientationPointsAccess(m_theWorkspace); GlossaryAccess GlossaryAccess = new GlossaryAccess(m_theWorkspace); DescriptionOfMapUnitsAccess DescriptionOfMapUnitsAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); // Loop through the dictionary foreach (KeyValuePair<string, object> anEntry in dataAccessClasses) { // What table does this come from? switch (anEntry.Key) { case "MapUnitPolys": // Loop through the records in the data access object that comes in MapUnitPolysAccess thisMapUnitPolysAccess = (MapUnitPolysAccess)anEntry.Value; foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> MapUnitPolysToUpdate in thisMapUnitPolysAccess.MapUnitPolysDictionary) { MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = (MapUnitPolysAccess.MapUnitPoly)MapUnitPolysToUpdate.Value; thisMapUnitPoly.DataSourceID = dataSourceID; mapUnitPolysAccess.UpdateMapUnitPoly(thisMapUnitPoly); } mapUnitPolysAccess.SaveMapUnitPolys(); break; case "DataSourcePolys": // Loop through the records in the data access object that comes in DataSourcePolysAccess thisDataSourcePolysAccess = (DataSourcePolysAccess)anEntry.Value; foreach (KeyValuePair<string, DataSourcePolysAccess.DataSourcePoly> DataSourcePolysToUpdate in thisDataSourcePolysAccess.DataSourcePolysDictionary) { DataSourcePolysAccess.DataSourcePoly thisDataSourcePoly = (DataSourcePolysAccess.DataSourcePoly)DataSourcePolysToUpdate.Value; thisDataSourcePoly.DataSourceID = dataSourceID; dataSourcePolysAccess.UpdateDataSourcePoly(thisDataSourcePoly); } dataSourcePolysAccess.SaveDataSourcePolys(); break; case "OtherPolys": OtherPolysAccess thisOtherPolysAccess = (OtherPolysAccess)anEntry.Value; foreach (KeyValuePair<string, OtherPolysAccess.OtherPoly> OtherPolysToUpdate in thisOtherPolysAccess.OtherPolysDictionary) { OtherPolysAccess.OtherPoly thisOtherPoly = (OtherPolysAccess.OtherPoly)OtherPolysToUpdate.Value; thisOtherPoly.DataSourceID = dataSourceID; OtherPolysAccess.UpdateOtherPoly(thisOtherPoly); } OtherPolysAccess.SaveOtherPolys(); break; case "ContactsAndFaults": ContactsAndFaultsAccess thisContactsAndFaultsAccess = (ContactsAndFaultsAccess)anEntry.Value; foreach (KeyValuePair<string, ContactsAndFaultsAccess.ContactsAndFault> ContactsAndFaultsToUpdate in thisContactsAndFaultsAccess.ContactsAndFaultsDictionary) { ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = (ContactsAndFaultsAccess.ContactsAndFault)ContactsAndFaultsToUpdate.Value; thisContactsAndFault.DataSourceID = dataSourceID; ContactsAndFaultsAccess.UpdateContactsAndFault(thisContactsAndFault); } ContactsAndFaultsAccess.SaveContactsAndFaults(); break; case "GeologicLines": GeologicLinesAccess thisGeologicLinesAccess = (GeologicLinesAccess)anEntry.Value; foreach (KeyValuePair<string, GeologicLinesAccess.GeologicLine> GeologicLinesToUpdate in thisGeologicLinesAccess.GeologicLinesDictionary) { GeologicLinesAccess.GeologicLine thisGeologicLine = (GeologicLinesAccess.GeologicLine)GeologicLinesToUpdate.Value; thisGeologicLine.DataSourceID = dataSourceID; GeologicLinesAccess.UpdateGeologicLine(thisGeologicLine); } GeologicLinesAccess.SaveGeologicLines(); break; case "Stations": StationsAccess thisStationsAccess = (StationsAccess)anEntry.Value; foreach (KeyValuePair<string, StationsAccess.Station> StationsToUpdate in thisStationsAccess.StationsDictionary) { StationsAccess.Station thisStation = (StationsAccess.Station)StationsToUpdate.Value; thisStation.DataSourceID = dataSourceID; StationsAccess.UpdateStation(thisStation); } StationsAccess.SaveStations(); break; case "GenericSamples": GenericSamplesAccess thisGenericSamplesAccess = (GenericSamplesAccess)anEntry.Value; foreach (KeyValuePair<string, GenericSamplesAccess.GenericSample> GenericSamplesToUpdate in thisGenericSamplesAccess.GenericSamplesDictionary) { GenericSamplesAccess.GenericSample thisGenericSample = (GenericSamplesAccess.GenericSample)GenericSamplesToUpdate.Value; thisGenericSample.DataSourceID = dataSourceID; GenericSamplesAccess.UpdateGenericSample(thisGenericSample); } GenericSamplesAccess.SaveGenericSamples(); break; case "OrientationPoints": OrientationPointsAccess thisOrientationPointsAccess = (OrientationPointsAccess)anEntry.Value; foreach (KeyValuePair<string, OrientationPointsAccess.OrientationPoint> OrientationPointsToUpdate in thisOrientationPointsAccess.OrientationPointsDictionary) { OrientationPointsAccess.OrientationPoint thisOrientationPoint = (OrientationPointsAccess.OrientationPoint)OrientationPointsToUpdate.Value; thisOrientationPoint.DataSourceID = dataSourceID; OrientationPointsAccess.UpdateOrientationPoint(thisOrientationPoint); } OrientationPointsAccess.SaveOrientationPoints(); break; case "Glossary": GlossaryAccess thisGlossaryAccess = (GlossaryAccess)anEntry.Value; foreach (KeyValuePair<string, GlossaryAccess.Glossary> GlossaryToUpdate in thisGlossaryAccess.GlossaryDictionary) { GlossaryAccess.Glossary thisGlossary = (GlossaryAccess.Glossary)GlossaryToUpdate.Value; thisGlossary.DefinitionSourceID = dataSourceID; GlossaryAccess.UpdateGlossary(thisGlossary); } GlossaryAccess.SaveGlossary(); break; case "DescriptionOfMapUnits": DescriptionOfMapUnitsAccess thisDescriptionOfMapUnitsAccess = (DescriptionOfMapUnitsAccess)anEntry.Value; foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> DescriptionOfMapUnitsToUpdate in thisDescriptionOfMapUnitsAccess.DescriptionOfMapUnitsDictionary) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDescriptionOfMapUnit = (DescriptionOfMapUnitsAccess.DescriptionOfMapUnit)DescriptionOfMapUnitsToUpdate.Value; thisDescriptionOfMapUnit.DescriptionSourceID = dataSourceID; DescriptionOfMapUnitsAccess.UpdateDescriptionOfMapUnit(thisDescriptionOfMapUnit); } DescriptionOfMapUnitsAccess.SaveDescriptionOfMapUnits(); break; } } }
private void tlsbtnAssignUnit_Click(object sender, EventArgs e) { // Find the selected DMU Entry string dmuID = trvLegendItems.SelectedNode.Name; if (dmuID == null) { return; } DescriptionOfMapUnitsAccess dmuAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); dmuAccess.AddDescriptionOfMapUnits("DescriptionOfMapUnits_ID = '" + dmuID + "'"); DescriptionOfMapUnitsAccess.DescriptionOfMapUnit dmuEntry = dmuAccess.DescriptionOfMapUnitsDictionary[dmuID]; // Get selected polygons IFeatureLayer mapUnitPolysLayer = commonFunctions.FindFeatureLayer(m_theWorkspace, "MapUnitPolys"); // Find out if there are selected features IFeatureSelection featureSelection = (IFeatureSelection)mapUnitPolysLayer; ISelectionSet theSelection = featureSelection.SelectionSet; // Bail if nothing was selected if (theSelection.Count == 0) { return; } // Pass the selected features into a cursor that we can iterate through ICursor theCursor; theSelection.Search(null, false, out theCursor); int IdFld = theCursor.FindField("MapUnitPolys_ID"); // Build the Where Clause to get these features by looping through the cursor string sqlWhereClause = "MapUnitPolys_ID = '"; IRow theRow = theCursor.NextRow(); while (theRow != null) { sqlWhereClause += theRow.get_Value(IdFld) + "' OR MapUnitPolys_ID = '"; theRow = theCursor.NextRow(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(theCursor); // If we didn't add anything to the where clause, bail if (sqlWhereClause == "MapUnitPolys_ID = '") { return; } // Cleanup the where clause sqlWhereClause = sqlWhereClause.Remove(sqlWhereClause.Length - 23); // Get the MapUnitPolys MapUnitPolysAccess polysAccess = new MapUnitPolysAccess(m_theWorkspace); polysAccess.AddMapUnitPolys(sqlWhereClause); //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Data Access Issue: I actually have to pass the dictionary into another object. // If I don't, once the first record is updated, the dictionary is changed. // Then the foreach loop fails, because what it is looping through was adjusted. // Not very happy with this. //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Sort using Linq syntax var sortedPolys = ( from entry in polysAccess.MapUnitPolysDictionary select entry); MapUnitPolysAccess secondPolysAccess = new MapUnitPolysAccess(m_theWorkspace); try { // Cycle through the MapUnitPolys and update the MapUnit and Label attributes foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> anEntry in sortedPolys) { // Get the MapUnitPoly object secondPolysAccess.AddMapUnitPolys("MapUnitPolys_ID = '" + anEntry.Value.MapUnitPolys_ID + "'"); MapUnitPolysAccess.MapUnitPoly aPoly = secondPolysAccess.MapUnitPolysDictionary[anEntry.Value.MapUnitPolys_ID]; // Change the appropriate values aPoly.MapUnit = dmuEntry.MapUnit; aPoly.Label = dmuEntry.Label; // Update the Poly secondPolysAccess.UpdateMapUnitPoly(aPoly); } } catch (Exception err) { MessageBox.Show(err.Message); } // Save updates secondPolysAccess.SaveMapUnitPolys(); // Update the active view ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, mapUnitPolysLayer, null); }