/// <summary>
        /// Handles the click event of the Button and starts asynchronous geoprocessing.
        /// </summary>
        private void btnRunGP_Click(object sender, EventArgs e)
        {
            try
            {
                #region tidy up any previous gp runs

                //Clear the ListView control
                listView1.Items.Clear();

                //Remove any result layers present in the map
                IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
                foreach (IFeatureLayer resultLayer in _resultsList)
                {
                    mapLayers.DeleteLayer(resultLayer);
                }

                axTOCControl1.Update();

                //Empty the results layer list
                _resultsList.Clear();

                //make sure that my GP tool queue is empty
                _myGPToolsToExecute.Clear();

                #endregion

                //Buffer the selected cities by the specified distance
                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
                bufferTool.in_features = _layersDict["Cities"];
                bufferTool.buffer_distance_or_field = txtBufferDistance.Text + " Miles";
                bufferTool.out_feature_class        = "city_buffer.shp";

                //Clip the zip codes layer with the result of the buffer tool
                ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
                clipTool.in_features       = _layersDict["ZipCodes"];
                clipTool.clip_features     = bufferTool.out_feature_class;
                clipTool.out_feature_class = "city_buffer_clip.shp";

                //To run multiple GP tools asynchronously, all tool inputs must exist before ExecuteAsync is called.
                //The output from the first buffer operation is used as an input to the second clip
                //operation. To deal with this restriction a Queue is created and all tools added to it. The first tool
                //is executed from this method, whereas the second is executed from the ToolExecuted event. This approach
                //is scalable - any additional geoprocessing tools added to this queue will also be executed in turn.
                _myGPToolsToExecute.Enqueue(bufferTool);
                _myGPToolsToExecute.Enqueue(clipTool);
                _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue());
            }
            catch (Exception ex)
            {
                listView1.Items.Add(new ListViewItem(new string[2] {
                    "N/A", ex.Message
                }, "error"));
            }
        }
Beispiel #2
0
        public static void GetTysonPolygon()
        {
            IFeatureLayer pStudentLayer = Func.GetFeatureLayerByName("Students");
            IFeatureLayer pChinaLayer   = Func.GetFeatureLayerByName("BOUA_PJ");
            string        strOutput     = Application.StartupPath + @"\Data\TysonAll.shp";

            Geoprocessor gp = new Geoprocessor()
            {
                OverwriteOutput = true
            };

            ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons pCreateThiessenPolygons = new ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons()
            {
                in_features       = pStudentLayer,
                out_feature_class = strOutput,
                fields_to_copy    = "ONLY_FID"
            };
            IGeoProcessorResult pResult = gp.ExecuteAsync(pCreateThiessenPolygons);

            new Timer()
            {
                Enabled  = true,
                Interval = 500
            }.Tick += (sender, e) => {
                if (pResult.Status == esriJobStatus.esriJobSucceeded)
                {
                    ESRI.ArcGIS.AnalysisTools.Clip pClip = new ESRI.ArcGIS.AnalysisTools.Clip()
                    {
                        in_features       = strOutput,
                        clip_features     = pChinaLayer,
                        out_feature_class = Application.StartupPath + @"\Data\tyson.shp"
                    };
                    pResult = gp.ExecuteAsync(pClip);
                    new Timer()
                    {
                        Enabled  = true,
                        Interval = 500
                    }.Tick += (sender2, e2) => {
                        if (pResult.Status == esriJobStatus.esriJobSucceeded)
                        {
                            m_pMapC2.AddShapeFile(Application.StartupPath + @"\Data", "tyson.shp");
                            SetTysonSymbol();
                            (sender2 as Timer).Enabled = false;
                            CloseWaitForm();
                        }
                    };
                    (sender as Timer).Enabled = false;
                }
            };
        }
