Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Basics on how to use the api helper
            HttpResponseMessage msg = null;

            //todo: insert your segment key here
            BasicSegmentAnalyticsSender sender = new BasicSegmentAnalyticsSender("4H8F7Umac25FLQfpDqWLSbCDvFxfASBj");
            Thread t = new Thread(async() =>
            {
                // Create your analytics item object
                var identifyItem = new IdentifyItem("my_user", DateTime.UtcNow, null, new Dictionary <string, object>
                {
                    { "locale", "en-US" }
                }, new Dictionary <string, object>()
                {
                    { "All", true }
                }, new Dictionary <string, object>
                {
                    { "trait", 1 }
                });

                //and wait for the send!
                msg = await sender.SendData(identifyItem);
            });

            t.Start();
            t.Join();
            Console.ReadLine();
        }
Exemplo n.º 2
0
        private static IdentifyFeature ReplaceAliasWithFieldName(IdentifyItem identifyItem, IReadOnlyList <FieldInfo> fields)
        {
            if (identifyItem == null || identifyItem.Feature == null || identifyItem.Feature.Attributes == null || fields == null || !fields.Any())
            {
                return(new IdentifyFeature(identifyItem));
            }

            var identifyFeature = new IdentifyFeature(identifyItem);
            var attr            = identifyItem.Feature.Attributes;

            foreach (var field in fields)
            {
                var key = attr.Keys.FirstOrDefault(k => k == field.Alias && k != field.Name);
                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }
                attr[field.Name] = attr[key];
                attr.Remove(key);
                if (identifyItem.DisplayFieldName == key)
                {
                    identifyFeature = new IdentifyFeature(new IdentifyItem(identifyItem.LayerID,
                                                                           identifyItem.LayerName, field.Name, identifyItem.Value, identifyItem.Feature));
                }
            }
            return(identifyFeature);
        }
Exemplo n.º 3
0
        public void SendIdentifyItem()
        {
            var identifyItem = new IdentifyItem("my_user", DateTime.UtcNow, null, new Dictionary <string, object>
            {
                { "locale", "en-US" }
            }, new Dictionary <string, object>()
            {
                { "All", true }
            }, new Dictionary <string, object>
            {
                { "trait", 1 }
            });

            Assert.DoesNotThrowAsync(() => _passableSender.SendData(identifyItem));
        }
Exemplo n.º 4
0
    public static void readFile(string Filename)
    {
        string path;

        path = @"/Users/VDC/Documents/tmp/" + Filename;

        using (StreamReader sr = new StreamReader(path)) {
            string line;
            // Read and display lines from the file until the end of
            // the file is reached.

            while ((line = sr.ReadLine()) != null)
            {
                Debug.Log(line);
                line = line.Replace("(", "");
                line = line.Replace(")", "");
                string[] tmp = line.Split(',');
                IdentifyItem.relocateObject(tmp);
            }
        }
    }
Exemplo n.º 5
0
        private static async Task <IReadOnlyList <FieldInfo> > GetFieldInfo(Layer l, IdentifyItem item)
        {
            if (l == null || item == null || item.LayerID == -1)
            {
                return(null);
            }

            if (l is ArcGISDynamicMapServiceLayer)
            {
                var dynamicLayer = (ArcGISDynamicMapServiceLayer)l;
                var layerinfo    = await dynamicLayer.GetDetailsAsync(item.LayerID);

                return(layerinfo != null ? layerinfo.Fields : null);
            }
            if (l is ArcGISTiledMapServiceLayer)
            {
                var tiledLayer = (ArcGISTiledMapServiceLayer)l;
                var layerinfo  = await tiledLayer.GetDetailsAsync(item.LayerID);

                return(layerinfo != null ? layerinfo.Fields : null);
            }
            return(null);
        }
Exemplo n.º 6
0
        public void ShowIdResult(IdentifyItem result)
        {
            if (result == null || result.Spec == null || result.SpecOriginal == null || result.Wind < 1)
            {
                return;
            }
            var original = result.SpecOriginal;
            var spec     = result.Spec;

            this.guetPanel1.Title = string.Format("原光谱:{0},识别光谱:{1}", original.Name, spec.Name);

            var o = original.Clone();
            var r = spec.Clone();

            o.Name = "原光谱";
            r.Name = "识别光谱";
            var specs = new Spectrum[] { o, r };

            this.specGraph2.DrawSpec(specs.ToList());
            this.specGraph2.SetTitle("预处理后光谱对比");


            double[] tSQ;
            double   tTQ;

            RIPP.NIR.Data.Tools.MWCorr(original.Data.Y, spec.Data.Y, result.Wind, out tTQ, out tSQ);

            var s = original.Clone();

            s.Data.Y = tSQ;
            s.Name   = "SQ";
            s.Color  = Color.Blue;
            this.specGraph1.DrawSpec(s);
            this.tableLayoutPanel1.RowStyles[2].Height = 0;
            this.ShowDialog();
        }
