private void MyConstructor() { _controller = AlaskaPak.Controller; _controller.LayersChanged += Controller_LayersChanged; _data = new FormData(_controller.GetPointLayers()); Enabled = MapHasPointFeatureLayer; }
private static void EditLayer(FormData data) { IFeatureClass featureClass = data.GetFeatureClass(); if (featureClass == null) { MessageBox.Show(@"No feature layer/class was selected."); return; } if (featureClass.ShapeType != esriGeometryType.esriGeometryPoint) { MessageBox.Show(@"Data is not a point feature."); return; } //If fields don't exist, add them foreach (string fieldName in new[] { data.XFieldName, data.YFieldName }) { if (data.FieldNameExists(fieldName)) continue; esriFieldType fieldType = data.Format.Formattable ? esriFieldType.esriFieldTypeString : esriFieldType.esriFieldTypeDouble; try { AddField(featureClass, fieldName, fieldType); } catch (Exception e) { MessageBox.Show( @"Unable to add new fields. Check that the selected data is not open in Catalog. Check that the selected layer is not being edited. System Message: " + e.Message); return; } } //try to get an update cursor on the feature class IFeatureCursor cursor; try { cursor = featureClass.Update(null, true); } catch (Exception e) { Console.WriteLine(@"Unable to edit the layer: " + e.Message); return; } int xIndex = cursor.FindField(data.XFieldName); int yIndex = cursor.FindField(data.YFieldName); ISpatialReference spatialReference = null; if (data.Format.OutputFormat == FormatterOutputFormat.DataFrame) spatialReference = ArcMap.Document.FocusMap.SpatialReference; if (data.Format.Formattable) // We already guaranteed it is a point feature, so it must implement IGeoDataset spatialReference = GetGcsFromPcs(((IGeoDataset)featureClass).SpatialReference); IFeature feature = cursor.NextFeature(); while (feature != null) { var point = (IPoint)feature.Shape; if (spatialReference != null) point.Project(spatialReference); if (data.Format.Formattable) { feature.Value[xIndex] = data.Format.Format(point.X, false); feature.Value[yIndex] = data.Format.Format(point.Y, true); } else { feature.Value[xIndex] = point.X; feature.Value[yIndex] = point.Y; } cursor.UpdateFeature(feature); feature = cursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); }
internal AddXyForm(FormData data) { InitializeComponent(); Data = data; }