// Use geoprocessor to call drive times gp service and display results
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;

                _inputOverlay.Graphics.Clear();

                _inputOverlay.Graphics.Add(new Graphic(e.Location));

                var parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.Location));
                parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

                var result = await _gpTask.ExecuteAsync(parameter);

                var features = result.OutParameters.OfType<GPFeatureRecordSetLayer>().First().FeatureSet.Features;

                _resultsOverlay.Graphics.Clear();

                _resultsOverlay.Graphics.AddRange(features.Select((fs, idx) => new Graphic(fs.Geometry, _bufferSymbols[idx])));
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        // Use geoprocessor to call drive times gp service and display results
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;

                _inputOverlay.Graphics.Clear();

                _inputOverlay.Graphics.Add(new Graphic(e.Location));

                var parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.Location));
                parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

                var result = await _gpTask.ExecuteAsync(parameter);

                var features = result.OutParameters.OfType <GPFeatureRecordSetLayer>().First().FeatureSet.Features;

                _resultsOverlay.Graphics.Clear();

                _resultsOverlay.Graphics.AddRange(features.Select((fs, idx) => new Graphic(fs.Geometry, _bufferSymbols[idx])));
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        // Get the users input line on the map and fire off a GP Job to clip features
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
			try
			{
				uiPanel.IsEnabled = false;
				_inputOverlay.Graphics.Clear();
				_resultsOverlay.Graphics.Clear();

				foreach (var lyr in MyMapView.Map.Layers.OfType<GPResultImageLayer>())
					MyMapView.Map.Layers.Remove(lyr);

				//get the user's input line
				var inputLine = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polyline) as Polyline;

				progress.Visibility = Visibility.Visible;
				_inputOverlay.Graphics.Add(new Graphic() { Geometry = inputLine });

				var parameter = new GPInputParameter();
				parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputLine));
				parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, Int32.Parse(txtMiles.Text)));

				var result = await SubmitAndPollStatusAsync(parameter);

				if (result.JobStatus == GPJobStatus.Succeeded)
				{
					txtStatus.Text = "Finished processing. Retrieving results...";

					var resultData = await _gpTask.GetResultDataAsync(result.JobID, "Clipped_Counties");
					if (resultData is GPFeatureRecordSetLayer)
					{
						GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
						if (gpLayer.FeatureSet.Features.Count == 0)
						{
							var resultImageLayer = await _gpTask.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

							GPResultImageLayer gpImageLayer = resultImageLayer;
							gpImageLayer.Opacity = 0.5;
							MyMapView.Map.Layers.Add(gpImageLayer);
							txtStatus.Text = "Greater than 500 features returned.  Results drawn using map service.";
							return;
						}

						_resultsOverlay.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType<Graphic>());
					}
				}
			}
			catch (TaskCanceledException) { }
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "Sample Error");
			}
            finally
            {
                uiPanel.IsEnabled = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            // Convert screen point to map point
            var mapPoint = MyMapView.ScreenToLocation(e.Position);
            var layer    = MyMapView.Map.Layers["InputLayer"] as GraphicsLayer;

            layer.Graphics.Clear();
            layer.Graphics.Add(new Graphic()
            {
                Geometry = mapPoint
            });

            string       error = null;
            Geoprocessor task  = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons"));

            var parameter = new GPInputParameter();

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", mapPoint));
            parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

            try
            {
                var result = await task.ExecuteAsync(parameter);

                var r = MyMapView.Map.Layers["ResultLayer"] as GraphicsLayer;
                r.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        List <Esri.ArcGISRuntime.Symbology.Symbol> bufferSymbols = new List <Esri.ArcGISRuntime.Symbology.Symbol>(
                            new Esri.ArcGISRuntime.Symbology.Symbol[] { LayoutRoot.Resources["FillSymbol1"] as Esri.ArcGISRuntime.Symbology.Symbol,
                                                                        LayoutRoot.Resources["FillSymbol2"] as Esri.ArcGISRuntime.Symbology.Symbol,
                                                                        LayoutRoot.Resources["FillSymbol3"] as Esri.ArcGISRuntime.Symbology.Symbol });

                        int count = 0;
                        foreach (Graphic graphic in gpLayer.FeatureSet.Features)
                        {
                            graphic.Symbol = bufferSymbols[count];
                            graphic.Attributes.Add("Info", String.Format("{0} minute buffer ", 3 - count));
                            r.Graphics.Add(graphic);
                            count++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                error = "Geoprocessor service failed: " + ex.Message;
            }
            if (error != null)
            {
                await new MessageDialog(error).ShowAsync();
            }
        }
Exemplo n.º 5
0
        public async void Clip()
        {
            //get the user's input line
            var inputLine = await this.mapView.Editor.RequestShapeAsync(DrawShape.Polyline) as Polyline;

            // clear the graphics layers
            this.resultGraphicsLayer.Graphics.Clear();
            this.inputGraphicsLayer.Graphics.Clear();

            // add new graphic to layer
            this.inputGraphicsLayer.Graphics.Add(new Graphic {
                Geometry = inputLine, Symbol = this.simpleInputLineSymbol
            });

            // add the parameters
            var parameter = new GPInputParameter();

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputLine));
            parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, this.Distance));

            // poll the task
            var result = await SubmitAndPollStatusAsync(parameter);

            // add successful results to the map
            if (result.JobStatus == GPJobStatus.Succeeded)
            {
                this.Status = "Finished processing. Retrieving results...";

                var resultData = await gpTask.GetResultDataAsync(result.JobID, "Clipped_Counties");

                if (resultData is GPFeatureRecordSetLayer)
                {
                    GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                    if (gpLayer.FeatureSet.Features.Count == 0)
                    {
                        // the the map service results
                        var resultImageLayer = await gpTask.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

                        // make the result image layer opaque
                        GPResultImageLayer gpImageLayer = resultImageLayer;
                        gpImageLayer.Opacity = 0.5;
                        this.mapView.Map.Layers.Add(gpImageLayer);
                        this.Status = "Greater than 500 features returned.  Results drawn using map service.";
                        return;
                    }

                    // get the result features and add them to the GraphicsLayer
                    var features = gpLayer.FeatureSet.Features;
                    foreach (Feature feature in features)
                    {
                        this.resultGraphicsLayer.Graphics.Add(feature as Graphic);
                    }
                }
                this.Status = "Success!!!";
            }
        }
        // Get the users click point on the map and fire off a GP Job to calculate the viewshed
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
                inputLayer.Graphics.Clear();
                mapView.Map.Layers.Remove("ViewshedResultsLayer");

                //get the user's input point
                var inputPoint = await mapView.Editor.RequestPointAsync();

                progress.Visibility = Visibility.Visible;
                inputLayer.Graphics.Add(new Graphic()
                {
                    Geometry = inputPoint
                });

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
                parameter.GPParameters.Add(new GPString("Height", txtHeight.Text));
                parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(txtMiles.Text)));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    //get the results as a ArcGISDynamicMapServiceLayer
                    var resultLayer = _gpTask.GetResultMapServiceLayer(result.JobID);
                    if (resultLayer != null)
                    {
                        //Insert the results layer just beneath the input graphics layer.
                        //This allows us to see the input point at all times.
                        resultLayer.ID = "ViewshedResultsLayer";
                        mapView.Map.Layers.Insert(mapView.Map.Layers.IndexOf(inputLayer), resultLayer);
                        await mapView.LayersLoadedAsync(new List <Layer> {
                            resultLayer
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 7
0
        private async void OnStartViewShedCommand(object obj)
        {
            try
            {
                _inputOverlay    = mapView.GraphicsOverlays["inputOverlay"];
                _viewshedOverlay = mapView.GraphicsOverlays["ViewshedOverlay"];

                string txtMiles = obj as string;

                ViewShedEnabled = false;
                _inputOverlay.Graphics.Clear();
                _viewshedOverlay.Graphics.Clear();

                //get the user's input point
                var inputPoint = await mapView.Editor.RequestPointAsync();

                ViewShedProgressVisible = Visibility.Visible;
                _inputOverlay.Graphics.Add(new Graphic()
                {
                    Geometry = inputPoint
                });

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
                parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance ", LinearUnits.Miles, Convert.ToDouble(txtMiles)));

                ToolStatus = "Processing on server...";
                var result = await _gpTask.ExecuteAsync(parameter);

                if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
                {
                    throw new ApplicationException("No viewshed graphics returned for this start point.");
                }

                ToolStatus = "Finished processing. Retrieving results...";
                var viewshedLayer = (GPFeatureRecordSetLayer)result.OutParameters[0];
                _viewshedOverlay.Graphics.AddRange(viewshedLayer.FeatureSet.Features.OfType <Graphic>());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                ViewShedEnabled         = true;
                ViewShedProgressVisible = Visibility.Collapsed;
            }
        }
        // Calls the ExtractData service and prompts the user for saving the results
        private async void ExtractDataButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled   = false;
                progress.Visibility = txtStatus.Visibility = Visibility.Visible;

                var layersToClip = listLayers.SelectedItems.OfType <string>().Select(s => new GPString(s, s)).ToList();
                if (layersToClip == null || layersToClip.Count == 0)
                {
                    throw new ApplicationException("Please select layers to extract data from.");
                }

                if (graphicsLayer.Graphics.Count == 0)
                {
                    throw new ApplicationException("Please digitize an area of interest polygon on the map.");
                }

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };
                parameter.GPParameters.Add(new GPMultiValue <GPString>("Layers_to_Clip", layersToClip));
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Area_of_Interest", graphicsLayer.Graphics[0].Geometry));
                parameter.GPParameters.Add(new GPString("Feature_Format", (string)comboFormat.SelectedItem));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    var outParam = await _gpTask.GetResultDataAsync(result.JobID, "Output_Zip_File") as GPDataFile;

                    if (outParam != null && outParam.Uri != null)
                    {
                        await SaveResultsToFile(outParam);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled   = true;
                progress.Visibility = txtStatus.Visibility = Visibility.Collapsed;
            }
        }
        // Use geoprocessor to call drive times gp service and display results
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
               
                progress.Visibility = Visibility.Visible;

                // If the _gpTask has completed successfully (or before it is run the first time), the _cancellationTokenSource is set to null. 
                // If it has not completed and the map is clicked/tapped again, set the _cancellationTokenSource to cancel the initial task. 
                if (_cancellationTokenSource != null)
                {
                    _cancellationTokenSource.Cancel(); // Cancel previous operation
                }

                _cancellationTokenSource = new CancellationTokenSource();

                _inputOverlay.Graphics.Clear();
                _resultsOverlay.Graphics.Clear();

                _inputOverlay.Graphics.Add(new Graphic(e.Location));

                var parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.Location));
                parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

                var result = await _gpTask.ExecuteAsync(parameter, _cancellationTokenSource.Token);

                _cancellationTokenSource = null; // null out to show there are no pending operations

                if (result != null)
                {
                    var features = result.OutParameters.OfType<GPFeatureRecordSetLayer>().First().FeatureSet.Features;
                    _resultsOverlay.Graphics.AddRange(features.Select((fs, idx) => new Graphic(fs.Geometry, _bufferSymbols[idx])));
                }
            }
            catch (OperationCanceledException)
            {
                // Catch this exception because it is expected (when task cancellation is successful).
                // Catching it here prevents the message from being propagated to a MessageBox. 

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
		private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
		{
			// Convert screen point to map point
			var mapPoint = MyMapView.ScreenToLocation(e.Position);
			var layer = MyMapView.Map.Layers["InputLayer"] as GraphicsLayer;
			layer.Graphics.Clear();
			layer.Graphics.Add(new Graphic() { Geometry = mapPoint });

			string error = null;
			Geoprocessor task = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons"));

			var parameter = new GPInputParameter();

			parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", mapPoint));
			parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

			try
			{
				var result = await task.ExecuteAsync(parameter);
				var r = MyMapView.Map.Layers["ResultLayer"] as GraphicsLayer;
				r.Graphics.Clear();
				foreach (GPParameter gpParameter in result.OutParameters)
				{
					if (gpParameter is GPFeatureRecordSetLayer)
					{
						GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
						List<Esri.ArcGISRuntime.Symbology.Symbol> bufferSymbols = new List<Esri.ArcGISRuntime.Symbology.Symbol>(
							  new Esri.ArcGISRuntime.Symbology.Symbol[] { LayoutRoot.Resources["FillSymbol1"] as Esri.ArcGISRuntime.Symbology.Symbol, 
								  LayoutRoot.Resources["FillSymbol2"] as Esri.ArcGISRuntime.Symbology.Symbol, 
								  LayoutRoot.Resources["FillSymbol3"] as Esri.ArcGISRuntime.Symbology.Symbol });

						int count = 0;
						foreach (Graphic graphic in gpLayer.FeatureSet.Features)
						{
							graphic.Symbol = bufferSymbols[count];
							graphic.Attributes.Add("Info", String.Format("{0} minute buffer ", 3 - count));
							r.Graphics.Add(graphic);
							count++;
						}
					}
				}
			}
			catch (Exception ex)
			{
				error = "Geoprocessor service failed: " + ex.Message;
			}
			if (error != null)
				await new MessageDialog(error).ShowAsync();
		}
        // Use geoprocessor to call drive times gp service and display results
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;

                // If the _gpTask has completed successfully (or before it is run the first time), the _cancellationTokenSource is set to null.
                // If it has not completed and the map is clicked/tapped again, set the _cancellationTokenSource to cancel the initial task.
                if (_cancellationTokenSource != null)
                {
                    _cancellationTokenSource.Cancel(); // Cancel previous operation
                }

                _cancellationTokenSource = new CancellationTokenSource();

                _inputOverlay.Graphics.Clear();
                _resultsOverlay.Graphics.Clear();

                _inputOverlay.Graphics.Add(new Graphic(e.Location));

                var parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.Location));
                parameter.GPParameters.Add(new GPString("Drive_Times", "1 2 3"));

                var result = await _gpTask.ExecuteAsync(parameter, _cancellationTokenSource.Token);

                _cancellationTokenSource = null; // null out to show there are no pending operations

                if (result != null)
                {
                    var features = result.OutParameters.OfType <GPFeatureRecordSetLayer>().First().FeatureSet.Features;
                    _resultsOverlay.Graphics.AddRange(features.Select((fs, idx) => new Graphic(fs.Geometry, _bufferSymbols[idx])));
                }
            }
            catch (OperationCanceledException)
            {
                // Catch this exception because it is expected (when task cancellation is successful).
                // Catching it here prevents the message from being propagated to a MessageBox.
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled         = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

            //get the user's input point
            var inputPoint = await MyMapView.Editor.RequestPointAsync();

            //update UI elements
            MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
            MyProgressRing.IsActive   = true;

            viewshedLayer.Graphics.Clear();

            inputLayer.Graphics.Clear();
            inputLayer.Graphics.Add(new Graphic()
            {
                Geometry = inputPoint
            });

            Geoprocessor gpTask = new Geoprocessor(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
            parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance ", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));

            var result = await gpTask.ExecuteAsync(parameter);

            if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
            {
                throw new Exception("No viewshed graphics returned for this start point.");
            }

            var viewshedResult = result.OutParameters[0] as GPFeatureRecordSetLayer;

            viewshedLayer.Graphics.AddRange(viewshedResult.FeatureSet.Features.OfType <Graphic>());

            //Reset the UI
            StatusTextBlock.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
            StartButton.IsEnabled         = true;
            ClearResultsButton.Visibility = Visibility.Visible;
            MyProgressRing.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
            MyProgressRing.IsActive       = false;
        }
        // Get the users click point on the map and fire off a GP Job to calculate the viewshed
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
                inputLayer.Graphics.Clear();
                mapView.Map.Layers.Remove("ViewshedResultsLayer");

                //get the user's input point
                var inputPoint = await mapView.Editor.RequestPointAsync();

                progress.Visibility = Visibility.Visible;
                inputLayer.Graphics.Add(new Graphic() { Geometry = inputPoint });

                var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
                parameter.GPParameters.Add(new GPString("Height", txtHeight.Text));
                parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(txtMiles.Text)));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    //get the results as a ArcGISDynamicMapServiceLayer
                    var resultLayer = _gpTask.GetResultMapServiceLayer(result.JobID);
                    if (resultLayer != null)
                    {
                        //Insert the results layer just beneath the input graphics layer.
                        //This allows us to see the input point at all times.
                        resultLayer.ID = "ViewshedResultsLayer";
                        mapView.Map.Layers.Insert(mapView.Map.Layers.IndexOf(inputLayer), resultLayer);
                        await mapView.LayersLoadedAsync(new List<Layer> { resultLayer });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 14
0
        private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                Progress.Visibility = Visibility.Visible;


                _inputOverlay.Graphics.Clear();
                _inputOverlay.Graphics.Add(new Graphic()
                {
                    Geometry = e.Location
                });

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

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = MyMapView.SpatialReference
                };
                var ptNorm       = GeometryEngine.NormalizeCentralMeridian(e.Location);
                var ptGeographic = GeometryEngine.Project(ptNorm, SpatialReferences.Wgs84) as MapPoint;

                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", ptGeographic));
                parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                _resultsOverlay.Graphics.Clear();

                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        _resultsOverlay.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType <Graphic>());
                    }
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Geoprocessor service failed: " + ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                Progress.Visibility = Visibility.Collapsed;
            }
        }
        // Get the users click point on the map and fire off a GP Job to calculate the viewshed
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
                _inputOverlay.Graphics.Clear();
                _viewshedOverlay.Graphics.Clear();

                //get the user's input point
                var inputPoint = await MyMapView.Editor.RequestPointAsync();

                progress.Visibility = Visibility.Visible;
                _inputOverlay.Graphics.Add(new Graphic()
                {
                    Geometry = inputPoint
                });

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
                parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance", LinearUnits.Miles, Convert.ToDouble(txtMiles.Text)));

                txtStatus.Text = "Processing on server...";
                var result = await _gpTask.ExecuteAsync(parameter);

                if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
                {
                    throw new ApplicationException("No viewshed graphics returned for this start point.");
                }

                txtStatus.Text = "Finished processing. Retrieving results...";
                var viewshedLayer = result.OutParameters[0] as GPFeatureRecordSetLayer;
                _viewshedOverlay.Graphics.AddRange(viewshedLayer.FeatureSet.Features.OfType <Graphic>());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
        private async void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            var mapPoint = e.Location;
            var l        = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;

            l.Graphics.Clear();
            l.Graphics.Add(new Graphic()
            {
                Geometry = mapPoint
            });
            string       error            = null;
            Geoprocessor geoprocessorTask = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = mapView1.SpatialReference
            };
            var toGeographic = GeometryEngine.Project(mapPoint, new SpatialReference(4326)) as MapPoint;

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", toGeographic));
            parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

            try
            {
                var result = await geoprocessorTask.ExecuteAsync(parameter);

                var r = mapView1.Map.Layers["ResultLayer"] as GraphicsLayer;
                r.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        r.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType <Graphic>());
                    }
                }
            }
            catch (Exception ex)
            {
                error = "Geoprocessor service failed: " + ex.Message;
            }
            if (error != null)
            {
                await new MessageDialog(error).ShowAsync();
            }
        }