Exemplo n.º 7
0
 public nodeRow(IdentifyItem result)
 {
     this._result = result;
 }
 public void CreateNewIdentifyItem()
 {
     var passableIdentifyItem = new IdentifyItem("user");
 }
Exemplo n.º 9
0
        private static async Task <KeyValuePair <Layer, IEnumerable <IdentifyFeature> > > IdentifyLayer(MapViewController controller, Layer layer, Point tapPoint, MapPoint mapPoint)
        {
            if (layer is ArcGISDynamicMapServiceLayer)
            {
                var dynamicLayer = ((ArcGISDynamicMapServiceLayer)layer);

                if (!dynamicLayer.ServiceInfo.Capabilities.Contains("Query"))
                {
                    return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
                }

                var identifyTask = new IdentifyTask(new Uri(dynamicLayer.ServiceUri, UriKind.Absolute));

                var resolution = controller.UnitsPerPixel;
                var center     = controller.Extent.GetCenter();
                var extent     = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
                                              center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameters(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                                                               c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
                {
                    LayerOption        = LayerOption.Visible,
                    LayerTimeOptions   = dynamicLayer.LayerTimeOptions,
                    LayerIDs           = dynamicLayer.VisibleLayers,
                    DynamicLayerInfos  = dynamicLayer.DynamicLayerInfos,
                    GeodatabaseVersion = dynamicLayer.GeodatabaseVersion,
                    TimeExtent         = controller.TimeExtent,
                };
                var identifyItems    = (await identifyTask.ExecuteAsync(identifyParameter)).Results;
                var identifyFeatures = new List <IdentifyFeature>();

                try
                {
                    var dict = new Dictionary <int, IReadOnlyList <FieldInfo> >();
                    foreach (var identifyItem in identifyItems)
                    {
                        IReadOnlyList <FieldInfo> fields;
                        if (dict.ContainsKey(identifyItem.LayerID))
                        {
                            fields = dict[identifyItem.LayerID];
                        }
                        else
                        {
                            fields = await GetFieldInfo(dynamicLayer, identifyItem);

                            dict[identifyItem.LayerID] = fields;
                        }
                        var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);
                        identifyFeatures.Add(identifyFeature);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, identifyFeatures));
            }
            if (layer is ArcGISTiledMapServiceLayer)
            {
                var tiledlayer = ((ArcGISTiledMapServiceLayer)layer);
                if (!tiledlayer.ServiceInfo.Capabilities.Contains("Query"))
                {
                    return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
                }

                var identifyTask = new IdentifyTask(new Uri(tiledlayer.ServiceUri, UriKind.Absolute));
                var resolution   = controller.UnitsPerPixel;
                var center       = controller.Extent.GetCenter();
                var extent       = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
                                                center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameters(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                                                               c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
                {
                    LayerOption = LayerOption.Visible,
                    TimeExtent  = controller.TimeExtent,
                };

                var identifyItems = (await identifyTask.ExecuteAsync(identifyParameter)).Results;

                var identifyFeatures = new List <IdentifyFeature>();
                var dict             = new Dictionary <int, IReadOnlyList <FieldInfo> >();
                foreach (var identifyItem in identifyItems)
                {
                    IReadOnlyList <FieldInfo> fields;
                    if (dict.ContainsKey(identifyItem.LayerID))
                    {
                        fields = dict[identifyItem.LayerID];
                    }
                    else
                    {
                        fields = await GetFieldInfo(tiledlayer, identifyItem);

                        dict[identifyItem.LayerID] = fields;
                    }
                    var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);
                    identifyFeatures.Add(identifyFeature);
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, identifyFeatures));
            }
            if (layer is FeatureLayer)
            {
                var featureLayer = ((FeatureLayer)layer);
                var featureIds   = await controller.FeatureLayerHitTestAsync(featureLayer, tapPoint, 1000);

                IEnumerable <Feature> features = new List <Feature>();
                if (featureIds != null && featureIds.Any())
                {
                    features = await featureLayer.FeatureTable.QueryAsync(featureIds);
                }

                var schema = featureLayer.FeatureTable.Schema;
                IList <IdentifyFeature> displayFeatures = new List <IdentifyFeature>();
                foreach (var f in features)
                {
                    var             objectIDFieldName  = schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name;
                    var             objectIDFieldValue = f.Attributes[objectIDFieldName].ToString();
                    IdentifyItem    identifyItem       = new IdentifyItem(-1, featureLayer.DisplayName, objectIDFieldName, objectIDFieldValue, f);
                    IdentifyFeature identifyFeature    = new IdentifyFeature(identifyItem, schema.Fields);
                    displayFeatures.Add(identifyFeature);
                }
                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, displayFeatures));
            }
            if (layer is GraphicsLayer)
            {
                var graphicsLayer = ((GraphicsLayer)layer);
                var graphics      = await controller.GraphicsLayerHitTestAsync(graphicsLayer, tapPoint, 1000);

                return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, graphics.Select(f => new IdentifyFeature(new IdentifyItem(
                                                                                                                                    -1,
                                                                                                                                    layer.DisplayName,
                                                                                                                                    "",
                                                                                                                                    "",
                                                                                                                                    f
                                                                                                                                    )))));
            }

            // Not supported or not implemented yet
            return(new KeyValuePair <Layer, IEnumerable <IdentifyFeature> >(layer, null));
        }
