Example #1
0
        // Accept user boundary line and run the Geoprocessing Task to summarize population
        private async void SummarizePopulationButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtResult.Visibility = System.Windows.Visibility.Collapsed;
                AreaLayer.Graphics.Clear();

                var boundary = await mapView.Editor.RequestShapeAsync(DrawShape.Freehand) as Polyline;

                var polygon = new Polygon(boundary, mapView.SpatialReference);
                polygon = GeometryEngine.Simplify(polygon) as Polygon;
                AreaLayer.Graphics.Add(new Graphic()
                {
                    Geometry = polygon
                });

                progress.Visibility = Visibility.Visible;

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/GPServer/PopulationSummary"));

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = mapView.SpatialReference
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("inputPoly", polygon));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                GPRecordSet rs = result.OutParameters.OfType <GPRecordSet>().FirstOrDefault();
                if (rs != null && rs.FeatureSet.Features != null)
                {
                    int population = Convert.ToInt32(rs.FeatureSet.Features[0].Attributes["SUM"]);
                    txtResult.Visibility = System.Windows.Visibility.Visible;
                    txtResult.Text       = string.Format("Area Population: {0:N0}", population);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Geoprocessor service failed: " + ex.Message, "Sample Error");
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        // Accept user boundary line and run the Geoprocessing Task to summarize population
        private async void SummarizePopulationButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtResult.Visibility = Visibility.Collapsed;
                _areaOverlay.Graphics.Clear();

                var boundary = await MyMapView.Editor.RequestShapeAsync(DrawShape.Freehand) as Polyline;

                var polygon = new Polygon(boundary.Parts, MyMapView.SpatialReference);
                polygon = GeometryEngine.Simplify(polygon) as Polygon;
                _areaOverlay.Graphics.Add(new Graphic()
                {
                    Geometry = polygon
                });

                progress.Visibility = Visibility.Visible;

                Geoprocessor geoprocessorTask = new Geoprocessor(new Uri(PopulationSummaryServiceUrl));

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = MyMapView.SpatialReference
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("inputPoly", polygon));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                GPRecordSet rs = result.OutParameters.OfType <GPRecordSet>().FirstOrDefault();
                if (rs != null && rs.FeatureSet.Features != null)
                {
                    int population = Convert.ToInt32(rs.FeatureSet.Features[0].Attributes["SUM"]);
                    txtResult.Visibility = Visibility.Visible;
                    txtResult.Text       = string.Format("Area Population: {0:N0}", population);
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
Example #3
0
        /// <summary>
        /// Method converts breaks from routes to GPRecordSet.
        /// </summary>
        /// <param name="routes">Routes collection to get breaks.</param>
        /// <param name="addSequence">Flag, showing that we must
        /// add sequence attribute to break gp feature.</param>
        /// <returns>Breaks GPRecordSet.</returns>
        public GPRecordSet ConvertBreaks(ICollection <Route> routes, bool addSequence)
        {
            Debug.Assert(routes != null);

            List <GPFeature> features = new List <GPFeature>();

            // Convert all breaks for every route to GP Features.
            foreach (Route route in routes)
            {
                Breaks breaks = (Breaks)route.Breaks.Clone();
                features.AddRange(_ConvertToGPBreaks(breaks, route, addSequence));
            }

            GPRecordSet rs = null;

            if (features.Count > 0)
            {
                rs          = new GPRecordSet();
                rs.Features = features.ToArray();
            }

            return(rs);
        }
Example #4
0
        public static string ParameterToString(GPParameterType type, GPParameter param, CultureInfo culture)
        {
            if (param == null)
            {
                return(string.Empty);
            }
            switch (type)
            {
            case GPParameterType.Boolean:
                GPBoolean boo = param as GPBoolean;
                if (boo != null)
                {
                    return(boo.Value.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Date:
                GPDate date = param as GPDate;
                if (date != null && date.Value != null)
                {
                    return(date.Value.Ticks.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Double:
                GPDouble dub = param as GPDouble;
                if (dub != null && !double.IsNaN(dub.Value))
                {
                    return(dub.Value.ToString(culture));
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Long:
                GPLong lon = param as GPLong;
                if (lon != null)
                {
                    return(lon.Value.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.String:
                GPString stir = param as GPString;
                if (stir != null && stir.Value != null)
                {
                    return(stir.Value);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.FeatureLayer:
                GPFeatureRecordSetLayer feat = param as GPFeatureRecordSetLayer;
                if (feat != null && feat.Url != null)
                {
                    return(feat.Url);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.RecordSet:
                GPRecordSet rsl = param as GPRecordSet;
                if (rsl != null && rsl.Url != null)
                {
                    return(rsl.Url);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.DataFile:
                GPDataFile dat = param as GPDataFile;
                if (dat != null && dat.Url != null)
                {
                    return(dat.Url);
                }
                else
                {
                    return(string.Empty);
                }
            }
            return(string.Empty);
        }
        private void BuildUI()
        {
            if (ParamContainer == null || ParameterConfigs == null ||
                ParameterConfigs.Count < 1)
            {
                return;
            }
            if ((Results == null || Results.Count < 1) && (Errors == null || Errors.Count < 1))
            {
                return;
            }
            if (!inputLayerInfoAvailable())
            {
                return;
            }
            ParamContainer.Children.Clear();
            ParamContainer.ColumnDefinitions.Clear();
            ParamContainer.RowDefinitions.Clear();
            ParamContainer.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            ParamContainer.ColumnDefinitions.Add(new ColumnDefinition()); // { Width = new GridLength(0, GridUnitType.Star) });
            HasSimpleResults       = false;
            layerParamNameIDLookup = InputLayers != null ?
                                     new Dictionary <string, string>(InputLayers) : new Dictionary <string, string>();
            int pendingGPResultImageLayers = 0;

            #region Results
            if (Results != null && Results.Count > 0)
            {
                #region GP mapserver result
                MapServiceLayerParameterConfig mapServiceLayerParameterConfig = ParameterConfigs.FirstOrDefault(p => p.Type == GPParameterType.MapServiceLayer) as MapServiceLayerParameterConfig;
                if (mapServiceLayerParameterConfig != null && mapServiceLayerParameterConfig.SupportsJobResource)
                {
                    string t   = "/rest/services/";
                    string url = string.Format("{0}/{1}/MapServer/jobs/{2}", TaskUrl.Substring(0, TaskUrl.IndexOf(t, StringComparison.OrdinalIgnoreCase) + t.Length - 1), mapServiceLayerParameterConfig.Name, JobID);

                    ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer
                    {
                        Url      = url,
                        ProxyURL = UseProxy ? ProxyUrl : null
                    };
                    layer.SetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.ExcludeSerializationProperty, true);
                    addToMap(mapServiceLayerParameterConfig, layer);
                }
                #endregion

                #region display each result
                foreach (ParameterConfig config in ParameterConfigs)
                {
                    MapServiceLayerParameterConfig cfg;
                    if (config.Type == GPParameterType.MapServiceLayer && (cfg = config as MapServiceLayerParameterConfig) != null && !cfg.SupportsJobResource)
                    {
                        pendingGPResultImageLayers++;
                        Geoprocessor gp = new Geoprocessor(TaskUrl);
                        gp.OutputSpatialReference        = Map.SpatialReference.Clone();
                        gp.GetResultImageLayerCompleted += (s, e) =>
                        {
                            GPResultImageLayer gpImageLayer = e.GPResultImageLayer;
                            setLayerProps(cfg, gpImageLayer);
                            gpImageLayer.ProxyUrl = UseProxy ? ProxyUrl : null;
                            Map.Layers.Add(gpImageLayer);
                            layerParamNameIDLookup.Add(cfg.Name, gpImageLayer.ID);
                            pendingGPResultImageLayers--;
                            if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers == 0)
                            {
                                LayerOrderer.OrderLayers(Map, LayerOrder, layerParamNameIDLookup);
                            }
                        };
                        // Initialize proxy
                        gp.ProxyURL = UseProxy ? ProxyUrl : null;
                        gp.GetResultImageLayerAsync(JobID, cfg.Name);
                        continue;
                    }

                    GPParameter param = getParameter(config.Name);
                    if (param == null)
                    {
                        continue;
                    }
                    string value = ParameterBase.ParameterToDisplayString(config.Type, param);

                    switch (config.Type)
                    {
                    case GPParameterType.Boolean:
                    case GPParameterType.Double:
                    case GPParameterType.Long:
                    case GPParameterType.String:
                    case GPParameterType.Date:
                    case GPParameterType.LinearUnit:
                        if (value == null)
                        {
                            value = string.Empty;
                        }
                        addparamUI(config.Label, value, false);
                        break;

                    case GPParameterType.FeatureLayer:
                        addToMap(param as GPFeatureRecordSetLayer, config);
                        break;

                    case GPParameterType.RecordSet:
                        if (string.IsNullOrEmpty(value) && param is GPRecordSet)
                        {
                            GPRecordSet rs = param as GPRecordSet;
                            if (string.IsNullOrEmpty(rs.Url) && rs.FeatureSet != null)
                            {
                                value = ESRI.ArcGIS.Mapping.GP.Resources.Strings.OnlyUrlOutputIsSupportedForRecordsets;
                            }
                            else
                            {
                                value = string.Empty;
                            }
                            addparamUI(config.Label, value, false);
                        }
                        else
                        {
                            addparamUI(config.Label, value, true);
                        }
                        break;

                    case GPParameterType.DataFile:
                    case GPParameterType.RasterData:
                    case GPParameterType.RasterDataLayer:
                        if (value == null)
                        {
                            value = string.Empty;
                        }
                        addparamUI(config.Label, value, true);
                        break;
                    }
                }
                #endregion

                if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers == 0)
                {
                    LayerOrderer.OrderLayers(Map, LayerOrder, layerParamNameIDLookup);
                }
            }
            #endregion

            #region Errors
            if (Errors != null && Errors.Count > 0)
            {
                foreach (Exception error in Errors)
                {
                    addparamUI(ESRI.ArcGIS.Mapping.GP.Resources.Strings.LabelError + " ", error.Message, false);
                    HasSimpleResults = true;
                }
            }
            #endregion
        }