Beispiel #3
0
            //注册要素类
            /// <summary>
            /// 返回true说明FeatureClass存在,返回false说明不存在,重新创建
            /// </summary>
            /// <param name="IN_ShapePath"></param>
            /// <returns></returns>
            private bool PRV_AddFeatureClass(string IN_ShapePath)
            {
                string            Temp_Direction         = System.IO.Path.GetDirectoryName(IN_ShapePath);            //该Shp文件的目录
                string            Temp_Name              = System.IO.Path.GetFileNameWithoutExtension(IN_ShapePath); //该Shp文件的名称
                IWorkspaceFactory Temp_ShapeWorkFactory  = new ShapefileWorkspaceFactory();
                IFeatureWorkspace Temp_ShapeWorkspace    = Temp_ShapeWorkFactory.OpenFromFile(Temp_Direction, 0) as IFeatureWorkspace;
                IWorkspaceFactory Temp_AccessWorkFactory = new AccessWorkspaceFactory();
                IFeatureWorkspace Temp_Workspace         = Temp_AccessWorkFactory.OpenFromFile(S_MDBFile, 0) as IFeatureWorkspace;

                IFeatureClassContainer tem_FeatureClassContainer = (IFeatureClassContainer)FDS_Featuredataset;
                IEnumFeatureClass      pEnumFeatureClass         = (IEnumFeatureClass)tem_FeatureClassContainer.Classes;
                IFeatureClass          tem_FeatureClass          = pEnumFeatureClass.Next();

                while (null != tem_FeatureClass)
                {
                    if (Temp_Name == tem_FeatureClass.AliasName)
                    {// return true;
                    }
                    tem_FeatureClass = pEnumFeatureClass.Next();
                }

                IFeatureClass Temp_FeatureClass        = Temp_ShapeWorkspace.OpenFeatureClass(Temp_Name);
                FeatureClassToFeatureClass Temp_FCToFC = new FeatureClassToFeatureClass(IN_ShapePath, S_MDBFile + "\\" + FDS_Featuredataset.Name, Temp_Name);//将Shp文件导入要素数据集

                GP_Progress = GP_Tool.ExecuteAsync(Temp_FCToFC);
                TH_TimeSpan = new Thread(PRV_GetStatus);//开辟线程计时
                TH_TimeSpan.Start();
                TH_TimeSpan.Join();

                return(false);
                // IFeatureClassContainer ss = (FDS_Featuredataset.Workspace as IFeatureWorkspace).OpenFeatureDataset(FDS_Featuredataset.Name) as IFeatureClassContainer;
                //  Console.WriteLine("完成");
            }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            _geoprocessorTask.CancelAsync();

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint,
            };

            graphic.Attributes.Add("Info", "Start location");
            string latlon = String.Format("{0}, {1}", e.MapPoint.X, e.MapPoint.Y);

            graphic.Attributes.Add("LatLon", latlon);
            graphic.SetZIndex(1);
            graphicsLayer.Graphics.Add(graphic);

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.MapPoint));
            parameters.Add(new GPString("Drive_Times", "1 2 3"));

            _geoprocessorTask.ExecuteAsync(parameters);
        }
