private static void OnStopEditing(bool save)
        {
            try
            {
                LogClient.Info(string.Format("On Stop Editing: {0}", save));
                EditFeatures.Clear();
                _doSelection = true;

                if (StopEditEvent != null)
                {
                    StopEditEvent();
                    AvContentChanged();
                }

                if (_editToolCheckTimer != null)
                {
                    _editToolCheckTimer.Dispose();
                    _editToolCheckTimer = null;
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("VectorLayer.OnStopEditing", ex.Message, ex);
                Trace.WriteLine(ex.Message, "VectorLayer.OnStopEditing");
            }
        }
        private static void OnDeleteFeature(IObject obj)
        {
            try
            {
                var feature = obj as IFeature;
                LogClient.Info(string.Format("On Delete Feature: {0}", ((feature != null) ? feature.Class.AliasName : string.Empty)));

                if ((FeatureDeleteEvent != null) && (feature != null))
                {
                    if (EditFeatures.Contains(feature))
                    {
                        EditFeatures.Remove(feature);
                    }

                    VectorLayer vectorLayer = GetLayer(feature);

                    if ((vectorLayer != null) && (vectorLayer.IsVisibleInGlobespotter))
                    {
                        FeatureDeleteEvent(feature);
                        AvContentChanged();
                    }
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("VectorLayer.OnDeleteFeature", ex.Message, ex);
                Trace.WriteLine(ex.Message, "VectorLayer.OnDeleteFeature");
            }
        }
        // =========================================================================
        // Functions (Public)
        // =========================================================================
        public string GetGmlFromLocation(List <RecordingLocation> recordingLocations, double distance, out Color color, SpatialReference cyclSpatialRef)
        {
            string result = WfsHeader;

            // ReSharper disable UseIndexedProperty

            if (_featureClass != null)
            {
                IGeometry         geometryBag        = new GeometryBagClass();
                var               geometryCollection = geometryBag as IGeometryCollection;
                Config            config             = Config.Instance;
                SpatialReference  spatRel            = config.SpatialReference;
                ISpatialReference gsSpatialReference = (spatRel == null) ? ArcUtils.SpatialReference : spatRel.SpatialRef;
                var               projCoord          = gsSpatialReference as IProjectedCoordinateSystem;

                if (projCoord == null)
                {
                    var geoCoord = gsSpatialReference as IGeographicCoordinateSystem;

                    if (geoCoord != null)
                    {
                        IAngularUnit unit   = geoCoord.CoordinateUnit;
                        double       factor = unit.ConversionFactor;
                        distance = distance * factor;
                    }
                }
                else
                {
                    ILinearUnit unit   = projCoord.CoordinateUnit;
                    double      factor = unit.ConversionFactor;
                    distance = distance / factor;
                }

                foreach (var recordingLocation in recordingLocations)
                {
                    double x = recordingLocation.X;
                    double y = recordingLocation.Y;

                    IEnvelope envelope = new EnvelopeClass
                    {
                        XMin             = x - distance,
                        XMax             = x + distance,
                        YMin             = y - distance,
                        YMax             = y + distance,
                        SpatialReference = gsSpatialReference
                    };

                    envelope.Project(SpatialReference);
                    geometryCollection.AddGeometry(envelope);
                }

                ITopologicalOperator unionedPolygon = new PolygonClass();
                unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
                var polygon = unionedPolygon as IPolygon;

                ISpatialFilter spatialFilter = new SpatialFilterClass
                {
                    Geometry      = polygon,
                    GeometryField = _featureClass.ShapeFieldName,
                    SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects
                };

                var featureCursor = _featureClass.Search(spatialFilter, false);
                var featureCount  = _featureClass.FeatureCount(spatialFilter);
                var shapeId       = featureCursor.FindField(_featureClass.ShapeFieldName);
                var gmlConverter  = new GMLConverter();

                for (int i = 0; i < featureCount; i++)
                {
                    IFeature feature = featureCursor.NextFeature();

                    if (!EditFeatures.Contains(feature))
                    {
                        IFields fields      = feature.Fields;
                        var     fieldvalues = new Dictionary <string, string> {
                            { "FEATURECLASSNAME", _featureClass.AliasName }
                        };

                        for (int j = 0; j < fields.FieldCount; j++)
                        {
                            IField field = fields.Field[j];
                            string name  = field.Name;
                            int    id    = featureCursor.FindField(name);

                            string value = (id != shapeId)
                ? feature.get_Value(id).ToString()
                : _featureClass.ShapeType.ToString().Replace("esriGeometry", string.Empty);
                            fieldvalues.Add(name, value);
                        }

                        var shapeVar = feature.get_Value(shapeId);
                        var geometry = shapeVar as IGeometry;

                        if (geometry != null)
                        {
                            geometry.Project((cyclSpatialRef == null) ? gsSpatialReference : cyclSpatialRef.SpatialRef);

                            if (!HasZ)
                            {
                                var pointCollection = geometry as IPointCollection4;

                                if (pointCollection != null)
                                {
                                    for (int j = 0; j < pointCollection.PointCount; j++)
                                    {
                                        IPoint point = pointCollection.Point[j];

                                        if (point != null)
                                        {
                                            point.Z = double.NaN;
                                        }

                                        pointCollection.ReplacePoints(j, 1, 1, point);
                                    }

                                    shapeVar = pointCollection as IGeometry;
                                }
                                else
                                {
                                    var point = geometry as IPoint;

                                    if (point != null)
                                    {
                                        point.Z  = double.NaN;
                                        shapeVar = point;
                                    }
                                }
                            }
                        }

                        gmlConverter.ESRIGeometry = shapeVar;
                        string gml = gmlConverter.GML;
                        gml = gml.Replace("<Polygon>", string.Format("<Polygon srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("<LineString>", string.Format("<LineString srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("<point>", string.Format("<point srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("point", "Point");
                        gml = gml.Replace(",1.#QNAN", string.Empty);
                        gml = gml.Replace("<", "<gml:");
                        gml = gml.Replace("<gml:/", "</gml:");
                        string fieldValueStr = fieldvalues.Aggregate(string.Empty,
                                                                     (current, fieldvalue) => string.Format("{0}<{1}>{2}</{1}>", current, fieldvalue.Key, fieldvalue.Value));
                        result = string.Format("{0}<gml:featureMember><xs:Geometry>{1}{2}</xs:Geometry></gml:featureMember>", result,
                                               fieldValueStr, gml);
                    }
                }
            }

            // ReSharper restore UseIndexedProperty
            color      = ArcUtils.GetColorFromLayer(_layer);
            GmlChanged = (_color != color);
            _color     = color;
            string newGml = string.Concat(result, WfsFinished);

            GmlChanged = ((newGml != _gml) || GmlChanged);
            return(_gml = newGml);
        }
        private static void OnSelectionChanged()
        {
            try
            {
                IApplication application = ArcMap.Application;
                ICommandItem tool        = application.CurrentTool;
                string       name        = tool.Name;

                IEditor3 editor = ArcUtils.Editor;
                LogClient.Info("On Selection Changed");

                if (editor != null)
                {
                    IEnumFeature editSelection = editor.EditSelection;

                    if (editSelection != null)
                    {
                        editSelection.Reset();
                        EditFeatures.Clear();
                        IFeature feature;

                        while ((feature = editSelection.Next()) != null)
                        {
                            EditFeatures.Add(feature);
                        }

                        if (FeatureStartEditEvent != null)
                        {
                            var geometries = new List <IGeometry>();
                            editSelection.Reset();
                            bool isPointLayer = false;

                            while ((feature = editSelection.Next()) != null)
                            {
                                VectorLayer vectorLayer = GetLayer(feature);

                                if ((vectorLayer != null) && (vectorLayer.IsVisibleInGlobespotter))
                                {
                                    geometries.Add(feature.Shape);
                                    isPointLayer = isPointLayer || (Measurement.GetTypeOfLayer(feature.Shape) == TypeOfLayer.Point);
                                }
                            }

                            if ((_doSelection && (name != "Query_SelectFeatures")) || (!isPointLayer))
                            {
                                FeatureStartEditEvent(geometries);
                                AvContentChanged();

                                _doSelection = false;

                                if (_nextSelectionTimer == null)
                                {
                                    var       checkEvent  = new AutoResetEvent(true);
                                    const int timeOutTime = 1500;

                                    var checkTimerCallBack = new TimerCallback(CheckTimerCallBack);

                                    _nextSelectionTimer = new Timer(checkTimerCallBack, checkEvent, timeOutTime, -1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("VectorLayer.OnSelectionChanged", ex.Message, ex);
                Trace.WriteLine(ex.Message, "VectorLayer.OnSelectionChanged");
            }
        }
 /// <summary>
 /// Reverts any changes made to the features, resetting to values from the built-in program database.
 /// </summary>
 public void RevertToDatabase()
 {
     EditsPriorToRevertToDatabase = EditFeatures.Clone();
     EditFeatures = Description.ProgramInformation.Features.Clone();
     InitializeToEditFeatures();
 }