private void OnContentChanged() { try { Color = ArcUtils.GetColorFromLayer(_layer); if (LayerChangedEvent != null) { LayerChangedEvent(this); } } catch (Exception ex) { Trace.WriteLine(ex.Message, "CycloMediaLayer.OnContentChanged"); } }
// ========================================================================= // 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); }