Beispiel #5
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;
            }
        }
        public FeatureLayerChangeVersion()
        {
            InitializeComponent();

            featureLayer = (MyMap.Layers["ServiceConnections"] as FeatureLayer);

            Geoprocessor gp_ListVersions = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions");

            gp_ListVersions.Failed += (s, a) =>
            {
                MessageBox.Show("Geoprocessing service failed: " + a.Error);
            };

            gp_ListVersions.ExecuteCompleted += (c, d) =>
            {
                VersionsCombo.DataContext = (d.Results.OutParameters[0] as GPRecordSet).FeatureSet;

                foreach (Graphic g in (d.Results.OutParameters[0] as GPRecordSet).FeatureSet.Features)
                {
                    if ((g.Attributes["name"] as string) == featureLayer.GdbVersion)
                    {
                        VersionsCombo.SelectedValue = g;
                        break;
                    }
                }
            };

            List <GPParameter> gpparams = new List <GPParameter>();

            gpparams.Add(new GPRecordSet("Versions", new FeatureSet()));
            gp_ListVersions.ExecuteAsync(gpparams);
        }
        public static void ClipRaster(string inRaster, string inClipFeature, string outTempRaster)
        {
            Clip clipTool = new Clip();

            //set clip parameters
            clipTool.in_raster = inRaster;
            clipTool.out_raster = outTempRaster;

            //clip extent
            clipTool.in_template_dataset = inClipFeature;

            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;

            try
            {

               IGeoProcessorResult result = (IGeoProcessorResult)gp.ExecuteAsync(clipTool);

               while(result.Status != esriJobStatus.esriJobSucceeded)
               {
                   //Console.WriteLine(result.Status.ToString());
                   System.Threading.Thread.Sleep(100);
               }

            }
            catch (Exception ex)
            {
                object level = 0;
                Console.WriteLine(gp.GetMessages(ref level));
                Console.WriteLine(" Failed to clip raster using ESRI clip tool " + ex.Message);
            }
        }
        public static void ClipRaster(string inRaster, string inClipFeature, string outTempRaster)
        {
            Clip clipTool = new Clip();

            //set clip parameters
            clipTool.in_raster  = inRaster;
            clipTool.out_raster = outTempRaster;

            //clip extent
            clipTool.in_template_dataset = inClipFeature;

            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;

            try
            {
                IGeoProcessorResult result = (IGeoProcessorResult)gp.ExecuteAsync(clipTool);

                while (result.Status != esriJobStatus.esriJobSucceeded)
                {
                    //Console.WriteLine(result.Status.ToString());
                    System.Threading.Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                object level = 0;
                Console.WriteLine(gp.GetMessages(ref level));
                Console.WriteLine(" Failed to clip raster using ESRI clip tool " + ex.Message);
            }
        }
        public FeatureLayerChangeVersion()
        {
            InitializeComponent();

            featureLayer = (MyMap.Layers["ServiceConnections"] as FeatureLayer);

            Geoprocessor gp_ListVersions = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions");

            gp_ListVersions.Failed += (s, a) =>
            {
                MessageBox.Show("Geoprocessing service failed: " + a.Error);
            };

            gp_ListVersions.ExecuteCompleted += (c, d) =>
            {
                VersionsCombo.DataContext = (d.Results.OutParameters[0] as GPRecordSet).FeatureSet;

                foreach (Graphic g in (d.Results.OutParameters[0] as GPRecordSet).FeatureSet.Features)
                {
                    if ((g.Attributes["name"] as string) == featureLayer.GdbVersion)
                    {
                        VersionsCombo.SelectedValue = g;
                        break;
                    }
                }
            };

            List<GPParameter> gpparams = new List<GPParameter>();
            gpparams.Add(new GPRecordSet("Versions", new FeatureSet()));
            gp_ListVersions.ExecuteAsync(gpparams);
        }
Beispiel #10
0
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs e)
        {
            MyDrawObject.IsEnabled = false;

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = e.Geometry as MapPoint
            };

            graphicsLayer.Graphics.Add(graphic);

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

            geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;
            geoprocessorTask.Failed           += GeoprocessorTask_Failed;

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Point", e.Geometry as MapPoint));
            parameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

            geoprocessorTask.ExecuteAsync(parameters);
        }
Beispiel #11
0
        // ***********************************************************************************
        // * ...Find the nearest Weather Station
        // ***********************************************************************************
        private void btnLookupWindDirection_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_spillLocationGraphicsLayer.Graphics.Count > 0)
                {
                    List <GPParameter> parameters = new List <GPParameter>();

                    client.Projection.WebMercator        wm       = new client.Projection.WebMercator();
                    ESRI.ArcGIS.Client.Geometry.Geometry geoPoint = wm.ToGeographic(_spillLocationGraphicsLayer.Graphics[0].Geometry);

                    parameters.Add(new GPFeatureRecordSetLayer("Feature_Set", geoPoint));

                    Geoprocessor findNearestWSGPTask = new Geoprocessor(_findNearestWSURL);
                    findNearestWSGPTask.OutputSpatialReference = _mapWidget.Map.SpatialReference;

                    findNearestWSGPTask.ExecuteCompleted += findNearestWSGPTask_ExecuteCompleted;
                    findNearestWSGPTask.Failed           += GeoprocessorTask_Failed;
                    findNearestWSGPTask.ExecuteAsync(parameters);
                }
                else
                {
                    MessageBox.Show("Please add the incident location on the map first!", "Warning");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                MessageBox.Show("Could not get wind direction!", "Error");
                return;
            }
        }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            _geoprocessorTask.CancelAsync();

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            MapPoint mapPoint = e.MapPoint;

            mapPoint.SpatialReference = new SpatialReference(4326);

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = mapPoint
            };

            graphicsLayer.Graphics.Add(graphic);

            MyMap.Cursor = System.Windows.Input.Cursors.Wait;

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", mapPoint));
            parameters.Add(new GPLinearUnit("Viewshed_Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));

            _geoprocessorTask.OutputSpatialReference = new SpatialReference(4326);
            _geoprocessorTask.ExecuteAsync(parameters);
        }
        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();
            }
        }
