private async Task <IFeatureSet> GetGeodatabaseVersionsAsync() { // Start animating the activity indicator. _progressBar.StartAnimating(); // Results will be returned as a feature set. IFeatureSet results = null; // Create new geoprocessing task. GeoprocessingTask listVersionsTask = await GeoprocessingTask.CreateAsync(_listVersionsUrl); // Create default parameters that are passed to the geoprocessing task. GeoprocessingParameters listVersionsParameters = await listVersionsTask.CreateDefaultParametersAsync(); // Create job that handles the communication between the application and the geoprocessing task. GeoprocessingJob listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters); try { // Execute analysis and wait for the results. GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync(); // Get results from the outputs. GeoprocessingFeatures listVersionsResults = (GeoprocessingFeatures)analysisResult.Outputs["Versions"]; // Set results. results = listVersionsResults.Features; } catch (Exception ex) { // Error handling if something goes wrong. if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null) { UIAlertController alert = new UIAlertController { Message = "Executing geoprocessing failed. " + listVersionsJob.Error.Message }; alert.ShowViewController(this, this); } else { UIAlertController alert = new UIAlertController { Message = "An error occurred. " + ex }; alert.ShowViewController(this, this); } } finally { // Stop the activity animation. _progressBar.StopAnimating(); } return(results); }
private async Task CalculateViewshed(MapPoint location) { // Create new geoprocessing task var viewshedTask = new GeoprocessingTask(new Uri(ViewshedUrl)); // Create input collection that contains the requested location var inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, MyMapView.SpatialReference); Feature inputFeature = inputFeatures.CreateFeature(); inputFeature.Geometry = location; await inputFeatures.AddFeatureAsync(inputFeature); // Create parameters that are passed to the used geoprocessing task GeoprocessingParameters viewshedParameters = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute); // Request output features in same SpatialReference as view. viewshedParameters.OutputSpatialReference = MyMapView.SpatialReference; // Add input location to geoprocessing parameters viewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(inputFeatures)); // Create job that handles the communication between the application and the geoprocessing task var viewshedJob = viewshedTask.CreateJob(viewshedParameters); try { // Execute analysis and wait for the results GeoprocessingResult analysisResult = await viewshedJob.GetResultAsync(); // Get results from the outputs GeoprocessingFeatures viewshedResultFeatures = analysisResult.Outputs["Viewshed_Result"] as GeoprocessingFeatures; // Add all the results as a graphics to the map IFeatureSet viewshedAreas = viewshedResultFeatures.Features; foreach (var feature in viewshedAreas) { _resultOverlay.Graphics.Add(new Graphic(feature.Geometry)); } } catch (Exception ex) { if (viewshedJob.Status == JobStatus.Failed && viewshedJob.Error != null) { MessageBox.Show("Executing geoprocessing failed. " + viewshedJob.Error.Message, "Geoprocessing error"); } else { MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error"); } } finally { SetBusy(false); } }
private async Task <IFeatureSet> GetGeodatabaseVersionsAsync() { // Results will be returned as a feature set IFeatureSet results = null; // Create new geoprocessing task var listVersionsTask = await GeoprocessingTask.CreateAsync(new Uri(ListVersionsUrl)); // Create parameters that are passed to the used geoprocessing task GeoprocessingParameters listVersionsParameters = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute); // Create job that handles the communication between the application and the geoprocessing task var listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters); try { // Execute analysis and wait for the results GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync(); // Get results from the outputs GeoprocessingFeatures listVersionsResults = analysisResult.Outputs["Versions"] as GeoprocessingFeatures; // Set results results = listVersionsResults.Features; } catch (Exception ex) { // Error handling if something goes wrong if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null) { var alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetTitle("Geoprocessing error"); alertBuilder.SetMessage("Executing geoprocessing failed. " + listVersionsJob.Error.Message); alertBuilder.Show(); } else { var alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetTitle("Sample error"); alertBuilder.SetMessage("An error occurred. " + ex.ToString()); alertBuilder.Show(); } } finally { // Set the UI to indicate that the geoprocessing is not running SetBusy(false); } return(results); }
private async Task <IFeatureSet> GetGeodatabaseVersionsAsync() { // Results will be returned as a feature set IFeatureSet results = null; // Create new geoprocessing task var listVersionsTask = await GeoprocessingTask.CreateAsync(ListVersionsUrl); // Create default parameters that are passed to the geoprocessing task GeoprocessingParameters listVersionsParameters = await listVersionsTask.CreateDefaultParametersAsync(); // Create job that handles the communication between the application and the geoprocessing task var listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters); try { // Execute analysis and wait for the results GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync(); // Get results from the outputs GeoprocessingFeatures listVersionsResults = analysisResult.Outputs["Versions"] as GeoprocessingFeatures; // Set results results = listVersionsResults.Features; } catch (Exception ex) { // Error handling if something goes wrong if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null) { UIAlertController alert = new UIAlertController(); alert.Message = "Executing geoprocessing failed. " + listVersionsJob.Error.Message; alert.ShowViewController(this, this); } else { UIAlertController alert = new UIAlertController(); alert.Message = "An error occurred. " + ex.ToString(); alert.ShowViewController(this, this); } } finally { // Set the UI to indicate that the geoprocessing is not running SetBusy(false); } return(results); }
private async Task <IFeatureSet> GetGeodatabaseVersionsAsync() { // Results will be returned as a feature set IFeatureSet results = null; // Create new geoprocessing task GeoprocessingTask listVersionsTask = await GeoprocessingTask.CreateAsync(new Uri(ListVersionsUrl)); // Create default parameters that are passed to the geoprocessing task GeoprocessingParameters listVersionsParameters = await listVersionsTask.CreateDefaultParametersAsync(); // Create job that handles the communication between the application and the geoprocessing task GeoprocessingJob listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters); try { // Execute analysis and wait for the results GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync(); // Get results from the outputs GeoprocessingFeatures listVersionsResults = (GeoprocessingFeatures)analysisResult.Outputs["Versions"]; // Set results results = listVersionsResults.Features; } catch (Exception ex) { // Error handling if something goes wrong if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null) { await Application.Current.MainPage.DisplayAlert("Geoprocessing error", "Executing geoprocessing failed. " + listVersionsJob.Error.Message, "OK"); } else { await Application.Current.MainPage.DisplayAlert("Sample error", "An error occurred. " + ex.ToString(), "OK"); } } finally { // Set the UI to indicate that the geoprocessing is not running SetBusy(false); } return(results); }
private async Task CalculateViewshed(MapPoint location) { // This function will define a new geoprocessing task that performs a custom viewshed analysis based upon a // user click on the map and then display the results back as a polygon fill graphics overlay. If there // is a problem with the execution of the geoprocessing task an error message will be displayed // Create new geoprocessing task using the url defined in the member variables section GeoprocessingTask myViewshedTask = await GeoprocessingTask.CreateAsync(new Uri(_viewshedUrl)); // Create a new feature collection table based upon point geometries using the current map view spatial reference FeatureCollectionTable myInputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, MyMapView.SpatialReference); // Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet Feature myInputFeature = myInputFeatures.CreateFeature(); // Assign a physical location to the new point feature based upon where the user clicked in the map view myInputFeature.Geometry = location; // Add the new feature with (x,y) location to the feature collection table await myInputFeatures.AddFeatureAsync(myInputFeature); // Create the parameters that are passed to the used geoprocessing task GeoprocessingParameters myViewshedParameters = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute) { // Request the output features to use the same SpatialReference as the map view OutputSpatialReference = MyMapView.SpatialReference }; // Add an input location to the geoprocessing parameters myViewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(myInputFeatures)); // Create the job that handles the communication between the application and the geoprocessing task GeoprocessingJob myViewshedJob = myViewshedTask.CreateJob(myViewshedParameters); try { // Execute analysis and wait for the results GeoprocessingResult myAnalysisResult = await myViewshedJob.GetResultAsync(); // Get the results from the outputs GeoprocessingFeatures myViewshedResultFeatures = (GeoprocessingFeatures)myAnalysisResult.Outputs["Viewshed_Result"]; // Add all the results as a graphics to the map IFeatureSet myViewshedAreas = myViewshedResultFeatures.Features; foreach (Feature myFeature in myViewshedAreas) { _resultOverlay.Graphics.Add(new Graphic(myFeature.Geometry)); } } catch (Exception ex) { // Display an error message if there is a problem if (myViewshedJob.Status == JobStatus.Failed && myViewshedJob.Error != null) { MessageBox.Show("Executing geoprocessing failed. " + myViewshedJob.Error.Message, "Geoprocessing error"); } else { MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error"); } } finally { // Indicate that the geoprocessing is not running SetBusy(false); } }
private async Task CalculateViewshed(MapPoint location) { // This function will define a new geoprocessing task that performs a custom viewshed analysis based upon a // user click on the map and then display the results back as a polygon fill graphics overlay. If there // is a problem with the execution of the geoprocessing task an error message will be displayed. // Create new geoprocessing task using the URL defined in the member variables section. GeoprocessingTask viewshedTask = await GeoprocessingTask.CreateAsync(new Uri(ViewshedServiceUrl)); // Create a new feature collection table based upon point geometries using the current map view spatial reference. FeatureCollectionTable inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, _myMapView.SpatialReference); // Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet. Feature inputFeature = inputFeatures.CreateFeature(); // Assign a physical location to the new point feature based upon where the user clicked in the map view. inputFeature.Geometry = location; // Add the new feature with (x,y) location to the feature collection table. await inputFeatures.AddFeatureAsync(inputFeature); // Create the parameters that are passed to the used geoprocessing task. GeoprocessingParameters viewshedParameters = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute) { OutputSpatialReference = _myMapView.SpatialReference }; // Add an input location to the geoprocessing parameters. viewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(inputFeatures)); // Create the job that handles the communication between the application and the geoprocessing task. GeoprocessingJob viewshedJob = viewshedTask.CreateJob(viewshedParameters); try { // Execute analysis and wait for the results. GeoprocessingResult analysisResult = await viewshedJob.GetResultAsync(); // Get the results from the outputs. GeoprocessingFeatures viewshedResultFeatures = (GeoprocessingFeatures)analysisResult.Outputs["Viewshed_Result"]; // Add all the results as a graphics to the map. foreach (Feature feature in viewshedResultFeatures.Features) { _resultOverlay.Graphics.Add(new Graphic(feature.Geometry)); } } catch (Exception ex) { // Display an error message if there is a problem. if (viewshedJob.Status == JobStatus.Failed && viewshedJob.Error != null) { // Report error UIAlertController alert = UIAlertController.Create("Geoprocessing Error", viewshedJob.Error.Message, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { // Report error UIAlertController alert = UIAlertController.Create("Sample Error", ex.ToString(), UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } } }
private async void ExecuteGPService() { //加载DEM并且缩放到该区域 Map map = new Map(Basemap.CreateTopographic()); string pathToRaster = @"D:\work\github\ExecuteGPK\LasVegasNED13_geoid1.tif"; var myRaster = new Raster(pathToRaster); // create a RasterLayer using the Raster var newRasterLayer = new RasterLayer(myRaster); map.OperationalLayers.Add(newRasterLayer); Viewpoint viewPoint = new Viewpoint(36.131, -115.144, 800000); myMapView.Map = map; await myMapView.SetViewpointAsync(viewPoint, TimeSpan.FromSeconds(2)); StartLocalServer(); LocalGeoprocessingService localServiceGP = new LocalGeoprocessingService(@"D:\work\github\ExecuteGPK\InterpolateShape.gpk"); localServiceGP.ServiceType = GeoprocessingServiceType.SynchronousExecute; // Handle the status changed event to check when it's loaded localServiceGP.StatusChanged += async(svc, args) => { // If service started successfully, create a gp task if (args.Status == LocalServerStatus.Started) { // Get the URL for the specific geoprocessing tool var gpSvcUrl = (svc as LocalGeoprocessingService).Url.AbsoluteUri + "/InterpolateShape"; // Create the geoprocessing task GeoprocessingTask gpRouteTask = new GeoprocessingTask(new Uri(gpSvcUrl)); GeoprocessingParameters para = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute); // Create the schema for a lines table (one text field to contain a name attribute) var inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Polyline, myMapView.SpatialReference); Feature inputFeature = inputFeatures.CreateFeature(); var geometry = await myMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline, false); inputFeature.Geometry = geometry; await inputFeatures.AddFeatureAsync(inputFeature); para.Inputs.Add("inputLine", new GeoprocessingFeatures(inputFeatures)); para.ReturnZ = true; para.OutputSpatialReference = myMapView.SpatialReference; GeoprocessingJob routeJob = gpRouteTask.CreateJob(para); try { // Execute analysis and wait for the results GeoprocessingResult geoprocessingResult = await routeJob.GetResultAsync(); GeoprocessingFeatures resultFeatures = geoprocessingResult.Outputs["outputLine"] as GeoprocessingFeatures; IFeatureSet interpolateShapeResult = resultFeatures.Features; Esri.ArcGISRuntime.Geometry.Polyline elevationLine = interpolateShapeResult.First().Geometry as Esri.ArcGISRuntime.Geometry.Polyline; MapPoint startPoint = elevationLine.Parts[0].Points[0]; int count = elevationLine.Parts[0].PointCount; MapPoint stopPoint = elevationLine.Parts[0].Points[count - 1]; double chazhi = stopPoint.Z - startPoint.Z; MessageBox.Show("终点的Z值为: " + stopPoint.Z.ToString() + ",起点的Z值为: " + startPoint.Z.ToString()); } catch (Exception ex) { if (routeJob.Status == JobStatus.Failed && routeJob.Error != null) { MessageBox.Show("Executing geoprocessing failed. " + routeJob.Error.Message, "Geoprocessing error"); } else { MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error"); } } // Create parameters, run the task, process results, etc. // ... } }; // Start the local geoprocessing service await localServiceGP.StartAsync(); }