public IFeatureClass CreateFeatureClass()
        {
            IFeatureClass result     = null;
            IFieldsEdit   fieldsEdit = new FieldsClass();

            fieldsEdit = CreateField(fieldsEdit, "ObjectId", esriFieldType.esriFieldTypeOID);

            IMappedFeature   mapFeature               = CreateMappedFeature(null);
            esriGeometryType esriGeometryType         = mapFeature.EsriGeometryType;
            Dictionary <string, esriFieldType> fields = mapFeature.Fields;

            if ((esriGeometryType != esriGeometryType.esriGeometryNull) && (fields.Count >= 1))
            {
                string            shapeFieldName   = mapFeature.ShapeFieldName;
                ISpatialReference spatialReference = ArcUtils.SpatialReference;
                fieldsEdit = CreateGeometryField(fieldsEdit, shapeFieldName, spatialReference, esriGeometryType);
                fieldsEdit = fields.Aggregate(fieldsEdit, (current, field) => CreateField(current, field.Key, field.Value));

                foreach (var fieldName in FieldNames)
                {
                    if ((!string.IsNullOrEmpty(fieldName)) &&
                        (!fields.Aggregate(false, (current, field) => (field.Key == fieldName) || current)))
                    {
                        CreateField(fieldsEdit, fieldName, esriFieldType.esriFieldTypeString);
                    }
                }

                IFeatureWorkspace featureWorkspace = _cycloMediaGroupLayer.FeatureWorkspace;
                result = featureWorkspace.CreateFeatureClass(FcName, fieldsEdit, null, null, esriFeatureType.esriFTSimple,
                                                             shapeFieldName, string.Empty);
            }

            return(result);
        }
        protected override bool Filter(IMappedFeature mappedFeature)
        {
            var  recording = mappedFeature as Recording;
            bool result    = (recording != null);

            if (result)
            {
                DateTime?recordedAt = recording.RecordedAt;
                result = (recordedAt != null);

                if (result)
                {
                    var dateTime = (DateTime)recordedAt;
                    int year     = dateTime.Year;
                    int month    = dateTime.Month;

                    if (!YearMonth.ContainsKey(year))
                    {
                        YearMonth.Add(year, month);
                        ChangeHistoricalDate();
                    }
                    else
                    {
                        YearMonth[year] = month;
                    }
                }
            }

            return(result);
        }
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            try
            {
                CycloMediaLayer layer;
                string          imageId = GetImageIdFromPoint(arg, out layer);

                if ((!string.IsNullOrEmpty(imageId)) && (layer != null))
                {
                    IMappedFeature mappedFeature = layer.GetLocationInfo(imageId);
                    var            recording     = mappedFeature as Recording;

                    if (recording != null)
                    {
                        if ((recording.IsAuthorized == null) || ((bool)recording.IsAuthorized))
                        {
                            FrmGlobespotter.ShowLocation(imageId, layer);
                        }
                        else
                        {
                            MessageBox.Show(Resources.GsOpenLocation_OnMouseUp_You_are_not_authorized_to_view_the_image_);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logClient.Error("GsOpenLocation.OnMouseUp", ex.Message, ex);
                Trace.WriteLine(ex.Message, "GsOpenLocation.OnMouseUp");
            }

            base.OnMouseUp(arg);
        }
 // =========================================================================
 // Constructor
 // =========================================================================
 private WfsLayer(CycloMediaGroupLayer layer)
     : base(layer)
 {
     _web               = Web.Instance;
     _imageToAdd        = new Dictionary <string, Image>();
     _getImageLock      = new object();
     _getImageThread    = null;
     _refreshDataThread = null;
     _addedImage        = false;
     _minimumScale      = 0.0;
     _mappedFeature     = null;
 }
        // =========================================================================
        // Functions (Protected)
        // =========================================================================
        protected override IMappedFeature CreateMappedFeature(XElement mappedFeatureElement)
        {
            if (_mappedFeature == null)
            {
                _mappedFeature = new WfsFeature(mappedFeatureElement, FeatureType);
            }
            else
            {
                _mappedFeature.Update(mappedFeatureElement);
            }

            return(_mappedFeature);
        }
        public string GetFeatureFromPoint(int x, int y)
        {
            string      result     = string.Empty;
            IActiveView activeView = ArcUtils.ActiveView;

            if ((activeView != null) && InsideScale)
            {
                IMappedFeature         mapFeature    = CreateMappedFeature(null);
                string                 objectId      = mapFeature.ObjectId;
                IScreenDisplay         screenDisplay = activeView.ScreenDisplay;
                IDisplayTransformation dispTrans     = screenDisplay.DisplayTransformation;
                IPoint                 pointLu       = dispTrans.ToMapPoint(x - SizeLayer, y - SizeLayer);
                IPoint                 pointRd       = dispTrans.ToMapPoint(x + SizeLayer, y + SizeLayer);

                IEnvelope envelope = new EnvelopeClass
                {
                    XMin             = pointLu.X,
                    XMax             = pointRd.X,
                    YMin             = pointLu.Y,
                    YMax             = pointRd.Y,
                    SpatialReference = ArcUtils.SpatialReference
                };

                envelope.Project(SpatialReference);

                ISpatialFilter spatialFilter = new SpatialFilterClass
                {
                    Geometry      = envelope,
                    GeometryField = FeatureClass.ShapeFieldName,
                    SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains,
                    SubFields     = objectId
                };

                var      existsResult = FeatureClass.Search(spatialFilter, false);
                IFeature feature;

                // ReSharper disable UseIndexedProperty
                while ((feature = existsResult.NextFeature()) != null)
                {
                    int imId = existsResult.FindField(objectId);
                    result = (string)feature.get_Value(imId);
                }

                // ReSharper restore UseIndexedProperty
            }

            return(result);
        }
        public IFeature GetFeature(string imageId)
        {
            IMappedFeature mappedFeature  = CreateMappedFeature(null);
            var            fields         = mappedFeature.Fields;
            string         shapeFieldName = mappedFeature.ShapeFieldName;

            IQueryFilter filter = new QueryFilterClass
            {
                WhereClause = string.Format("ImageId = '{0}'", imageId),
                SubFields   = string.Format("{0}, {1}", fields.Aggregate("ObjectId", (current, field) => string.Format
                                                                             ("{0}{1}{2}", current, string.IsNullOrEmpty(current) ? string.Empty : ", ", field.Key)), shapeFieldName)
            };

            var existsResult = FeatureClass.Search(filter, false);

            return(existsResult.NextFeature());
        }
        private void backgroundImageSearch_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!e.Cancelled)
            {
                var featureMemberElements = e.Result as List <XElement>;

                if (featureMemberElements != null)
                {
                    string                  imageId    = txtImageId.Text;
                    GsExtension             extension  = GsExtension.GetExtension();
                    CycloMediaGroupLayer    groupLayer = extension.CycloMediaGroupLayer;
                    IList <CycloMediaLayer> layers     = groupLayer.Layers;

                    foreach (var layer in layers)
                    {
                        if (layer.IsVisible)
                        {
                            layer.SaveFeatureMembers(featureMemberElements, null);
                            IMappedFeature mappedFeature = layer.GetLocationInfo(imageId);
                            var            recording     = mappedFeature as Recording;

                            if (recording != null)
                            {
                                DateTime?   recordedAt       = recording.RecordedAt;
                                CultureInfo ci               = CultureInfo.InvariantCulture;
                                string      recordedAtString = (recordedAt == null) ? string.Empty : ((DateTime)recordedAt).ToString(ci);
                                string      imageIdString    = recording.ImageId;
                                IFeature    feature          = layer.GetFeature(imageId);
                                var         items            = new[] { imageIdString, recordedAtString };
                                var         listViewItem     = new ListViewItem(items)
                                {
                                    Tag = new object[] { feature, layer }
                                };
                                lvResults.Items.Add(listViewItem);
                            }
                        }
                    }
                }
            }

            btnFind.Enabled     = true;
            btnCancel.Enabled   = true;
            prSearching.Visible = false;
            txtImageId.Enabled  = true;
        }
        public IMappedFeature GetLocationInfo(string imageId)
        {
            IMappedFeature result         = CreateMappedFeature(null);
            var            fields         = result.Fields;
            string         shapeFieldName = result.ShapeFieldName;

            IQueryFilter filter = new QueryFilterClass
            {
                WhereClause = string.Format("ImageId = '{0}'", imageId),
                SubFields   = string.Format("{0}, {1}", fields.Aggregate(string.Empty, (current, field) => string.Format
                                                                             ("{0}{1}{2}", current, string.IsNullOrEmpty(current) ? string.Empty : ", ", field.Key)), shapeFieldName)
            };

            var      existsResult = FeatureClass.Search(filter, false);
            IFeature feature      = existsResult.NextFeature();

            // ReSharper disable UseIndexedProperty

            if (feature != null)
            {
                foreach (var field in fields)
                {
                    string name   = field.Key;
                    int    nameId = existsResult.FindField(name);
                    object item   = feature.get_Value(nameId);
                    result.UpdateItem(name, item);
                }

                var point = feature.Shape as IPoint;
                result.UpdateItem(shapeFieldName, point);
            }
            else
            {
                result = null;
            }

            // ReSharper restore UseIndexedProperty
            return(result);
        }
        // =========================================================================
        // Private Functions
        // =========================================================================
        private void AddObs(Bitmap bitmap, FrmGlobespotter frmGlobespotter, int entityId, int pointId,
                            MeasurementObservation observation)
        {
            if (_entityId != entityId)
            {
                _lastPointIdUpd = null;
            }

            string               imageId      = observation.imageId;
            GsExtension          extension    = GsExtension.GetExtension();
            CycloMediaGroupLayer groupLayer   = extension.CycloMediaGroupLayer;
            IMappedFeature       locationInfo = groupLayer.GetLocationInfo(imageId);
            var    recordingInfo = locationInfo as Recording;
            double stdX          = (recordingInfo == null) ? 0 : (recordingInfo.LongitudePrecision ?? 0);
            double stdY          = (recordingInfo == null) ? 0 : (recordingInfo.LatitudePrecision ?? 0);
            double stdZ          = (recordingInfo == null) ? 0 : (recordingInfo.HeightPrecision ?? 0);
            string std           = string.Format("{0:0.00} {1:0.00} {2:0.00}", stdX, stdY, stdZ);

            if ((_entityId != entityId) || (_pointId != pointId))
            {
                ClearForm(false);
                _entityId           = entityId;
                _pointId            = pointId;
                _measurementPoint   = null;
                _measurementPointS  = null;
                txtNumber.Text      = string.Empty;
                txtPosition.Text    = string.Empty;
                txtPositionStd.Text = string.Empty;
                RelO.Image          = null;
                SetOpenClose(false);
            }

            Measurement measurement = Measurement.Get(_entityId);

            if (measurement != null)
            {
                _measurementPointS = measurement[_pointId];
                _measurementPointS.UpdateObservation(imageId, observation.x, observation.y, observation.z);
                txtNumber.Text = _measurementPointS.M.ToString(_ci);

                if (measurement.IsPointMeasurement)
                {
                    SetOpenClose(true);

                    if (_commandItem == null)
                    {
                        _commandItem = ArcMap.Application.CurrentTool;
                        ArcUtils.SetToolActiveInToolBar("esriEditor.EditTool");
                    }
                }
            }

            if (bitmap != null)
            {
                _bitmapImageId.Add(imageId);
                _idBitmap.Add(bitmap);
            }

            bool add = true;

            foreach (ListViewItem item in lvObservations.Items)
            {
                var obs = item.Tag as MeasurementObservation;

                if (obs != null)
                {
                    if (obs.imageId == imageId)
                    {
                        add = false;
                    }
                }
            }

            if (add)
            {
                _frmGlobespotter = frmGlobespotter;
                var items        = new[] { imageId, std, "X" };
                var listViewItem = new ListViewItem(items)
                {
                    Tag = observation
                };
                lvObservations.Items.Add(listViewItem);
                DrawObservations();
                RedrawObservationList();
            }
        }
 protected override bool Filter(IMappedFeature mappedFeature)
 {
     return(true);
 }
        /// <summary>
        /// Saves the spatial and attribute data to a geodatabase.
        /// </summary>
        /// <param name="featureMemberElements">The root node of the feature element list</param>
        /// <param name="envelope"></param>
        public void SaveFeatureMembers(IEnumerable <XElement> featureMemberElements, IEnvelope envelope)
        {
            // ReSharper disable PossibleMultipleEnumeration

            if ((featureMemberElements != null) && featureMemberElements.Any())
            {
                if (FeatureClass == null)
                {
                    IMappedFeature feature = CreateMappedFeature(null);
                    XName          name    = feature.Name;

                    foreach (var featureMemberElement in featureMemberElements)
                    {
                        IEnumerable <XElement> mappedFeatureElements = featureMemberElement.Descendants(name);

                        foreach (var mappedFeatureElement in mappedFeatureElements)
                        {
                            CreateMappedFeature(mappedFeatureElement);
                        }
                    }

                    if (FeatureClass != null)
                    {
                        var featureLayer = _layer as FeatureLayer;

                        if (featureLayer != null)
                        {
                            featureLayer.FeatureClass = FeatureClass;
                        }
                    }
                }

                IMappedFeature    mapFeature          = CreateMappedFeature(null);
                var               fieldIds            = mapFeature.Fields.ToDictionary(field => FeatureClass.FindField(field.Key), field => field.Key);
                string            idField             = mapFeature.ObjectId;
                XName             objectName          = mapFeature.Name;
                IFeatureWorkspace featureWorkspace    = _cycloMediaGroupLayer.FeatureWorkspace;
                var               workspaceEdit       = featureWorkspace as IWorkspaceEdit;
                var               spatialCacheManager = featureWorkspace as ISpatialCacheManager3;

                if (workspaceEdit != null)
                {
                    var exists = new Dictionary <string, IFeature>();

                    if (FeatureClass != null)
                    {
                        ISpatialFilter spatialFilter = new SpatialFilterClass
                        {
                            Geometry      = envelope,
                            GeometryField = FeatureClass.ShapeFieldName,
                            SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains,
                            SubFields     = idField
                        };

                        workspaceEdit.StartEditing(false);
                        var existsResult = FeatureClass.Search(spatialFilter, false);
                        var existsCount  = FeatureClass.FeatureCount(spatialFilter);
                        var imId         = existsResult.FindField(idField);
                        // ReSharper disable UseIndexedProperty

                        for (int i = 0; i < existsCount; i++)
                        {
                            IFeature feature  = existsResult.NextFeature();
                            var      recValue = feature.get_Value(imId) as string;

                            if ((recValue != null) && (!exists.ContainsKey(recValue)))
                            {
                                exists.Add(recValue, feature);
                            }
                        }
                    }

                    if (FeatureClass != null)
                    {
                        foreach (XElement featureMemberElement in featureMemberElements)
                        {
                            IEnumerable <XElement> mappedFeatureElements = featureMemberElement.Descendants(objectName);

                            foreach (var mappedFeatureElement in mappedFeatureElements)
                            {
                                IMappedFeature mappedFeature = CreateMappedFeature(mappedFeatureElement);

                                if (mappedFeature.Shape != null)
                                {
                                    if (mappedFeature.Shape.Type == ShapeType.Point)
                                    {
                                        if (!exists.ContainsKey((string)mappedFeature.FieldToItem(idField)))
                                        {
                                            var shapePoint = mappedFeature.Shape as ShapePoint;

                                            if ((shapePoint != null) && Filter(mappedFeature))
                                            {
                                                IPoint point = new Point();
                                                point.PutCoords(shapePoint.X, shapePoint.Y);
                                                IFeature feature = FeatureClass.CreateFeature();
                                                feature.Shape = point;

                                                foreach (var fieldId in fieldIds)
                                                {
                                                    feature.set_Value(fieldId.Key, mappedFeature.FieldToItem(fieldId.Value));
                                                }

                                                feature.Store();
                                            }
                                        }
                                        else
                                        {
                                            if (Filter(mappedFeature))
                                            {
                                                exists.Remove((string)mappedFeature.FieldToItem(idField));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    foreach (var feature in exists)
                    {
                        feature.Value.Delete();
                    }

                    workspaceEdit.StopEditing(true);

                    if ((spatialCacheManager != null) && (envelope != null))
                    {
                        spatialCacheManager.FillCache(envelope);
                    }
                    // ReSharper restore UseIndexedProperty
                }
            }

            // ReSharper restore PossibleMultipleEnumeration
        }
 protected abstract bool Filter(IMappedFeature mappedFeature);