Beispiel #14
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;
            }
        }
		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();
		}
        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;
        }
        // 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;
            }
        }
Beispiel #18
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;
            }
        }
        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();
            }
        }
Beispiel #20
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;
            }
        }
Beispiel #21
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;
            }
        }
        // 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;
            }
        }
        // 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;
            }
        }
Beispiel #24
0
        /// <summary>
        /// 调用GP执行具体的tool
        /// </summary>
        /// <param name="process"></param>
        /// <returns></returns>
        private static bool RunGPTool(IGPProcess process)
        {
            try
            {
                Geoprocessor GP = new Geoprocessor();
                GP.OverwriteOutput = true;

                IGeoProcessorResult result = (IGeoProcessorResult)GP.ExecuteAsync(process);
                if (result != null && result.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    return(true);
                }
                return(false);
            }
            catch
            {
                throw;
            }
        }
        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 void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            Graphic graphic = new Graphic()
            {
                Symbol =  LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint
            };
            _graphicsLayer.Graphics.Add(graphic);

            Geoprocessor geoprocessorTask = new Geoprocessor("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle");
            geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;
            geoprocessorTask.Failed += GeoprocessorTask_Failed;
            geoprocessorTask.OutputSpatialReference = MyMap.SpatialReference;

            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPFeatureRecordSetLayer("Input_Point", _mercator.ToGeographic(e.MapPoint)));
            parameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

            geoprocessorTask.ExecuteAsync(parameters);
        }
        public FeatureLayerChangeVersion()
        {
            InitializeComponent();
              Geoprocessor gp_ListVersions = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions");

              gp_ListVersions.Failed += (s, a) =>
              {
            MessageBox.Show("Geoprocessing service failed: " + a.Error);
              };

              gp_ListVersions.ExecuteCompleted += (c, d) =>
              {
            VersionsCombo.DataContext = (d.Results.OutParameters[0] as GPRecordSet).FeatureSet;
            VersionsCombo.SelectedIndex = 0;
              };

              List<GPParameter> gpparams = new List<GPParameter>();
              gpparams.Add(new GPRecordSet("Versions", new FeatureSet()));
              gp_ListVersions.ExecuteAsync(gpparams);
        }
       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;
           }
       }