Exemplo n.º 17
0
        // Begin geoprocessing with a user tap on the map
        private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                Progress.Visibility = Visibility.Visible;

                InputLayer.Graphics.Clear();
                InputLayer.Graphics.Add(new Graphic()
                {
                    Geometry = e.Location
                });

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = mapView.SpatialReference
                };
                var ptNorm       = GeometryEngine.NormalizeCentralMeridianOfGeometry(e.Location);
                var ptGeographic = GeometryEngine.Project(ptNorm, SpatialReferences.Wgs84) as MapPoint;

                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", ptGeographic));
                parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                ResultLayer.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        ResultLayer.Graphics.AddRange(gpLayer.FeatureSet.Features);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Geoprocessor service failed: " + ex.Message, "Sample Error");
            }
            finally
            {
                Progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 18
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;
            }
        }
Exemplo n.º 20
0
        // Submit GP Job and Poll the server for results every 2 seconds.
        private async Task <GPJobInfo> SubmitAndPollStatusAsync(GPInputParameter parameter)
        {
            // Submit gp service job
            var result = await _gpTask.SubmitJobAsync(parameter);

            // Poll for the results async
            while (result.JobStatus != GPJobStatus.Cancelled && result.JobStatus != GPJobStatus.Deleted &&
                   result.JobStatus != GPJobStatus.Succeeded && result.JobStatus != GPJobStatus.TimedOut)
            {
                result = await _gpTask.CheckJobStatusAsync(result.JobID);

                txtStatus.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));

                await Task.Delay(2000);
            }

            return(result);
        }
        // Submit GP Job and Poll the server for results every 2 seconds.
        private async Task<GPJobInfo> SubmitAndPollStatusAsync(GPInputParameter parameter)
        {
            // Submit gp service job
            var result = await _gpTask.SubmitJobAsync(parameter);

            // Poll for the results async
            while (result.JobStatus != GPJobStatus.Cancelled && result.JobStatus != GPJobStatus.Deleted
                && result.JobStatus != GPJobStatus.Succeeded && result.JobStatus != GPJobStatus.TimedOut)
            {
                result = await _gpTask.CheckJobStatusAsync(result.JobID);

                txtStatus.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));

                await Task.Delay(2000);
            }

            return result;
        }
        public async void CreateViewshed()
        {
            // // get a point from the user
            var mapPoint = await this.mapView.Editor.RequestPointAsync();

            // clear the graphics layers
            this.viewshedGraphicsLayer.Graphics.Clear();
            this.inputGraphicsLayer.Graphics.Clear();

            // add new graphic to layer
            this.inputGraphicsLayer.Graphics.Add(new Graphic {
                Geometry = mapPoint, Symbol = this.sms
            });

            // specify the input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", mapPoint));
            parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance", LinearUnits.Miles, this.distance));

            // Send to the server
            this.Status = "Processing on server...";
            var result = await gpTask.ExecuteAsync(parameter);

            if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
            {
                throw new ApplicationException("No viewshed graphics returned for this start point.");
            }

            // process the output
            this.Status = "Finished processing. Retrieving results...";
            var viewshedLayer = result.OutParameters[0] as GPFeatureRecordSetLayer;
            var features      = viewshedLayer.FeatureSet.Features;

            foreach (Feature feature in features)
            {
                this.viewshedGraphicsLayer.Graphics.Add(feature as Graphic);
            }
            this.Status = "Finished!!";
        }
       private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
       {
           try
           {
               Progress.Visibility = Visibility.Visible;

               
               _inputOverlay.Graphics.Clear();
               _inputOverlay.Graphics.Add(new Graphic() { Geometry = e.Location });

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

               var parameter = new GPInputParameter() { OutSpatialReference = MyMapView.SpatialReference };
			   var ptNorm = GeometryEngine.NormalizeCentralMeridian(e.Location);
               var ptGeographic = GeometryEngine.Project(ptNorm, SpatialReferences.Wgs84) as MapPoint;

               parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", ptGeographic));
               parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

               var result = await geoprocessorTask.ExecuteAsync(parameter);

               _resultsOverlay.Graphics.Clear();

               foreach (GPParameter gpParameter in result.OutParameters)
               {
                   if (gpParameter is GPFeatureRecordSetLayer)
                   {
                       GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                       _resultsOverlay.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType<Graphic>());
                   }
               }
           }
           catch (Exception ex)
           {
               var _x = new MessageDialog("Geoprocessor service failed: " + ex.Message, "Sample Error").ShowAsync();
           }
           finally
           {
               Progress.Visibility = Visibility.Collapsed;
           }
       }
        // Begin geoprocessing with a user tap on the map
        private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            try
            {
                Progress.Visibility = Visibility.Visible;

                InputLayer.Graphics.Clear();
                InputLayer.Graphics.Add(new Graphic() { Geometry = e.Location });

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

                var parameter = new GPInputParameter() { OutSpatialReference = mapView.SpatialReference };
                var ptNorm = GeometryEngine.NormalizeCentralMeridianOfGeometry(e.Location);
                var ptGeographic = GeometryEngine.Project(ptNorm, SpatialReferences.Wgs84) as MapPoint;

                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", ptGeographic));
                parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

                var result = await geoprocessorTask.ExecuteAsync(parameter);

                ResultLayer.Graphics.Clear();
                foreach (GPParameter gpParameter in result.OutParameters)
                {
                    if (gpParameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
                        ResultLayer.Graphics.AddRange(gpLayer.FeatureSet.Features);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Geoprocessor service failed: " + ex.Message, "Sample Error");
            }
            finally
            {
                Progress.Visibility = Visibility.Collapsed;
            }
        }
	   private async void mapView1_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
		{            
			var mapPoint = e.Location;
			var l = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;
			l.Graphics.Clear();
			l.Graphics.Add(new Graphic() { Geometry = mapPoint });
			string error = null;
			Geoprocessor geoprocessorTask = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

			var parameter = new GPInputParameter()
			{
				OutSpatialReference = mapView1.SpatialReference
			};
			var toGeographic = GeometryEngine.Project(mapPoint, new SpatialReference(4326)) as MapPoint;

			parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", toGeographic));
			parameter.GPParameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

			try
			{
				var result = await geoprocessorTask.ExecuteAsync(parameter);
				var r = mapView1.Map.Layers["ResultLayer"] as GraphicsLayer;
				r.Graphics.Clear();
				foreach (GPParameter gpParameter in result.OutParameters)
				{
					if (gpParameter is GPFeatureRecordSetLayer)
					{
						GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;
						r.Graphics.AddRange(gpLayer.FeatureSet.Features.OfType<Graphic>());
					}
				}
			}
			catch (Exception ex)
			{
				error = "Geoprocessor service failed: " + ex.Message;
			}
			if (error != null)
				await new MessageDialog(error).ShowAsync();
		}
        // 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;
			}
		}
		private async void StartButton_Click(object sender, RoutedEventArgs e)
		{
			StartButton.IsEnabled = false;
			ClearResultsButton.Visibility = Visibility.Collapsed;

			//get the user's input point
			var inputPoint = await MyMapView.Editor.RequestPointAsync();

			//update UI elements
			MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
			MyProgressRing.IsActive = true;

			viewshedLayer.Graphics.Clear();

			inputLayer.Graphics.Clear();
			inputLayer.Graphics.Add(new Graphic() { Geometry = inputPoint });

			Geoprocessor gpTask = new Geoprocessor(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed"));

			var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
			parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
			parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance ", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));

			var result = await gpTask.ExecuteAsync(parameter);

			if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
				throw new Exception("No viewshed graphics returned for this start point.");

			var viewshedResult = result.OutParameters[0] as GPFeatureRecordSetLayer;
			viewshedLayer.Graphics.AddRange(viewshedResult.FeatureSet.Features.OfType<Graphic>());

			//Reset the UI
			StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
			StartButton.IsEnabled = true;
			ClearResultsButton.Visibility = Visibility.Visible;
			MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
			MyProgressRing.IsActive = false;
		}
        // Get the users click point on the map and fire off a GP Job to calculate the viewshed
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
				_inputOverlay.Graphics.Clear();
				_viewshedOverlay.Graphics.Clear();

                //get the user's input point
                var inputPoint = await MyMapView.Editor.RequestPointAsync();

                progress.Visibility = Visibility.Visible;
				_inputOverlay.Graphics.Add(new Graphic() { Geometry = inputPoint });

                var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
				parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
				parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance ", LinearUnits.Miles, Convert.ToDouble(txtMiles.Text)));

				txtStatus.Text = "Processing on server...";
				var result = await _gpTask.ExecuteAsync(parameter);
                if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
					throw new ApplicationException("No viewshed graphics returned for this start point.");

                txtStatus.Text = "Finished processing. Retrieving results...";
				var viewshedLayer = result.OutParameters[0] as GPFeatureRecordSetLayer;
				_viewshedOverlay.Graphics.AddRange(viewshedLayer.FeatureSet.Features.OfType<Graphic>());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 30
0
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;
            StatusText     = "Executing...";

            // Clear previous results
            TapPoints.Clear();
            if (m_viewshedLayer != null)
            {
                Layers.Remove(m_viewshedLayer);
            }


            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the viewshed calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/ArcGIS/rest/services/" +
                                                         "ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", e.Location));
            parameter.GPParameters.Add(new GPString("Height", "50"));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, 10));

            try
            {
                var result = await task.SubmitJobAsync(parameter);

                // Poll the server for results every two seconds.
                while (result.JobStatus != GPJobStatus.Cancelled &&
                       result.JobStatus != GPJobStatus.Deleted &&
                       result.JobStatus != GPJobStatus.Failed &&
                       result.JobStatus != GPJobStatus.Succeeded &&
                       result.JobStatus != GPJobStatus.TimedOut)
                {
                    result = await task.CheckJobStatusAsync(result.JobID);

                    // show the status
                    var descriptions = result.Messages.Select(msg => msg.Description);
                    var status       = string.Join(Environment.NewLine, descriptions);
                    if (!string.IsNullOrEmpty(status))
                    {
                        StatusText = status;
                    }

                    await Task.Delay(2000);
                }

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    // get the results as a ArcGISDynamicMapServiceLayer
                    StatusText      = "Calculation complete. Retrieving results...";
                    m_viewshedLayer = task.GetResultMapServiceLayer(result.JobID);

                    if (m_viewshedLayer != null)
                    {
                        // Insert the results layer beneath the tap points layer.
                        // This allows the input point to be visible at all times.
                        Layers.Insert(Layers.IndexOf(m_tapPointsLayer), m_viewshedLayer);

                        // Wait until the viewshed layer is initialized
                        await m_viewshedLayer.InitializeAsync();
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "Viewshed calculation failed";
                }
            }
            catch (Exception ex)
            {
                error = "Viewshed calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
            {
                MessageBox.Show(error);
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
            StatusText     = "";
        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

            //get the user's input point
            var inputPoint = await mapView1.Editor.RequestPointAsync();

            //update UI elements
            MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
            MyProgressRing.IsActive = true;

            inputLayer.Graphics.Clear();
            inputLayer.Graphics.Add(new Graphic() { Geometry = inputPoint });

            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/arcgis/rest/services/ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = new SpatialReference(102100)
            };
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
            parameter.GPParameters.Add(new GPString("Height", HeightTextBox.Text));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));


            var result = await task.SubmitJobAsync(parameter);

            //Poll the server for results every 2 seconds.
            while (result.JobStatus != GPJobStatus.Cancelled && result.JobStatus != GPJobStatus.Deleted &&
                 result.JobStatus != GPJobStatus.Succeeded && result.JobStatus != GPJobStatus.TimedOut)
            {
                result = await task.CheckJobStatusAsync(result.JobID);

                //show the status
                StatusTextBlock.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));


                await Task.Delay(2000);
            }
            if (result.JobStatus == GPJobStatus.Succeeded)
            {
                //get the results as a ArcGISDynamicMapServiceLayer
                StatusTextBlock.Text = "Finished processing. Retrieving results...";
                var resultLayer = task.GetResultMapServiceLayer(result.JobID);

                if (resultLayer != null)
                {
                    //Add an ID so that we can reference this layer (to remove it)
                    resultLayer.ID = "MyResultsLayer";

                    //Insert the results layer just beneath the input graphics layer.
                    //This allows us to see the input point at all times.
                    mapView1.Map.Layers.Insert(mapView1.Map.Layers.IndexOf(inputLayer), resultLayer);

                }

                //Reset the UI
                StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                StartButton.IsEnabled = true;
                ClearResultsButton.Visibility = Visibility.Visible;
                MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                MyProgressRing.IsActive = false;
            }
        }
        // On tap, get an input line and perform a buffer and clip operation
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;

            // Clear previous results
            TapPoints.Clear();
            Currents.Clear();



            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the drive time calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                                                         "Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            var projectedMapPoint = GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", projectedMapPoint));
            parameter.GPParameters.Add(new GPDouble("Days", Days));

            try
            {
                // Run the operation
                var result = await task.ExecuteAsync(parameter);

                // Check that layers were returned from the operation
                var outputLayers = result.OutParameters.OfType <GPFeatureRecordSetLayer>();
                if (outputLayers.Count() > 0)
                {
                    // Get the first layer returned - this will be the drive time areas
                    var outputLayer = outputLayers.First();
                    if (outputLayer.FeatureSet != null && outputLayer.FeatureSet.Features != null)
                    {
                        // Instead of adding ocean current features one-by-one, update the collection all at once to
                        // allow the map to render the new features in one rendering pass.
                        Currents = new ObservableCollection <Graphic>(outputLayer.FeatureSet.Features);
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "No results returned";
                }
            }
            catch (Exception ex)
            {
                error = "Calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
            {
                MessageBox.Show(error);
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
        }
        // Get the users input line on the map and fire off a GP Job to clip features
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
                inputLayer.Graphics.Clear();
                resultLayer.Graphics.Clear();

                foreach (var lyr in mapView.Map.Layers.OfType <GPResultImageLayer>())
                {
                    mapView.Map.Layers.Remove(lyr);
                }

                //get the user's input line
                var inputLine = await mapView.Editor.RequestShapeAsync(DrawShape.Polyline) as Polyline;

                progress.Visibility = Visibility.Visible;
                inputLayer.Graphics.Add(new Graphic()
                {
                    Geometry = inputLine
                });

                var parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputLine));
                parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, Int32.Parse(txtMiles.Text)));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    var resultData = await _gpTask.GetResultDataAsync(result.JobID, "Clipped_Counties");

                    if (resultData is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                        if (gpLayer.FeatureSet.Features.Count == 0)
                        {
                            var resultImageLayer = await _gpTask.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

                            GPResultImageLayer gpImageLayer = resultImageLayer;
                            gpImageLayer.Opacity = 0.5;
                            mapView.Map.Layers.Add(gpImageLayer);
                            txtStatus.Text = "Greater than 500 features returned.  Results drawn using map service.";
                            return;
                        }

                        resultLayer.Graphics.AddRange(gpLayer.FeatureSet.Features);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
		private async void StartButton_Click(object sender, RoutedEventArgs e)
		{
			StartButton.IsEnabled = false;
			ClearResultsButton.Visibility = Visibility.Collapsed;

			//get the user's input point
			var inputPoint = await MyMapView.Editor.RequestPointAsync();

			//update UI elements
			MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
			MyProgressRing.IsActive = true;

			viewshedLayer.Graphics.Clear();

			inputLayer.Graphics.Clear();
			inputLayer.Graphics.Add(new Graphic() { Geometry = inputPoint });

			Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/arcgis/rest/services/ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

			var parameter = new GPInputParameter()
			{
				OutSpatialReference = new SpatialReference(102100)
			};
			parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
			parameter.GPParameters.Add(new GPString("Height", HeightTextBox.Text));
			parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));


			var result = await task.SubmitJobAsync(parameter);

			//Poll the server for results every 2 seconds.
			while (result.JobStatus != GPJobStatus.Cancelled && result.JobStatus != GPJobStatus.Deleted &&
				 result.JobStatus != GPJobStatus.Succeeded && result.JobStatus != GPJobStatus.TimedOut)
			{
				result = await task.CheckJobStatusAsync(result.JobID);

				//show the status
				StatusTextBlock.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));


				await Task.Delay(2000);
			}
			if (result.JobStatus == GPJobStatus.Succeeded)
			{
				//get the results as a ArcGISDynamicMapServiceLayer
				StatusTextBlock.Text = "Finished processing. Retrieving results...";                
				var viewshedResult = await task.GetResultDataAsync(result.JobID, "View") as GPFeatureRecordSetLayer;
				var rangeResult = await task.GetResultDataAsync(result.JobID, "Range") as GPFeatureRecordSetLayer;

				if (viewshedResult != null && viewshedResult.FeatureSet != null && viewshedResult.FeatureSet.Features != null)
				{
					foreach (var feature in viewshedResult.FeatureSet.Features)
					{
						viewshedLayer.Graphics.Add((Graphic)feature);
					}
				}

				//Reset the UI
				StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
				StartButton.IsEnabled = true;
				ClearResultsButton.Visibility = Visibility.Visible;
				MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
				MyProgressRing.IsActive = false;
			}
		}