Exemplo n.º 10
0
 public IdentifyFeature(IdentifyItem item, IEnumerable <FieldInfo> fields) : this(item)
 {
     Fields = fields;
 }
Exemplo n.º 11
0
 public IdentifyFeature(IdentifyItem item)
 {
     Item = item;
 }
        private static async Task<KeyValuePair<Layer,IEnumerable<IdentifyFeature>>> IdentifyLayer(MapViewController controller, Layer layer, Point tapPoint, MapPoint mapPoint)
        {
            if (layer is ArcGISDynamicMapServiceLayer)
            {
                var dynamicLayer = ((ArcGISDynamicMapServiceLayer)layer);
                
                if (!dynamicLayer.ServiceInfo.Capabilities.Contains("Query"))                
                    return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, null);
                
                var identifyTask = new IdentifyTask(new Uri(dynamicLayer.ServiceUri, UriKind.Absolute));

				var resolution = controller.UnitsPerPixel;
				var center = controller.Extent.GetCenter();
				var extent = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
					center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameters(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                    c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
				{
                    LayerOption = LayerOption.Visible,
                    LayerTimeOptions = dynamicLayer.LayerTimeOptions,
                    LayerIDs = dynamicLayer.VisibleLayers,
                    DynamicLayerInfos = dynamicLayer.DynamicLayerInfos,
                    GeodatabaseVersion = dynamicLayer.GeodatabaseVersion,
                    TimeExtent = controller.TimeExtent,
                };
                var identifyItems = (await identifyTask.ExecuteAsync(identifyParameter)).Results;
                var identifyFeatures = new List<IdentifyFeature>();

                try
                {
                    var dict = new Dictionary<int, IReadOnlyList<FieldInfo>>();
                    foreach (var identifyItem in identifyItems)
                    {
                        IReadOnlyList<FieldInfo> fields;
                        if(dict.ContainsKey(identifyItem.LayerID))
                            fields = dict[identifyItem.LayerID];
                        else
                        {
                            fields = await GetFieldInfo(dynamicLayer, identifyItem);                            
                            dict[identifyItem.LayerID] = fields;
                        }                        
                        var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);                        
                        identifyFeatures.Add(identifyFeature);
                    }

                }
                catch (Exception ex)
                {
                    
                    throw;
                }
                return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, identifyFeatures);
            }
            if (layer is ArcGISTiledMapServiceLayer)
            {
                var tiledlayer = ((ArcGISTiledMapServiceLayer) layer);
                if (!tiledlayer.ServiceInfo.Capabilities.Contains("Query"))
                    return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, null);

                var identifyTask = new IdentifyTask(new Uri(tiledlayer.ServiceUri, UriKind.Absolute));
				var resolution = controller.UnitsPerPixel;
				var center = controller.Extent.GetCenter();
				var extent = new Envelope(center.X - resolution * c_defaultTolerance, center.Y - resolution * c_defaultTolerance,
					center.X + resolution * c_defaultTolerance, center.Y + resolution * c_defaultTolerance, controller.SpatialReference);
                var identifyParameter = new IdentifyParameters(mapPoint, extent, c_defaultTolerance, c_defaultTolerance,
                    c_defaultTolerance, DisplayInformation.GetForCurrentView().LogicalDpi)
                {
                    LayerOption = LayerOption.Visible,                    
                    TimeExtent = controller.TimeExtent,
                };

                var identifyItems = (await identifyTask.ExecuteAsync(identifyParameter)).Results;
                
                var identifyFeatures = new List<IdentifyFeature>();
                var dict = new Dictionary<int, IReadOnlyList<FieldInfo>>();
                foreach (var identifyItem in identifyItems)
                {
                    IReadOnlyList<FieldInfo> fields;
                    if (dict.ContainsKey(identifyItem.LayerID))
                        fields = dict[identifyItem.LayerID];
                    else
                    {
                        fields = await GetFieldInfo(tiledlayer, identifyItem);
                        dict[identifyItem.LayerID] = fields;
                    }
                    var identifyFeature = ReplaceAliasWithFieldName(identifyItem, fields);
                    identifyFeatures.Add(identifyFeature);
                }                                           
                return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, identifyFeatures);
            }
            if (layer is FeatureLayer)
            {
                var featureLayer = ((FeatureLayer)layer);
                var featureIds = await controller.FeatureLayerHitTestAsync(featureLayer, tapPoint, 1000);
                IEnumerable<Feature> features = new List<Feature>();
                if (featureIds != null && featureIds.Any())
                    features = await featureLayer.FeatureTable.QueryAsync(featureIds);

                var schema = featureLayer.FeatureTable.Schema;
                IList<IdentifyFeature> displayFeatures = new List<IdentifyFeature>();
                foreach (var f in features)
                {
                    var objectIDFieldName = schema.Fields.FirstOrDefault(x => x.Type == FieldType.Oid).Name;
                    var objectIDFieldValue = f.Attributes[objectIDFieldName].ToString();
                    IdentifyItem identifyItem = new IdentifyItem(-1, featureLayer.DisplayName, objectIDFieldName, objectIDFieldValue, f);
                    IdentifyFeature identifyFeature = new IdentifyFeature(identifyItem, schema.Fields);
                    displayFeatures.Add(identifyFeature);
                }
                return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, displayFeatures);
            }
            if (layer is GraphicsLayer)
            {
                var graphicsLayer = ((GraphicsLayer) layer);
                var graphics = await controller.GraphicsLayerHitTestAsync(graphicsLayer, tapPoint, 1000);                
                return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer, graphics.Select(f => new IdentifyFeature(new IdentifyItem(
                    -1, 
                    layer.DisplayName,
                    "",
                    "",
                    f
                    ))));
            }

            // Not supported or not implemented yet
            return new KeyValuePair<Layer, IEnumerable<IdentifyFeature>>(layer,null);
        }
 public IdentifyFeature(IdentifyItem item, IEnumerable<FieldInfo> fields) : this(item)
 {
     Fields = fields;
 }
 public IdentifyFeature(IdentifyItem item)
 {
     Item = item;
 }
        private static async Task<IReadOnlyList<FieldInfo>> GetFieldInfo(Layer l, IdentifyItem item)
        {
            if (l == null || item == null || item.LayerID == -1)
                return null;

            if (l is ArcGISDynamicMapServiceLayer)
            {
                var dynamicLayer = (ArcGISDynamicMapServiceLayer)l;
                var layerinfo = await dynamicLayer.GetDetailsAsync(item.LayerID);
                return layerinfo != null ? layerinfo.Fields : null;
            }
            if (l is ArcGISTiledMapServiceLayer)
            {
                var tiledLayer = (ArcGISTiledMapServiceLayer)l;
                var layerinfo = await tiledLayer.GetDetailsAsync(item.LayerID);
                return layerinfo != null ? layerinfo.Fields : null;
            }
            return null;
        }
        private static IdentifyFeature ReplaceAliasWithFieldName(IdentifyItem identifyItem, IReadOnlyList<FieldInfo> fields)
        {
            if (identifyItem == null || identifyItem.Feature == null || identifyItem.Feature.Attributes == null || fields == null || !fields.Any())
                return new IdentifyFeature(identifyItem);

            var identifyFeature = new IdentifyFeature(identifyItem);
            var attr = identifyItem.Feature.Attributes;
            foreach (var field in fields)
            {
                var key = attr.Keys.FirstOrDefault(k => k == field.Alias && k != field.Name);
                if (string.IsNullOrEmpty(key)) continue;
                attr[field.Name] = attr[key];
                attr.Remove(key);
                if (identifyItem.DisplayFieldName == key)
                    identifyFeature = new IdentifyFeature(new IdentifyItem(identifyItem.LayerID,
                        identifyItem.LayerName, field.Name, identifyItem.Value, identifyItem.Feature));
            }
            return identifyFeature;
        }