Beispiel #29
0
        public FeatureLayerChangeVersion()
        {
            InitializeComponent();
            Geoprocessor gp_ListVersions = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions");

            gp_ListVersions.Failed += (s, a) =>
            {
                MessageBox.Show("Geoprocessing service failed: " + a.Error);
            };

            gp_ListVersions.ExecuteCompleted += (c, d) =>
            {
                VersionsCombo.DataContext   = (d.Results.OutParameters[0] as GPRecordSet).FeatureSet;
                VersionsCombo.SelectedIndex = 0;
            };

            List <GPParameter> gpparams = new List <GPParameter>();

            gpparams.Add(new GPRecordSet("Versions", new FeatureSet()));
            gp_ListVersions.ExecuteAsync(gpparams);
        }
        // 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;
            }
        }
        // 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;
            }
        }
	   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 = 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;
		}
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint
            };

            _graphicsLayer.Graphics.Add(graphic);

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

            geoprocessorTask.ExecuteCompleted      += GeoprocessorTask_ExecuteCompleted;
            geoprocessorTask.Failed                += GeoprocessorTask_Failed;
            geoprocessorTask.OutputSpatialReference = MyMap.SpatialReference;

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Point", _mercator.ToGeographic(e.MapPoint)));
            parameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

            geoprocessorTask.ExecuteAsync(parameters);
        }
        private void MyDrawObject_OnDrawComplete(object sender, DrawEventArgs args)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            Graphic graphic = new Graphic()
            {
              Symbol = LayoutRoot.Resources["BlueLineSymbol"] as Symbol,
              Geometry = args.Geometry
            };
            graphicsLayer.Graphics.Add(graphic);

            Geoprocessor geoprocessorTask = new Geoprocessor("http://sampleserver2.arcgisonline.com/ArcGIS/rest/services/" +
                "Elevation/ESRI_Elevation_World/GPServer/ProfileService");
            geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;
            geoprocessorTask.Failed += GeoprocessorTask_Failed;

            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPFeatureRecordSetLayer("Input_Polylines", args.Geometry));
            parameters.Add(new GPLong("Image_Width", 600));
            parameters.Add(new GPLong("Image_Height", 250));
            parameters.Add(new GPBoolean("Display_Segments", true));

            geoprocessorTask.ExecuteAsync(parameters);
        }
        // ***********************************************************************************
        // * ...Find the nearest Weather Station 
        // ***********************************************************************************
        private void btnLookupWindDirection_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_spillLocationGraphicsLayer.Graphics.Count > 0)
                {
                    List<GPParameter> parameters = new List<GPParameter>();

                    client.Projection.WebMercator wm = new client.Projection.WebMercator();
                    ESRI.ArcGIS.Client.Geometry.Geometry geoPoint = wm.ToGeographic(_spillLocationGraphicsLayer.Graphics[0].Geometry);

                    parameters.Add(new GPFeatureRecordSetLayer("Feature_Set", geoPoint));

                    Geoprocessor findNearestWSGPTask = new Geoprocessor(_findNearestWSURL);
                    findNearestWSGPTask.OutputSpatialReference = _mapWidget.Map.SpatialReference;

                    findNearestWSGPTask.ExecuteCompleted += findNearestWSGPTask_ExecuteCompleted;
                    findNearestWSGPTask.Failed += GeoprocessorTask_Failed;
                    findNearestWSGPTask.ExecuteAsync(parameters);
                }
                else
                {
                    MessageBox.Show("Please add the incident location on the map first!", "Warning");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                MessageBox.Show("Could not get wind direction!", "Error");
                return;
            }
        }
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs e)
        {
            MyDrawObject.IsEnabled = false;

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();

            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = e.Geometry as MapPoint
            };
            graphicsLayer.Graphics.Add(graphic);

            Geoprocessor geoprocessorTask = new Geoprocessor("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                "Specialty/ESRI_Currents_World/GPServer/MessageInABottle");
            geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;
            geoprocessorTask.Failed += GeoprocessorTask_Failed;

            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPFeatureRecordSetLayer("Input_Point", e.Geometry as MapPoint));
            parameters.Add(new GPDouble("Days", Convert.ToDouble(DaysTextBox.Text)));

            geoprocessorTask.ExecuteAsync(parameters);
        }
        // ***********************************************************************************
        // * ...Execute Placard of ERG Chemical GP Tool 
        // ***********************************************************************************
        private void btnSolve_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_spillLocationGraphicsLayer.Graphics.Count > 0)
                {
                    Geoprocessor geoprocessorTask = new Geoprocessor();
                    if (cmbChemicalOrPlacardType.SelectedValue == null)
                    {
                        MessageBox.Show("Check your material or placard type!", "Error");
                        return;
                    }

                    var materialType = cmbChemicalOrPlacardType.SelectedValue.ToString();
                    var spillTime = cmbSpillTime.SelectedValue.ToString();
                    var spillSize = cmbSpillSize.SelectedValue.ToString();
                    var windDir = Convert.ToInt32(windDirection.Value);
                    List<GPParameter> parameters = new List<GPParameter>();

                    parameters.Add(new GPFeatureRecordSetLayer("in_features", new FeatureSet(_spillLocationGraphicsLayer.Graphics)));

                    if (cmbChemicalorPlacard.SelectedValue.ToString() == "Chemical")
                    {
                        geoprocessorTask.Url = _chemicalURL;
                        parameters.Add(new GPString("material_type", materialType));
                        geoprocessorTask.JobCompleted += ergChemicalGeoprocessorTask_JobCompleted;
                    }
                    else
                    {
                        geoprocessorTask.Url = _placardURL;
                        geoprocessorTask.JobCompleted += ergPlacardGeoprocessorTask_JobCompleted;
                        parameters.Add(new GPString("placard_id", materialType));
                    }

                    geoprocessorTask.OutputSpatialReference = _mapWidget.Map.SpatialReference;
                    geoprocessorTask.ProcessSpatialReference = _mapWidget.Map.SpatialReference;

                    if (_windDirectionQuestionResult == MessageBoxResult.No)
                        parameters.Add(new GPLong("wind_bearing", windDir));
                    else
                        parameters.Add(new GPLong("wind_bearing", _windDirectionTo));

                    parameters.Add(new GPString("time_of_day", spillTime));
                    parameters.Add(new GPString("spill_size", spillSize));


                    if (_gpExecutionType == "esriExecutionTypeSynchronous")
                    {
                        geoprocessorTask.ExecuteCompleted += ERGGeoprocessorTask_ExecuteCompleted;
                        geoprocessorTask.Failed += GeoprocessorTask_Failed;
                        geoprocessorTask.ExecuteAsync(parameters);
                    }
                    else
                        geoprocessorTask.SubmitJobAsync(parameters);
                }
                else
                    MessageBox.Show("Please add spill location on the map", "Error");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return;
            }
        }
        // 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;
        }
