Exemplo n.º 1
0
 /// <summary>
 /// Retrieves the demographics and other relevant 
 /// characteristics associated with the surrounding area.
 /// </summary>
 /// <param name="parameters">input parameters to Geoenrichment Service.</param>
 /// <param name="userToken">user token.</param>
 public void ExecuteAsync(GeoenrichmentParameter parameters, object userToken = null)
 {
     // Web requests made through ArcGISWebClient takes advantage of the IdentityManager.
     var client = new ArcGISWebClient();
     client.DownloadStringCompleted += (s, e) =>
     {
         if (e.Cancelled)
             OnExecuteCompleted(new GeoenrichmentEventArgs(new OperationCanceledException(), e.UserState));
         else if (e.Error != null)
             OnExecuteCompleted(new GeoenrichmentEventArgs(e.Error, e.UserState));
         else
         {
             var json = e.Result;
             var serviceException = ServiceException.FromJson(json);
             if(serviceException != null)
                 OnExecuteCompleted(new GeoenrichmentEventArgs(serviceException, e.UserState));
             OnExecuteCompleted(new GeoenrichmentEventArgs(GeoenrichmentResult.FromJson(json), e.UserState));
         }
     };
     client.DownloadStringAsync(new Uri(string.Format("{0}/enrich", ServiceUrl)),
         parameters.GetParameters(),
         ArcGISWebClient.HttpMethods.Auto, userToken);
 }
Exemplo n.º 2
0
        private void RunGeoenrichmentTask(MapPoint mp)
        {
            MyProgressBar.IsIndeterminate = true;
            var task = new GeoenrichmentTask(GEOENRICHMENT_URL);

            task.ExecuteCompleted += (s, e) =>
            {
                MyProgressBar.IsIndeterminate = false;
                if (e.Error != null)
                    MessageBox.Show(string.Format("GeoEnrichmentTask Failed with error: '{0}'", e.Error.Message));

                else if (e.Result != null &&
                    e.Result.Results != null
                    && e.Result.Results.Count > 0)
                {
                    var result = e.Result.Results.FirstOrDefault();
                    if (result.FeatureSets != null && result.FeatureSets.Count > 0)
                    {
                        var featureSet = result.FeatureSets.FirstOrDefault();
                        if (featureSet.Features != null && featureSet.Features.Count > 0)
                        {
                            var graphic = featureSet.Features.FirstOrDefault();
                            UpdateChart(graphic.Attributes, featureSet.Fields);
                        }
                    }
                }
            };

            var parameters = new GeoenrichmentParameter()
            {
                OutSpatialReference = MyMap.SpatialReference,
                StudyAreaOptions = new StudyAreaOptions()
                {
                    AreaType = "RingBuffer",
                    BufferUnits = "esriMiles",
                    BufferRadii = new int[] { 1 }
                },
                UseData = new UseData() { SourceCountry = "US" }
            };
            parameters.StudyAreas.Add(new Graphic() { Geometry = mp });
            parameters.DataCollections.Add("HouseholdsByIncome");
            parameters.IntersectingGeographies.Add(new IntersectingGeography()
            {
                GeographyLayer = "US.Counties",
                SourceCountry = "US"
            });
            parameters.IntersectingGeographies.Add(new IntersectingGeography()
            {
                GeographyLayer = "US.States",
                SourceCountry = "US"
            });
            task.ExecuteAsync(parameters);
        }