public static void UpdateCalculatedRecords(FeatureLayer featureLayer, IEnumerable <FeatureSourceColumn> updateColumns, bool needCalculate) { featureLayer.SafeProcess(() => { try { featureLayer.CloseInOverlay(); featureLayer.SetLayerAccess(LayerAccessMode.ReadWrite); featureLayer.Open(); foreach (var column in updateColumns) { var calculateColumn = column as CalculatedDbfColumn; if (calculateColumn == null) { EditorUIPlugin editorPlugin = GisEditor.UIManager.GetActiveUIPlugins <EditorUIPlugin>().FirstOrDefault(); if (editorPlugin != null) { string id = featureLayer.FeatureSource.Id; if (editorPlugin.CalculatedColumns.ContainsKey(id)) { calculateColumn = editorPlugin.CalculatedColumns[id].FirstOrDefault(c => c.ColumnName == column.ColumnName); } } } if (calculateColumn != null) { EditorUIPlugin editorPlugin = GisEditor.UIManager.GetActiveUIPlugins <EditorUIPlugin>().FirstOrDefault(); if (editorPlugin != null) { string id = featureLayer.FeatureSource.Id; if (editorPlugin.CalculatedColumns.ContainsKey(id) && !editorPlugin.CalculatedColumns[id].Any(c => c.ColumnName == calculateColumn.ColumnName)) { editorPlugin.CalculatedColumns[id].Add(calculateColumn); } else { editorPlugin.CalculatedColumns[id] = new Collection <CalculatedDbfColumn>(); editorPlugin.CalculatedColumns[id].Add(calculateColumn); } } if (needCalculate) { var features = featureLayer.FeatureSource.GetAllFeatures(new Collection <string>() { calculateColumn.ColumnName }); foreach (var feature in features) { Feature featureInDecimalDegree = ConvertToWgs84Projection(feature); var calculatedValue = string.Empty; double value = 0; switch (calculateColumn.CalculationType) { case CalculatedDbfColumnType.Perimeter: var perimeterShape = featureInDecimalDegree.GetShape() as AreaBaseShape; if (perimeterShape != null) { value = perimeterShape.GetPerimeter(GeographyUnit.DecimalDegree, calculateColumn.LengthUnit); } break; case CalculatedDbfColumnType.Area: var areaShape = featureInDecimalDegree.GetShape() as AreaBaseShape; if (areaShape != null) { value = areaShape.GetArea(GeographyUnit.DecimalDegree, calculateColumn.AreaUnit); } break; case CalculatedDbfColumnType.Length: var lineShape = featureInDecimalDegree.GetShape() as LineBaseShape; if (lineShape != null) { value = lineShape.GetLength(GeographyUnit.DecimalDegree, calculateColumn.LengthUnit); } break; default: break; } calculatedValue = string.Format("{0:N" + calculateColumn.DecimalLength + "}", value); if (calculatedValue.Length > calculateColumn.Length) { calculatedValue = calculatedValue.Substring(0, calculateColumn.Length); } featureLayer.EditTools.BeginTransaction(); //calculatedValue = calculatedValue.Substring(0, column.MaxLength); feature.ColumnValues[calculateColumn.ColumnName] = calculatedValue; featureLayer.EditTools.Update(feature); featureLayer.EditTools.CommitTransaction(); } } } } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { featureLayer.Close(); featureLayer.SetLayerAccess(LayerAccessMode.Read); } }); }