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); }