Beispiel #41
0
        // ***********************************************************************************
        // * ...Execute Placard of ERG Chemical GP Tool
        // ***********************************************************************************
        private void btnSolve_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_spillLocationGraphicsLayer.Graphics.Count > 0)
                {
                    Geoprocessor geoprocessorTask = new Geoprocessor();
                    if (cmbChemicalOrPlacardType.SelectedValue == null)
                    {
                        MessageBox.Show("Check your material or placard type!", "Error");
                        return;
                    }

                    var materialType = cmbChemicalOrPlacardType.SelectedValue.ToString();
                    var spillTime    = cmbSpillTime.SelectedValue.ToString();
                    var spillSize    = cmbSpillSize.SelectedValue.ToString();
                    var windDir      = Convert.ToInt32(windDirection.Value);
                    List <GPParameter> parameters = new List <GPParameter>();

                    parameters.Add(new GPFeatureRecordSetLayer("in_features", new FeatureSet(_spillLocationGraphicsLayer.Graphics)));

                    if (cmbChemicalorPlacard.SelectedValue.ToString() == "Chemical")
                    {
                        geoprocessorTask.Url = _chemicalURL;
                        parameters.Add(new GPString("material_type", materialType));
                        geoprocessorTask.JobCompleted += ergChemicalGeoprocessorTask_JobCompleted;
                    }
                    else
                    {
                        geoprocessorTask.Url           = _placardURL;
                        geoprocessorTask.JobCompleted += ergPlacardGeoprocessorTask_JobCompleted;
                        parameters.Add(new GPString("placard_id", materialType));
                    }

                    geoprocessorTask.OutputSpatialReference  = _mapWidget.Map.SpatialReference;
                    geoprocessorTask.ProcessSpatialReference = _mapWidget.Map.SpatialReference;

                    if (_windDirectionQuestionResult == MessageBoxResult.No)
                    {
                        parameters.Add(new GPLong("wind_bearing", windDir));
                    }
                    else
                    {
                        parameters.Add(new GPLong("wind_bearing", _windDirectionTo));
                    }

                    parameters.Add(new GPString("time_of_day", spillTime));
                    parameters.Add(new GPString("spill_size", spillSize));


                    if (_gpExecutionType == "esriExecutionTypeSynchronous")
                    {
                        geoprocessorTask.ExecuteCompleted += ERGGeoprocessorTask_ExecuteCompleted;
                        geoprocessorTask.Failed           += GeoprocessorTask_Failed;
                        geoprocessorTask.ExecuteAsync(parameters);
                    }
                    else
                    {
                        geoprocessorTask.SubmitJobAsync(parameters);
                    }
                }
                else
                {
                    MessageBox.Show("Please add spill location on the map", "Error");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return;
            }
        }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            IsBusy = true;
            // Cancel any outstanding Tasks
            _gpTask.CancelAsync();

            // Get the GraphicsLayer
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();
            e.MapPoint.SpatialReference = MyMap.SpatialReference;

            // Add a graphic at the click point
            Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = e.MapPoint,
                Symbol   = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };

            graphic.SetZIndex(1);
            graphicsLayer.Graphics.Add(graphic);

            // Create the graphic to submit.
            Graphic g = new Graphic()
            {
                Geometry = _mercator.ToGeographic(e.MapPoint)
            };

            // Create a new list of GP Parameters
            List <GPParameter> gpParams = new List <GPParameter>();

            // We want to specify input attributes - create a new FeatureSet.
            FeatureSet featureSet = new FeatureSet();

            // Create the Fields and add one called "VALUE".
            featureSet.Fields = new List <Field> {
                new Field()
                {
                    FieldName = "VALUE", Type = Field.FieldType.String, Alias = "VALUE"
                }
            };

            //var fs = new FeatureSet(new List<Graphic> { g });
            // Add the graphic to the FeatureSet
            featureSet.Features.Add(g);

            // Set the graphic's attribute
            featureSet.Features[0].Attributes["VALUE"] = valueText.Text;

            // Add the GP Paramr
            gpParams.Add(new GPFeatureRecordSetLayer("InputFeatures", featureSet));
            gpParams.Add(new GPLinearUnit("Distance", esriUnits.esriKilometers, 500));

            // Register an inline handler for ExecuteCompleted event
            _gpTask.ExecuteCompleted += (s, e1) =>
            {
                // Clear the graphics layer (will remove the input Pushpin)
                graphicsLayer.Graphics.Clear();

                // Get the results
                GPExecuteResults        results = e1.Results;
                GPFeatureRecordSetLayer rs      = results.OutParameters[0] as GPFeatureRecordSetLayer;

                // Get the result feature
                Graphic graphicBuff = rs.FeatureSet.Features[0];

                // Set the symbol
                graphicBuff.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;

                // Add to the layer
                graphicsLayer.Graphics.Add(graphicBuff);

                // Stop the progress bar
                IsBusy = false;
            };

            // Register an inline handler for the failed event (just in case)
            _gpTask.Failed += (s2, e2) =>
            {
                MessageBox.Show(e2.Error.Message);
                IsBusy = false;
            };

            // Execute the Buffer asynchronously
            _gpTask.ExecuteAsync(gpParams);
        }
        // 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;
        }
        private  void _myDrawObject_DrawComplete(object sender, DrawEventArgs e)
        {
            if (e.Geometry == null)
            {
                MapApplication.Current.HideWindow(_elevationProfileDialog);
                return;
            }

            try
            {

                _myDrawObject.IsEnabled = false;

                ProfileCalculationBusyIndicator.Visibility = Visibility.Visible;

                _lineGraphicLayer.Graphics[0].Geometry = e.Geometry;

                if (_cts != null)
                    _cts.Cancel();

                _cts = new CancellationTokenSource();

                Geoprocessor geoprocessorTask = new Geoprocessor(
                    "http://elevation.arcgis.com/arcgis/rest/services/Tools/ElevationSync/GPServer/Profile");
                geoprocessorTask.ExecuteCompleted += geoprocessorTask_ExecuteCompleted;

                List<GPParameter> parameters = new List<GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("InputLineFeatures", e.Geometry));
                parameters.Add(new GPString("returnM", "true"));
                parameters.Add(new GPString("returnZ", "true"));

                geoprocessorTask.ExecuteAsync(parameters, _cts.Token);

               
            }
            catch (Exception ex)
            {
                if (ex is ServiceException)
                {
                    MessageBox.Show(String.Format("{0}: {1}", (ex as ServiceException).Code.ToString(),
                        (ex as ServiceException).Details[0]), "Error", MessageBoxButton.OK);
                    return;
                }
            }
            finally
            {
                ProfileCalculationBusyIndicator.Visibility = Visibility.Collapsed;
            }
        }