Exemplo n.º 35
0
        public async void CreateViewshed()
        {
           // // get a point from the user
           var mapPoint = await this.mapView.Editor.RequestPointAsync();

           // clear the graphics layers
           this.viewshedGraphicsLayer.Graphics.Clear();
           this.inputGraphicsLayer.Graphics.Clear();
           
            // add new graphic to layer
           this.inputGraphicsLayer.Graphics.Add(new Graphic{ Geometry = mapPoint, Symbol = this.sms });

           // specify the input parameters
           var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
           parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", mapPoint));
           parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance", LinearUnits.Miles, this.distance));

           // Send to the server
           this.Status = "Processing on server...";
           var result = await gpTask.ExecuteAsync(parameter);
           if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
               throw new ApplicationException("No viewshed graphics returned for this start point.");
           
           // process the output
           this.Status = "Finished processing. Retrieving results...";
           var viewshedLayer = result.OutParameters[0] as GPFeatureRecordSetLayer;
           var features = viewshedLayer.FeatureSet.Features;
            foreach (Feature feature in features)
            {
                this.viewshedGraphicsLayer.Graphics.Add(feature as Graphic);
            }
            this.Status = "Finished!!";
        }
        // Calls the ExtractData service and prompts the user for saving the results
        private async void ExtractDataButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility = txtStatus.Visibility = Visibility.Visible;

                var layersToClip = listLayers.SelectedItems.OfType<string>().Select(s => new GPString(s, s)).ToList();
                if (layersToClip == null || layersToClip.Count == 0)
                    throw new Exception("Please select layers to extract data from.");

                if (_graphicsOverlay.Graphics.Count == 0)
                    throw new Exception("Please digitize an area of interest polygon on the map.");

                var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
                parameter.GPParameters.Add(new GPMultiValue<GPString>("Layers_to_Clip", layersToClip));
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Area_of_Interest", _graphicsOverlay.Graphics[0].Geometry));
                parameter.GPParameters.Add(new GPString("Feature_Format", (string)comboFormat.SelectedItem));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    var outParam = await _gpTask.GetResultDataAsync(result.JobID, "Output_Zip_File") as GPDataFile;
                    if (outParam != null && outParam.Uri != null)
                    {
                        await SaveResultsToFile(outParam);
                    }
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = txtStatus.Visibility = Visibility.Collapsed;
            }
        }
        // On tap, get an input line and perform a buffer and clip operation
       private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;

            // Clear previous results
            TapPoints.Clear();
            Currents.Clear();

          

            // Create graphic and add to tap points
            var g = new Graphic() { Geometry = e.Location };
            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the drive time calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                "Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };

            var projectedMapPoint = GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", projectedMapPoint));
            parameter.GPParameters.Add(new GPDouble("Days", Days));

            try
            {
                // Run the operation
                var result = await task.ExecuteAsync(parameter);

                // Check that layers were returned from the operation
                var outputLayers = result.OutParameters.OfType<GPFeatureRecordSetLayer>();
                if (outputLayers.Count() > 0)
                {
                    // Get the first layer returned - this will be the drive time areas
                    var outputLayer = outputLayers.First();
                    if (outputLayer.FeatureSet != null && outputLayer.FeatureSet.Features != null)
                    {
                        // Instead of adding ocean current features one-by-one, update the collection all at once to
                        // allow the map to render the new features in one rendering pass.
                        Currents = new ObservableCollection<Graphic>(outputLayer.FeatureSet.Features);
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "No results returned";
                }
            }
            catch (Exception ex)
            {
                error = "Calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
                MessageBox.Show(error);

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
        }
Exemplo n.º 38
0
        /// <summary>
        /// マップビュータップ時の処理
        /// </summary>
        private async void mainMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            //解析手順のメッセージを非表示
            analyzeTextBox.Visibility = System.Windows.Visibility.Collapsed;

            //プログレスバーを表示
            analyzeProgressBar.Visibility = System.Windows.Visibility.Visible;

            //マップビュータップ時のイベントハンドラを解除
            mainMapView.MapViewTapped -= mainMapView_MapViewTapped;

            //カーソルを矢印に変更
            mainMapView.Cursor = Cursors.Arrow;

            //クリックした位置からグラフィックを作成
            Graphic clickPoint = new Graphic(e.Location)
            {
                Symbol = layoutRoot.Resources["greenMarkerSymbol"] as SimpleMarkerSymbol,
                ZIndex = 2
            };

            //到達圏解析結果表示用のグラフィックスレイヤにクリック位置のグラフィックを追加
            serviceAreaResultLayer.Graphics.Add(clickPoint);

            try
            {
                //到達圏解析用パラメーターの作成
                GPInputParameter parameter = new GPInputParameter();
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("facilities", e.Location));  //解析の中心点
                parameter.GPParameters.Add(new GPString("break_values", "10"));                     //到達圏の範囲(10分)
                parameter.GPParameters.Add(new GPString("env:outSR", "102100"));                    //結果の空間参照(Web メルカトル)
                parameter.GPParameters.Add(new GPString("travel_mode", "Walking"));                 //"徒歩"で到達できる範囲を解析

                //到達圏の解析を開始
                GPJobInfo result = await serviceAreaGp.SubmitJobAsync(parameter);

                //到達圏の解析結果が"成功"、"失敗"、"時間切れ"、"キャンセル"のいずれかになるまで
                //2秒ごとに ArcGIS Online にステータスを確認
                while (result.JobStatus != GPJobStatus.Succeeded &&
                       result.JobStatus != GPJobStatus.Failed &&
                       result.JobStatus != GPJobStatus.TimedOut &&
                       result.JobStatus != GPJobStatus.Cancelled)
                {
                    result = await serviceAreaGp.CheckJobStatusAsync(result.JobID);

                    await Task.Delay(2000);
                }


                //到達圏解析の結果が成功した場合は結果を表示
                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    //到達圏解析の結果を取得
                    GPParameter resultData = await serviceAreaGp.GetResultDataAsync(result.JobID, "Service_Areas");

                    //到達圏解析結果レイヤのグラフィックを結果グラフィックとして取得
                    GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                    serviceAreaGraphic = gpLayer.FeatureSet.Features[0] as Graphic;

                    //グラフィックにシンボルを設定
                    serviceAreaGraphic.Symbol = layoutRoot.Resources["greenFillSymbol"] as SimpleFillSymbol;

                    //結果グラフィックが解析の中心点のグラフィックより下に表示されるように表示順序を設定
                    serviceAreaGraphic.ZIndex = 1;

                    //到達圏解析結果表示用のグラフィックスレイヤにグラフィックを追加
                    serviceAreaResultLayer.Graphics.Add(serviceAreaGraphic);
                }
            }
            //エラーが発生した場合の処理
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("到達圏解析:{0}", ex.Message));

                //到達圏解析の結果をクリア
                ClearAnalysisResult();
            }
            finally
            {
                //プログレスバーを非表示
                analyzeProgressBar.Visibility = System.Windows.Visibility.Collapsed;

                //到達圏解析ボタンを表示
                analyzePanel.Visibility = System.Windows.Visibility.Visible;
            }
        }
        private async void StartGP_Click(object sender, RoutedEventArgs e)
        {
            StartGP.IsEnabled = false;
            ClearGraphics();
            ClearButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ProcessingTextBlock.Visibility = Visibility.Collapsed;

            var inputPolyline = await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline);

            var inputGraphic = new Graphic { Geometry = inputPolyline };
            GraphicsLayer inputLayer = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;
            inputLayer.Graphics.Add(inputGraphic);

            MyProgressRing.Visibility = Visibility.Visible;
            MyProgressRing.IsActive = true;

            string message = null;

            Geoprocessor task = new Geoprocessor(new Uri(ServiceUri));
            var inputParameter = new GPInputParameter();
            inputParameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPolyline));
            inputParameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, Int32.Parse(DistanceTextBox.Text)));
            try
            {
                //Submit the job and await the results
                var gpJobInfo = await task.SubmitJobAsync(inputParameter);

                //Poll the server every 5 seconds for the status of the job.
                //Cancelled, Cancelling, Deleted, Deleting, Executing, Failed, New, Submitted, Succeeded, TimedOut, Waiting
                while (gpJobInfo.JobStatus != GPJobStatus.Cancelled &&
                    gpJobInfo.JobStatus != GPJobStatus.Deleted &&
                     gpJobInfo.JobStatus != GPJobStatus.Failed &&
                     gpJobInfo.JobStatus != GPJobStatus.Succeeded &&
                     gpJobInfo.JobStatus != GPJobStatus.TimedOut)
                {
                    gpJobInfo = await task.CheckJobStatusAsync(gpJobInfo.JobID);
                    await Task.Delay(5000);

                }

                //Now that the job is completed, check whether the service returned the results as Features or as a GPResultImageLayer.
                //This can happen if the number of features to return exceeds the limit set on the service
                if (gpJobInfo.JobStatus == GPJobStatus.Succeeded)
                {
                    var resultData = await task.GetResultDataAsync(gpJobInfo.JobID, "Clipped_Counties");
                    if (resultData is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                        if (gpLayer.FeatureSet.Features.Count == 0)
                        {
                            var resultImageLayer = await task.GetResultImageLayerAsync(gpJobInfo.JobID, "Clipped_Counties");
                            GPResultImageLayer gpImageLayer = resultImageLayer;
                            gpImageLayer.Opacity = 0.5;
                            mapView1.Map.Layers.Add(gpImageLayer);
                            ProcessingTextBlock.Visibility = Visibility.Visible;
                            ProcessingTextBlock.Text = "Greater than 500 features returned.  Results drawn using map service.";
                            return;
                        }
                        GraphicsLayer resultLayer = mapView1.Map.Layers["MyResultGraphicsLayer"] as GraphicsLayer;
                        foreach (Graphic g in gpLayer.FeatureSet.Features)
                        {
                            resultLayer.Graphics.Add(g);
                        }
                    }
                }
                MyProgressRing.Visibility = Visibility.Collapsed;
                MyProgressRing.IsActive = false;

                ClearButton.Visibility = Visibility.Visible;
                StartGP.IsEnabled = true;

            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            if (message != null)
                await new MessageDialog(message, "GP Failed").ShowAsync();


        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled         = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

            //get the user's input point
            var inputPoint = await mapView1.Editor.RequestPointAsync();

            //update UI elements
            MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
            MyProgressRing.IsActive   = true;

            viewShedLayer.Graphics.Clear();

            inputLayer.Graphics.Clear();
            inputLayer.Graphics.Add(new Graphic()
            {
                Geometry = inputPoint
            });

            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/arcgis/rest/services/ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = new SpatialReference(102100)
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
            parameter.GPParameters.Add(new GPString("Height", HeightTextBox.Text));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));


            var result = await task.SubmitJobAsync(parameter);

            //Poll the server for results every 2 seconds.
            while (result.JobStatus != GPJobStatus.Cancelled && result.JobStatus != GPJobStatus.Deleted &&
                   result.JobStatus != GPJobStatus.Succeeded && result.JobStatus != GPJobStatus.TimedOut)
            {
                result = await task.CheckJobStatusAsync(result.JobID);

                //show the status
                StatusTextBlock.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));


                await Task.Delay(2000);
            }
            if (result.JobStatus == GPJobStatus.Succeeded)
            {
                //get the results as a ArcGISDynamicMapServiceLayer
                StatusTextBlock.Text = "Finished processing. Retrieving results...";
                var viewshedResult = await task.GetResultDataAsync(result.JobID, "View") as GPFeatureRecordSetLayer;

                var rangeResult = await task.GetResultDataAsync(result.JobID, "Range") as GPFeatureRecordSetLayer;

                if (viewshedResult != null && viewshedResult.FeatureSet != null && viewshedResult.FeatureSet.Features != null)
                {
                    foreach (var feature in viewshedResult.FeatureSet.Features)
                    {
                        viewShedLayer.Graphics.Add((Graphic)feature);
                    }
                }

                //Reset the UI
                StatusTextBlock.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
                StartButton.IsEnabled         = true;
                ClearResultsButton.Visibility = Visibility.Visible;
                MyProgressRing.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                MyProgressRing.IsActive       = false;
            }
        }
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;
            StatusText = "Executing...";

            // Clear previous results
            TapPoints.Clear();
            if (m_viewshedLayer != null)
                Layers.Remove(m_viewshedLayer);

           
            // Create graphic and add to tap points
            var g = new Graphic() { Geometry = e.Location };
            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the viewshed calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/ArcGIS/rest/services/" +
                "ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", e.Location));
            parameter.GPParameters.Add(new GPString("Height", "50"));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, 10));

            try
            {
                var result = await task.SubmitJobAsync(parameter);

                // Poll the server for results every two seconds.
                while (result.JobStatus != GPJobStatus.Cancelled
                    && result.JobStatus != GPJobStatus.Deleted
                    && result.JobStatus != GPJobStatus.Failed
                    && result.JobStatus != GPJobStatus.Succeeded
                    && result.JobStatus != GPJobStatus.TimedOut)
                {
                    result = await task.CheckJobStatusAsync(result.JobID);

                    // show the status
                    var descriptions = result.Messages.Select(msg => msg.Description);
                    var status = string.Join(Environment.NewLine, descriptions);
                    if (!string.IsNullOrEmpty(status))
                        StatusText = status;

                    await Task.Delay(2000);
                }

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    // get the results as a ArcGISDynamicMapServiceLayer
                    StatusText = "Calculation complete. Retrieving results...";
                    m_viewshedLayer = task.GetResultMapServiceLayer(result.JobID);
                    
                    if (m_viewshedLayer != null)
                    {
                        // Insert the results layer beneath the tap points layer.
                        // This allows the input point to be visible at all times.
                        Layers.Insert(Layers.IndexOf(m_tapPointsLayer), m_viewshedLayer);

                        // Wait until the viewshed layer is initialized
                        await m_viewshedLayer.InitializeAsync();
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "Viewshed calculation failed";
                }
            }
            catch (Exception ex)
            {
                error = "Viewshed calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
                MessageBox.Show(error);

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
            StatusText = "";
        }
        // Waits for the user to draw a line, then performs the buffer and clip operation
        private async void getInputLineAndClip()
        {
            if (m_firstPointAdded)
                return;

            // Get line from user
            var clipLine = await Editor.RequestShapeAsync(DrawShape.Polyline,
                new SimpleLineSymbol() { Color = Colors.Red, Width = 2, Style = SimpleLineStyle.Dash });
            ClipLines.Add(new Graphic() { Geometry = clipLine });

            // Show busy UI
            BusyVisibility = Visibility.Visible;
            StatusText = "Executing...";

            string error = null;

            // Initialize the Geoprocessing task with the buffer and clip service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps10.esri.com/ArcGIS/rest/services/SamplesNET/" +
                "USA_Data_ClipTools/GPServer/ClipCounties"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", clipLine)); // input geometry
            parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, BufferDistance)); // buffer distance
            try
            {
                // Submit the job and await the results
                var result = await task.SubmitJobAsync(parameter);

                // Poll the server every two seconds for the status of the job.
                while (result.JobStatus != GPJobStatus.Cancelled
                    && result.JobStatus != GPJobStatus.Deleted
                    && result.JobStatus != GPJobStatus.Failed
                    && result.JobStatus != GPJobStatus.Succeeded
                    && result.JobStatus != GPJobStatus.TimedOut)
                {
                    result = await task.CheckJobStatusAsync(result.JobID);

                    // show the status
                    var descriptions = result.Messages.Select(msg => msg.Description);
                    var status = string.Join(Environment.NewLine, descriptions);
                    if (!string.IsNullOrEmpty(status))
                        StatusText = status;

                    await Task.Delay(2000);
                }

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    // Get the results
                    var resultData = await task.GetResultDataAsync(result.JobID, "Clipped_Counties");
                    if (resultData is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer resultsLayer = resultData as GPFeatureRecordSetLayer;
                        if (resultsLayer.FeatureSet != null
                            && resultsLayer.FeatureSet.Features != null
                            && resultsLayer.FeatureSet.Features.Count != 0)
                        {
                            // Results were returned as graphics.  Add them to the ClippedCounties collection
                            ClippedCounties = new ObservableCollection<Graphic>(resultsLayer.FeatureSet.Features);
                        }
                        else // Try to get results as a GPResultImageLayer
                        {
                            StatusText = "Clip operation complete. Retrieving results...";

                            m_clippedCountiesLayer = await task.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

                            // If successful, add the layer to the layers collection
                            if (m_clippedCountiesLayer != null)
                            {
                                m_clippedCountiesLayer.Opacity = 0.5;

                                // Insert the layer below the input layer
                                Layers.Insert(Layers.IndexOf(m_clipLinesLayer), m_clippedCountiesLayer);

                                // Wait until the result layer is initialized
                                await m_clippedCountiesLayer.InitializeAsync();
                            }
                            else
                            {
                                error = "No results found";
                            }
                        }
                    }
                    else
                    {
                        error = "Clip operation failed";
                    }
                }
                else
                {
                    error = "Clip operation failed";
                }
            }
            catch (Exception ex)
            {
                error = "Clip operation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
                MessageBox.Show(error);

            // Hide busy UI
            BusyVisibility = StatusVisibility = Visibility.Collapsed;
            StatusText = "";
            m_firstPointAdded = false;

            getInputLineAndClip();
        }
        private async void StartGP_Click(object sender, RoutedEventArgs e)
        {
            StartGP.IsEnabled = false;
            ClearGraphics();
            ClearButton.Visibility         = Windows.UI.Xaml.Visibility.Collapsed;
            ProcessingTextBlock.Visibility = Visibility.Collapsed;

            var inputPolyline = await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline);

            var inputGraphic = new Graphic {
                Geometry = inputPolyline
            };
            GraphicsLayer inputLayer = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;

            inputLayer.Graphics.Add(inputGraphic);

            MyProgressRing.Visibility = Visibility.Visible;
            MyProgressRing.IsActive   = true;

            string message = null;

            Geoprocessor task           = new Geoprocessor(new Uri(ServiceUri));
            var          inputParameter = new GPInputParameter();

            inputParameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPolyline));
            inputParameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, Int32.Parse(DistanceTextBox.Text)));
            try
            {
                //Submit the job and await the results
                var gpJobInfo = await task.SubmitJobAsync(inputParameter);

                //Poll the server every 5 seconds for the status of the job.
                //Cancelled, Cancelling, Deleted, Deleting, Executing, Failed, New, Submitted, Succeeded, TimedOut, Waiting
                while (gpJobInfo.JobStatus != GPJobStatus.Cancelled &&
                       gpJobInfo.JobStatus != GPJobStatus.Deleted &&
                       gpJobInfo.JobStatus != GPJobStatus.Failed &&
                       gpJobInfo.JobStatus != GPJobStatus.Succeeded &&
                       gpJobInfo.JobStatus != GPJobStatus.TimedOut)
                {
                    gpJobInfo = await task.CheckJobStatusAsync(gpJobInfo.JobID);

                    await Task.Delay(5000);
                }

                //Now that the job is completed, check whether the service returned the results as Features or as a GPResultImageLayer.
                //This can happen if the number of features to return exceeds the limit set on the service
                if (gpJobInfo.JobStatus == GPJobStatus.Succeeded)
                {
                    var resultData = await task.GetResultDataAsync(gpJobInfo.JobID, "Clipped_Counties");

                    if (resultData is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                        if (gpLayer.FeatureSet.Features.Count == 0)
                        {
                            var resultImageLayer = await task.GetResultImageLayerAsync(gpJobInfo.JobID, "Clipped_Counties");

                            GPResultImageLayer gpImageLayer = resultImageLayer;
                            gpImageLayer.Opacity = 0.5;
                            mapView1.Map.Layers.Add(gpImageLayer);
                            ProcessingTextBlock.Visibility = Visibility.Visible;
                            ProcessingTextBlock.Text       = "Greater than 500 features returned.  Results drawn using map service.";
                            return;
                        }
                        GraphicsLayer resultLayer = mapView1.Map.Layers["MyResultGraphicsLayer"] as GraphicsLayer;
                        foreach (Graphic g in gpLayer.FeatureSet.Features)
                        {
                            resultLayer.Graphics.Add(g);
                        }
                    }
                }
                MyProgressRing.Visibility = Visibility.Collapsed;
                MyProgressRing.IsActive   = false;

                ClearButton.Visibility = Visibility.Visible;
                StartGP.IsEnabled      = true;
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            if (message != null)
            {
                await new MessageDialog(message, "GP Failed").ShowAsync();
            }
        }
