Beispiel #1
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);
        }
        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 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();


        }
Beispiel #4
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();
        }
		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;
			}
		}
        // 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();
            }
        }
        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;
            }
        }
 private void CheckJobStatus(JobResult jobResult, string taskUrl, string outputName, object userToken = null)
 {
     var d = new DispatcherTimer();
     d.Interval = TimeSpan.FromMilliseconds(UpdateDelay);
     var gp = new Geoprocessor(taskUrl) { Token = Token, DisableClientCaching = true };
     gp.StatusUpdated += (s, e) =>
     {
         if (e.JobInfo.JobStatus == esriJobStatus.esriJobCancelled ||
             e.JobInfo.JobStatus == esriJobStatus.esriJobDeleted ||
             e.JobInfo.JobStatus == esriJobStatus.esriJobFailed ||
             e.JobInfo.JobStatus == esriJobStatus.esriJobSucceeded ||
             e.JobInfo.JobStatus == esriJobStatus.esriJobTimedOut)
         {
             d.Stop();
             if (e.JobInfo.JobStatus == esriJobStatus.esriJobSucceeded)
                 GetResultLayer(jobResult, taskUrl, outputName, userToken);
             else
                 OnAnalysisCompleted(new AnalysisEventArgs(new Exception(string.Format("Job has been {0}", e.JobInfo.JobStatus.ToString().ToLower().Replace("esrijob", string.Empty))), userToken));
         }
     };
     d.Tick += (s, e) =>
     {
         gp.CheckJobStatusAsync(jobResult.ID);
     };
     d.Start();
 }
Beispiel #10
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 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 = "";
        }
Beispiel #12
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;
            }
        }