Beispiel #45
0
        private void 前后台GP对比ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //前台执行GP
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();

            // Populate the variant array with parameter values.
            parameters.Add(FileGDBPath + "\\testPoint_100w");
            parameters.Add(FileGDBPath + "\\testPoint_100w_CopyPre");

            try
            {
                IGeoProcessorResult2 result = gp.ExecuteAsync("CopyFeatures_management", parameters) as IGeoProcessorResult2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GP Error");
            }
            finally
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    sb.AppendLine(gp.GetMessage(i));
                }
                if (sb.Capacity > 0)
                {
                    MessageBox.Show(sb.ToString(), "GP Messages");
                }
            }

            //后台执行GP
            // Create a variant array to hold the parameter values.
            IVariantArray parameters1 = new VarArrayClass();

            // Populate the variant array with parameter values.
            parameters1.Add(FileGDBPath + "\\testPoint_100w");
            parameters1.Add(FileGDBPath + "\\testPoint_100w_CopyBack");

            try
            {
                IGeoProcessorResult2 result = gp.Execute("CopyFeatures_management", parameters1, null) as IGeoProcessorResult2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GP Error");
            }
            finally
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    sb.AppendLine(gp.GetMessage(i));
                }
                if (sb.Capacity > 0)
                {
                    MessageBox.Show(sb.ToString(), "GP Messages");
                }
            }
        }