Exemplo n.º 44
0
        // Waits for the user to draw a line, then performs the buffer and clip operation
        private async void getInputLineAndClip()
        {
            if (m_firstPointAdded)
            {
                return;
            }

            // Get line from user
            var clipLine = await Editor.RequestShapeAsync(DrawShape.Polyline,
                                                          new SimpleLineSymbol()
            {
                Color = Colors.Red, Width = 2, Style = SimpleLineStyle.Dash
            });

            ClipLines.Add(new Graphic()
            {
                Geometry = clipLine
            });

            // Show busy UI
            BusyVisibility = Visibility.Visible;
            StatusText     = "Executing...";

            string error = null;

            // Initialize the Geoprocessing task with the buffer and clip service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps10.esri.com/ArcGIS/rest/services/SamplesNET/" +
                                                         "USA_Data_ClipTools/GPServer/ClipCounties"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", clipLine));            // input geometry
            parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, BufferDistance)); // buffer distance
            try
            {
                // Submit the job and await the results
                var result = await task.SubmitJobAsync(parameter);

                // Poll the server every two seconds for the status of the job.
                while (result.JobStatus != GPJobStatus.Cancelled &&
                       result.JobStatus != GPJobStatus.Deleted &&
                       result.JobStatus != GPJobStatus.Failed &&
                       result.JobStatus != GPJobStatus.Succeeded &&
                       result.JobStatus != GPJobStatus.TimedOut)
                {
                    result = await task.CheckJobStatusAsync(result.JobID);

                    // show the status
                    var descriptions = result.Messages.Select(msg => msg.Description);
                    var status       = string.Join(Environment.NewLine, descriptions);
                    if (!string.IsNullOrEmpty(status))
                    {
                        StatusText = status;
                    }

                    await Task.Delay(2000);
                }

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    // Get the results
                    var resultData = await task.GetResultDataAsync(result.JobID, "Clipped_Counties");

                    if (resultData is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer resultsLayer = resultData as GPFeatureRecordSetLayer;
                        if (resultsLayer.FeatureSet != null &&
                            resultsLayer.FeatureSet.Features != null &&
                            resultsLayer.FeatureSet.Features.Count != 0)
                        {
                            // Results were returned as graphics.  Add them to the ClippedCounties collection
                            ClippedCounties = new ObservableCollection <Graphic>(resultsLayer.FeatureSet.Features);
                        }
                        else // Try to get results as a GPResultImageLayer
                        {
                            StatusText = "Clip operation complete. Retrieving results...";

                            m_clippedCountiesLayer = await task.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

                            // If successful, add the layer to the layers collection
                            if (m_clippedCountiesLayer != null)
                            {
                                m_clippedCountiesLayer.Opacity = 0.5;

                                // Insert the layer below the input layer
                                Layers.Insert(Layers.IndexOf(m_clipLinesLayer), m_clippedCountiesLayer);

                                // Wait until the result layer is initialized
                                await m_clippedCountiesLayer.InitializeAsync();
                            }
                            else
                            {
                                error = "No results found";
                            }
                        }
                    }
                    else
                    {
                        error = "Clip operation failed";
                    }
                }
                else
                {
                    error = "Clip operation failed";
                }
            }
            catch (Exception ex)
            {
                error = "Clip operation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
            {
                MessageBox.Show(error);
            }

            // Hide busy UI
            BusyVisibility    = StatusVisibility = Visibility.Collapsed;
            StatusText        = "";
            m_firstPointAdded = false;

            getInputLineAndClip();
        }
Exemplo n.º 45
0
        public async void Clip()
        {
            //get the user's input line
            var inputLine = await this.mapView.Editor.RequestShapeAsync(DrawShape.Polyline) as Polyline;

            // clear the graphics layers
            this.resultGraphicsLayer.Graphics.Clear();
            this.inputGraphicsLayer.Graphics.Clear();

            // add new graphic to layer
            this.inputGraphicsLayer.Graphics.Add(new Graphic { Geometry = inputLine, Symbol = this.simpleInputLineSymbol });

            // add the parameters
            var parameter = new GPInputParameter();
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputLine));
            parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, this.Distance));

            // poll the task
            var result = await SubmitAndPollStatusAsync(parameter);

            // add successful results to the map
            if (result.JobStatus == GPJobStatus.Succeeded)
            {
                this.Status = "Finished processing. Retrieving results...";

                var resultData = await gpTask.GetResultDataAsync(result.JobID, "Clipped_Counties");
                if (resultData is GPFeatureRecordSetLayer)
                {
                    GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
                    if (gpLayer.FeatureSet.Features.Count == 0)
                    {
                        // the the map service results
                        var resultImageLayer = await gpTask.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");

                        // make the result image layer opaque
                        GPResultImageLayer gpImageLayer = resultImageLayer;
                        gpImageLayer.Opacity = 0.5;
                        this.mapView.Map.Layers.Add(gpImageLayer);
                        this.Status = "Greater than 500 features returned.  Results drawn using map service.";
                        return;
                    }

                    // get the result features and add them to the GraphicsLayer
                    var features = gpLayer.FeatureSet.Features;
                    foreach (Feature feature in features)
                    {
                        this.resultGraphicsLayer.Graphics.Add(feature as Graphic);
                    }
                  
                }
                this.Status = "Success!!!";
            }

        }
        private async void OnStartViewShedCommand(object obj)
        {
            try
            {
                _inputOverlay = mapView.GraphicsOverlays["inputOverlay"];
                _viewshedOverlay = mapView.GraphicsOverlays["ViewshedOverlay"];

                string txtMiles = obj as string;

                ViewShedEnabled = false;
                _inputOverlay.Graphics.Clear();
                _viewshedOverlay.Graphics.Clear();

                //get the user's input point
                var inputPoint = await mapView.Editor.RequestPointAsync();

                ViewShedProgressVisible = Visibility.Visible;
                _inputOverlay.Graphics.Add(new Graphic() { Geometry = inputPoint });

                var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", inputPoint));
                parameter.GPParameters.Add(new GPLinearUnit("Viewshed_Distance ", LinearUnits.Miles, Convert.ToDouble(txtMiles)));

                ToolStatus = "Processing on server...";
                var result = await _gpTask.ExecuteAsync(parameter);
                if (result == null || result.OutParameters == null || !(result.OutParameters[0] is GPFeatureRecordSetLayer))
                    throw new ApplicationException("No viewshed graphics returned for this start point.");

                ToolStatus = "Finished processing. Retrieving results...";
                var viewshedLayer = (GPFeatureRecordSetLayer) result.OutParameters[0];
                _viewshedOverlay.Graphics.AddRange(viewshedLayer.FeatureSet.Features.OfType<Graphic>());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                ViewShedEnabled = true;
                ViewShedProgressVisible = Visibility.Collapsed;
            }
        }