private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geoprocessor gpGroundComCov = new Geoprocessor(_serviceURL);
                gpGroundComCov.JobCompleted += gpGroundComCov_JobCompleted;
                gpGroundComCov.Failed       += gpGroundComCov_Failed;

                List <GPParameter> parameters = new List <GPParameter>();
                FeatureSet         pFeatures  = new FeatureSet(_graphicsLayer.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("FOBPoint", pFeatures));

                gpGroundComCov.ProcessSpatialReference = new SpatialReference(4326);
                gpGroundComCov.SubmitJobAsync(parameters);

                if (_mapWidget != null)
                {
                    _mapWidget.Map.MouseClick -= Map_MouseClick;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during run: " + ex.Message);
            }
        }
        private void CreateGPParamsAndExtract(GraphicCollection clipGraphics)
        {
            FeatureSet clipFS = new FeatureSet();

            clipFS.GeometryType     = GeometryType.Polygon;
            clipFS.SpatialReference = this.MapControl.SpatialReference;
            foreach (Graphic graphic in clipGraphics)
            {
                clipFS.Features.Add(graphic);
            }

            if (clipFS.Features.Count > 0)
            {
                List <GPParameter> gpParams = CreateGPParams(clipFS);

                if (gpParams.Count > 0)
                {
                    gpService.ProcessSpatialReference = this.MapControl.SpatialReference;
                    gpService.OutputSpatialReference  = this.MapControl.SpatialReference;

                    this.IsBusy = true;
                    txtExtractionStatus.Visibility = Visibility.Visible;
                    gpService.SubmitJobAsync(gpParams);
                }
            }
        }
        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;

            ProcessingTextBlock.Visibility = Visibility.Visible;
            _processingTimer.Start();

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

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol,
                Geometry = args.Geometry
            };

            graphicsLayer.Graphics.Add(graphic);

            Geoprocessor geoprocessorTask = new Geoprocessor("http://serverapps.esri.com/ArcGIS/rest/services/" +
                                                             "SamplesNET/USA_Data_ClipTools/GPServer/ClipCounties");

            geoprocessorTask.UpdateDelay   = 5000;
            geoprocessorTask.JobCompleted += GeoprocessorTask_JobCompleted;

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

            parameters.Add(new GPFeatureRecordSetLayer("Input_Features", args.Geometry));
            parameters.Add(new GPLinearUnit("Linear_unit", esriUnits.esriMiles, Int32.Parse(DistanceTextBox.Text)));

            geoprocessorTask.SubmitJobAsync(parameters);
        }
        private void RunButton_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_graphicsLayer.Graphics.Count > 0)
                {
                    //Geoprocessor gpFarthest = new Geoprocessor("http://dtcrugmo01.esri.com:6080/arcgis/rest/services/Tasks/FarthestOnCircle/GPServer/Farthest%20On%20Circle");
                    Geoprocessor gpFarthest = new Geoprocessor(_serviceURL);
                    gpFarthest.JobCompleted += gpFarthest_JobCompleted;
                    gpFarthest.Failed       += gpFarthest_Failed;
                    List <GPParameter> parameters = new List <GPParameter>();
                    FeatureSet         pFeatures  = new FeatureSet(_graphicsLayer.Graphics);
                    parameters.Add(new GPFeatureRecordSetLayer("Position_Last_Seen", pFeatures));
                    parameters.Add(new GPString("Range_for_Analysis_in_Nautical_Miles", Range.Text));
                    parameters.Add(new GPString("Average_Speed_in_Knots__kts__for_Analysis", Speed.Text));
                    gpFarthest.OutputSpatialReference = new SpatialReference(102100);

                    gpFarthest.SubmitJobAsync(parameters);

                    if (_mapWidget != null)
                    {
                        _mapWidget.Map.MouseClick -= Map_MouseClick;
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("error");
            }
        }
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
        {
            if (LayersList.SelectedItem == null)
            {
                MessageBox.Show("Please select layer(s) to extract");
                (MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics.Clear();
                return;
            }

            Geometry filterGeometry = args.Geometry;

            if (args.Geometry is Polyline)
            {
                Polyline freehandLine = args.Geometry as Polyline;
                freehandLine.Paths[0].Add(freehandLine.Paths[0][0].Clone());
                filterGeometry = new Polygon()
                {
                    SpatialReference = MyMap.SpatialReference
                };
                (filterGeometry as Polygon).Rings.Add(freehandLine.Paths[0]);
            }

            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = filterGeometry
            };
            _graphicsLayer.Graphics.Add(graphic);
            _drawObject.IsEnabled = false;

            ProcessingTextBlock.Visibility = Visibility.Visible;
            _processingTimer.Start();

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

            var strLayerList = new List <GPString>();

            foreach (var itm in LayersList.SelectedItems)
            {
                strLayerList.Add(new GPString(itm.ToString(), itm.ToString()));
            }
            parameters.Add(new GPMultiValue <GPString>("Layers_to_Clip", strLayerList));
            parameters.Add(new GPFeatureRecordSetLayer("Area_of_Interest", _graphicsLayer.Graphics[0].Geometry));
            parameters.Add(new GPString("Feature_Format", Formats.SelectedValue.ToString()));

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

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

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

                await Task.Delay(2000);
            }

            return(result);
        }
        private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs e)
        {
            MyDrawObject.IsEnabled = false;

            try
            {
                if (Convert.ToDouble(MilesTextBox.Text) > 10)
                {
                    MessageBox.Show("Distance must be 10 miles or less.");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Distance must be a double.");
                return;
            }

            graphicsLayer.ClearGraphics();

            MapPoint mapPoint = e.Geometry as MapPoint;

            mapPoint.SpatialReference = new SpatialReference(102100);

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

            graphicsLayer.Graphics.Add(graphic);

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

            parameters.Add(new GPFeatureRecordSetLayer("Input_Features", mapPoint));
            parameters.Add(new GPString("Height", HeightTextBox.Text));
            parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));

            _geoprocessorTask.OutputSpatialReference = new SpatialReference(102100);
            WaitGrid.Visibility = Visibility.Visible;

            _geoprocessorTask.SubmitJobAsync(parameters);
        }
        private void SubmitJob(MapPoint mp)
        {
            graphicsLayer.Graphics.Clear();

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

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

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

            parameters.Add(new GPFeatureRecordSetLayer("Facilities", new FeatureSet(graphicsLayer.Graphics)));
            parameters.Add(new GPString("Break_Values", "1 2 3"));
            parameters.Add(new GPString("Break_Units", "Minutes"));

            _geoprocessorTask.SubmitJobAsync(parameters);
        }
예제 #9
0
        void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
        {
            /*
             * Add a graphic at the user input location
             */
            MyMap.MouseClick -= MyMap_MouseClick;

            if (inputGraphicsLayer == null)
            {
                inputGraphicsLayer = new GraphicsLayer();
                MyMap.Layers.Add(inputGraphicsLayer);
            }

            // Add a Graphic at the click point
            Graphic graphic = new Graphic()
            {
                Symbol   = MainGrid.Resources["IncidentMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint
            };

            inputGraphicsLayer.Graphics.Add(graphic);

            /*
             * Reproject the mouseclick into the GP coordinate system
             */
            // Declare the ProjectCompleted Handler
            EventHandler <GraphicsEventArgs> ProjectCompletedHandler = null;

            // Handle the event
            ProjectCompletedHandler = (sender2, graphicsEventArgs) =>
            {
                // Unregister the handler
                geometryTask.ProjectCompleted -= ProjectCompletedHandler;

                // Cancel any existing Jobs
                geoprocessorTask.CancelAsync();

                // Handle the JobCompleted
                geoprocessorTask.JobCompleted += (sender3, jobInfoEventArgs) =>
                {
                    // Check whether it succeeded
                    if (jobInfoEventArgs.JobInfo.JobStatus != esriJobStatus.esriJobSucceeded)
                    {
                        //Do Something
                    }
                    ;

                    /*
                     * Create two new Geoprocessor Tasks to fetch the result data (thereby allowing them to run concurrently)
                     * Each will use the same event handler and we'll choose based on the Parameter Name.
                     * Alternatively could use the overload which takes an object (userToken).
                     */
                    Geoprocessor gpTaskSysvalves_Layer =
                        new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url);

                    gpTaskSysvalves_Layer.GetResultDataCompleted
                        += geoprocessorTask_GetResultDataCompleted;

                    gpTaskSysvalves_Layer.GetResultDataAsync(
                        jobInfoEventArgs.JobInfo.JobId, "Sysvalves_Layer");

                    Geoprocessor gpTaskDistribMains_Layer =
                        new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url);

                    gpTaskDistribMains_Layer.GetResultDataCompleted
                        += geoprocessorTask_GetResultDataCompleted;

                    gpTaskDistribMains_Layer.GetResultDataAsync(
                        jobInfoEventArgs.JobInfo.JobId, "DistribMains_Layer");
                };

                // Create the GP Parameter List
                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("Flags", graphicsEventArgs.Results[0].Geometry));
                geoprocessorTask.SubmitJobAsync(parameters);
            };
            // Register the handler for the ProjectCompleted event.
            geometryTask.ProjectCompleted += ProjectCompletedHandler;

            // Project the input point into the coordinate system of the data
            geometryTask.ProjectAsync(new List <Graphic>()
            {
                new Graphic()
                {
                    Geometry = e.MapPoint
                }
            },
                                      waterNetworkLocalMapService.SpatialReference);
        }
        // Waits for the user to draw a line, then performs the buffer and clip operation
        private async void getInputLineAndClip()
        {
            if (m_firstPointAdded)
                return;

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

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

            string error = null;

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

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

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

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

                    await Task.Delay(2000);
                }

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

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

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

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

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

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

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

            getInputLineAndClip();
        }
예제 #11
0
        }         // private GraphicsLayer getRLLayer()

        /// <summary>
        /// Geoprocessor service will be asked
        /// </summary>
        /// <param name="geom"></param>
        private void askGeoprocessor(ESRI.ArcGIS.Client.Geometry.Geometry geom)
        {
            var map  = MapApplication.Current.Map;
            var poly = geom as ESRI.ArcGIS.Client.Geometry.Polygon;

            //poly = poly.Clone();
            //poly.SpatialReference = map.SpatialReference;
            log(string.Format("askGeoprocessor, spatialReference map wkid '{0}', map wkt '{1}', geom wkid '{2}', geom wkt '{3}'",
                              map.SpatialReference.WKID, map.SpatialReference.WKT, poly.SpatialReference.WKID, poly.SpatialReference.WKT));
            double fSeismodens = 0, fProfilelength = 0, fShapeArea = 0;             // result
            var    oldCursor = MapApplication.Current.Map.Cursor;

            // todo: make gp as class member and check bisy state before asking.
            var gp = new Geoprocessor("http://cache.algis.com/ArcGIS/rest/services/" +
                                      "five/seismodens/GPServer/seismoprofiles%20density");

            gp.UpdateDelay = 300;
            var data = new List <GPParameter>();

            data.Add(new GPFeatureRecordSetLayer("inputPolygon", poly));

            gp.Failed += (sender, args) => {
                var tf = args as TaskFailedEventArgs;
                log(string.Format("gp.Failed, message {0}", tf.Error.Message));
                MapApplication.Current.Map.Cursor = oldCursor;
                MessageBox.Show(string.Format("Геопроцессор не может выполнить запрос \n {0}", tf.Error));
            };             // gp.Failed

            gp.JobCompleted += (sender, args) => {
                var    ji   = args as JobInfoEventArgs;
                string msgs = "";
                ji.JobInfo.Messages.ForEach(gpm => msgs += string.Format("\n{0}: {1}", gpm.MessageType, gpm.Description));
                log(string.Format("gp.JobCompleted, job status {0}, job id {1}, msgs {2}",
                                  ji.JobInfo.JobStatus, ji.JobInfo.JobId, msgs));
                MapApplication.Current.Map.Cursor = oldCursor;
                if (ji.JobInfo.JobStatus != esriJobStatus.esriJobSucceeded)
                {
                    MessageBox.Show(string.Format("Геопроцессор не может выполнить запрос \n {0}", msgs));
                    return;
                }

                gp.GetResultDataCompleted += (resSender, resArgs) => {
                    var p  = resArgs as GPParameterEventArgs;
                    var dv = p.Parameter as GPDouble;
                    var ci = new System.Globalization.CultureInfo("en-US");
                    log(string.Format(ci, "gp.GetResultDataCompleted, param name '{0}', value '{1}'", p.Parameter.Name, dv.Value));
                    if (p.Parameter.Name.Contains("seismoDens"))
                    {
                        fSeismodens = dv.Value;
                        gp.GetResultDataAsync(ji.JobInfo.JobId, "profilesLength");
                    }
                    if (p.Parameter.Name.Contains("profilesLength"))
                    {
                        fProfilelength = dv.Value;
                        gp.GetResultDataAsync(ji.JobInfo.JobId, "shapeArea");
                    }
                    if (p.Parameter.Name.Contains("shapeArea"))
                    {
                        fShapeArea = dv.Value;
                        log(string.Format("askGeoprocessor, we got all the results, job done."));
                        MessageBox.Show(string.Format(ci, "Сейсмоплотность {0} км/км2, \t\n суммарная длина профилей {1} км, \t\n " +
                                                      "очерченная площадь {2} км2", fSeismodens, fProfilelength, fShapeArea));
                    }
                };                 // gp.GetResultDataCompleted

                gp.GetResultDataAsync(ji.JobInfo.JobId, "seismoDens");
            };             // gp.JobCompleted

            MapApplication.Current.Map.Cursor = System.Windows.Input.Cursors.Wait;
            gp.SubmitJobAsync(data); // http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Geoprocessing_task/01660000000n000000/
        }                            // private void askGeoprocessor(ESRI.ArcGIS.Client.Geometry.Geometry geom)
예제 #12
0
        // Waits for the user to draw a line, then performs the buffer and clip operation
        private async void getInputLineAndClip()
        {
            if (m_firstPointAdded)
            {
                return;
            }

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

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

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

            string error = null;

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

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

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

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

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

                    await Task.Delay(2000);
                }

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

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

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

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

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

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

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

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

            getInputLineAndClip();
        }
예제 #13
0
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

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

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


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

            TapPoints.Add(g);

            string error = null;

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

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

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

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

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

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

                    await Task.Delay(2000);
                }

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

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

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

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

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
            StatusText     = "";
        }
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

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

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

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

            string error = null;

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

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

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

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

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

                    await Task.Delay(2000);
                }

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

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

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

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
            StatusText = "";
        }
예제 #15
0
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_graphicsLayer.Graphics.Count > 0)
                {
                    Geoprocessor gpAircraftRouteGen = new Geoprocessor(_serviceURL);
                    gpAircraftRouteGen.JobCompleted += gpAircraftRouteGen_JobCompleted;
                    gpAircraftRouteGen.Failed       += gpAircraftRouteGen_Failed;
                    List <GPParameter> parameters = new List <GPParameter>();
                    FeatureSet         pFeatures  = new FeatureSet(_graphicsLayer.Graphics);
                    parameters.Add(new GPFeatureRecordSetLayer("Route_Definition", pFeatures));
                    parameters.Add(new GPString("Aircraft_Model", aircraftmodel.Text));
                    parameters.Add(new GPDouble("Time_Step__s_", System.Convert.ToDouble(timestep.Text)));
                    string[] theTimevals = startTime.Text.Split(' ');
                    string[] theTime     = theTimevals[0].Split(':');
                    int      hour        = 0;
                    int      minute      = 0;
                    int      seconds     = 0;
                    if (theTimevals[1] == "PM")
                    {
                        hour = System.Convert.ToInt16(theTime[0]) + 12;
                    }
                    else
                    {
                        hour = System.Convert.ToInt16(theTime[0]);
                    }
                    minute  = System.Convert.ToInt16(theTime[1]);
                    seconds = System.Convert.ToInt16(theTime[2]);
                    DateTime start;
                    if (StartDate.SelectedDate == null)
                    {
                        start = new DateTime(StartDate.DisplayDate.Date.Year, StartDate.DisplayDate.Date.Month, StartDate.DisplayDate.Date.Day, hour, minute, seconds);
                    }
                    else
                    {
                        start = new DateTime(StartDate.SelectedDate.Value.Date.Year, StartDate.SelectedDate.Value.Date.Month, StartDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                    }

                    string[] theTimevalsStop = stopTime.Text.Split(' ');
                    string[] theTimeStop     = theTimevalsStop[0].Split(':');
                    if (theTimevalsStop[1] == "PM")
                    {
                        hour = System.Convert.ToInt16(theTimeStop[0]) + 12;
                    }
                    else
                    {
                        hour = System.Convert.ToInt16(theTimeStop[0]);
                    }
                    minute  = System.Convert.ToInt16(theTimeStop[1]);
                    seconds = System.Convert.ToInt16(theTimeStop[2]);

                    DateTime stop;
                    if (StopDate.SelectedDate == null)
                    {
                        stop = new DateTime(StopDate.DisplayDate.Date.Year, StopDate.DisplayDate.Date.Month, StopDate.DisplayDate.Date.Day, hour, minute, seconds);
                    }
                    else
                    {
                        stop = new DateTime(StopDate.SelectedDate.Value.Date.Year, StopDate.SelectedDate.Value.Date.Month, StopDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                    }


                    parameters.Add(new GPDate("Start_Time__UTC_", start.ToUniversalTime()));
                    parameters.Add(new GPDate("Stop_Time__UTC_", stop.ToUniversalTime()));

                    //gpAircraftRouteGen.OutputSpatialReference = new SpatialReference(102100);
                    gpAircraftRouteGen.OutputSpatialReference = new SpatialReference(4326);
                    gpAircraftRouteGen.SubmitJobAsync(parameters);

                    if (_mapWidget != null)
                    {
                        _mapWidget.Map.MouseClick -= Map_MouseClick;
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("error");
            }
        }
예제 #16
0
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geoprocessor gpAircraftComms = new Geoprocessor(_serviceURL);
                gpAircraftComms.JobCompleted += gpAircraftComms_JobCompleted;
                gpAircraftComms.Failed       += gpAircraftComms_Failed;

                List <GPParameter> parameters = new List <GPParameter>();
                FeatureSet         pFeatures  = new FeatureSet(_graphicsLayer.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("Waypoints", pFeatures));
                parameters.Add(new GPString("Aircraft_Model", aircraftmodel.Text));
                FeatureSet pPolygon = new FeatureSet(_graphicsLayerPoly.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("AreaTarget", pPolygon));

                parameters.Add(new GPDouble("Grid_Point_Granularity__deg_", System.Convert.ToDouble(gridgranularity.Text)));
                string[] theTimevals = startTime.Text.Split(' ');
                string[] theTime     = theTimevals[0].Split(':');
                int      hour        = 0;
                int      minute      = 0;
                int      seconds     = 0;
                if (theTimevals[1] == "PM")
                {
                    hour = System.Convert.ToInt16(theTime[0]) + 12;
                }
                else
                {
                    hour = System.Convert.ToInt16(theTime[0]);
                }
                minute  = System.Convert.ToInt16(theTime[1]);
                seconds = System.Convert.ToInt16(theTime[2]);
                DateTime start;
                if (StartDate.SelectedDate == null)
                {
                    start = new DateTime(StartDate.DisplayDate.Date.Year, StartDate.DisplayDate.Date.Month, StartDate.DisplayDate.Day, hour, minute, seconds);
                }
                else
                {
                    start = new DateTime(StartDate.SelectedDate.Value.Date.Year, StartDate.SelectedDate.Value.Date.Month, StartDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                }

                string[] theTimevalsStop = stopTime.Text.Split(' ');
                string[] theTimeStop     = theTimevalsStop[0].Split(':');
                if (theTimevalsStop[1] == "PM")
                {
                    hour = System.Convert.ToInt16(theTimeStop[0]) + 12;
                }
                else
                {
                    hour = System.Convert.ToInt16(theTimeStop[0]);
                }
                minute  = System.Convert.ToInt16(theTimeStop[1]);
                seconds = System.Convert.ToInt16(theTimeStop[2]);

                DateTime stop;
                if (StopDate.SelectedDate == null)
                {
                    stop = new DateTime(StopDate.DisplayDate.Year, StopDate.DisplayDate.Month, StopDate.DisplayDate.Day, hour, minute, seconds);
                }
                else
                {
                    stop = new DateTime(StopDate.SelectedDate.Value.Date.Year, StopDate.SelectedDate.Value.Date.Month, StopDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                }

                parameters.Add(new GPDate("Start_Time__UTC_", start.ToUniversalTime()));
                parameters.Add(new GPDate("Stop_Time__UTC_", stop.ToUniversalTime()));

                gpAircraftComms.ProcessSpatialReference = new SpatialReference(4326);
                gpAircraftComms.SubmitJobAsync(parameters);

                if (_mapWidget != null)
                {
                    _mapWidget.Map.MouseClick -= Map_MouseClick;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in run: " + ex.Message);
            }
        }
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geoprocessor gpGroundComCov = new Geoprocessor(_serviceURL);
                gpGroundComCov.JobCompleted += gpGroundComCov_JobCompleted;
                gpGroundComCov.Failed += gpGroundComCov_Failed;

                List<GPParameter> parameters = new List<GPParameter>();
                FeatureSet pFeatures = new FeatureSet(_graphicsLayer.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("FOBPoint", pFeatures));

                gpGroundComCov.ProcessSpatialReference = new SpatialReference(4326);
                gpGroundComCov.SubmitJobAsync(parameters);

                if (_mapWidget != null)
                {
                    _mapWidget.Map.MouseClick -= Map_MouseClick;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during run: " + ex.Message);
            }
        }
        // ***********************************************************************************
        // * ...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 MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;

              ProcessingTextBlock.Visibility = Visibility.Visible;
              _processingTimer.Start();

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

              Graphic graphic = new Graphic()
              {
            Symbol = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol,
            Geometry = args.Geometry
              };
              graphicsLayer.Graphics.Add(graphic);

              Geoprocessor geoprocessorTask = new Geoprocessor("http://serverapps10.esri.com/ArcGIS/rest/services/" +
              "SamplesNET/USA_Data_ClipTools/GPServer/ClipCounties");

              //geoprocessorTask.ProxyURL = "http://servicesbeta3.esri.com/SilverlightDemos/ProxyPage/proxy.ashx";

              geoprocessorTask.UpdateDelay = 5000;
              geoprocessorTask.JobCompleted += GeoprocessorTask_JobCompleted;

              List<GPParameter> parameters = new List<GPParameter>();
              parameters.Add(new GPFeatureRecordSetLayer("Input_Features", args.Geometry));
              parameters.Add(new GPLinearUnit("Linear_unit", esriUnits.esriMiles, Int32.Parse(DistanceTextBox.Text)));

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

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

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

            inputLayer.Graphics.Add(inputGraphic);

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

            string message = null;

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

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

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

                    await Task.Delay(5000);
                }

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

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

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

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

            if (message != null)
            {
                await new MessageDialog(message, "GP Failed").ShowAsync();
            }
        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled         = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

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

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

            viewShedLayer.Graphics.Clear();

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

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

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

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


            var result = await task.SubmitJobAsync(parameter);

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

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


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

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

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

                //Reset the UI
                StatusTextBlock.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
                StartButton.IsEnabled         = true;
                ClearResultsButton.Visibility = Visibility.Visible;
                MyProgressRing.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                MyProgressRing.IsActive       = false;
            }
        }
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_graphicsLayer.Graphics.Count > 0)
                {
                    Geoprocessor gpAircraftRouteGen = new Geoprocessor(_serviceURL);
                    gpAircraftRouteGen.JobCompleted += gpAircraftRouteGen_JobCompleted;
                    gpAircraftRouteGen.Failed += gpAircraftRouteGen_Failed;
                    List<GPParameter> parameters = new List<GPParameter>();
                    FeatureSet pFeatures = new FeatureSet(_graphicsLayer.Graphics);
                    parameters.Add(new GPFeatureRecordSetLayer("Route_Definition", pFeatures));
                    parameters.Add(new GPString("Aircraft_Model", aircraftmodel.Text));
                    parameters.Add(new GPDouble("Time_Step__s_", System.Convert.ToDouble(timestep.Text)));
                    string[] theTimevals = startTime.Text.Split(' ');
                    string[] theTime = theTimevals[0].Split(':');
                    int hour = 0;
                    int minute = 0;
                    int seconds = 0;
                    if (theTimevals[1] == "PM")
                        hour = System.Convert.ToInt16(theTime[0]) + 12;
                    else
                        hour = System.Convert.ToInt16(theTime[0]);
                    minute = System.Convert.ToInt16(theTime[1]);
                    seconds = System.Convert.ToInt16(theTime[2]);
                    DateTime start;
                    if (StartDate.SelectedDate == null)
                        start = new DateTime(StartDate.DisplayDate.Date.Year, StartDate.DisplayDate.Date.Month, StartDate.DisplayDate.Date.Day, hour, minute, seconds);
                    else
                        start = new DateTime(StartDate.SelectedDate.Value.Date.Year, StartDate.SelectedDate.Value.Date.Month, StartDate.SelectedDate.Value.Date.Day, hour, minute, seconds);

                    string[] theTimevalsStop = stopTime.Text.Split(' ');
                    string[] theTimeStop = theTimevalsStop[0].Split(':');
                    if (theTimevalsStop[1] == "PM")
                        hour = System.Convert.ToInt16(theTimeStop[0]) + 12;
                    else
                        hour = System.Convert.ToInt16(theTimeStop[0]);
                    minute = System.Convert.ToInt16(theTimeStop[1]);
                    seconds = System.Convert.ToInt16(theTimeStop[2]);

                    DateTime stop;
                    if (StopDate.SelectedDate == null)
                        stop = new DateTime(StopDate.DisplayDate.Date.Year, StopDate.DisplayDate.Date.Month, StopDate.DisplayDate.Date.Day, hour, minute, seconds);
                    else
                        stop = new DateTime(StopDate.SelectedDate.Value.Date.Year, StopDate.SelectedDate.Value.Date.Month, StopDate.SelectedDate.Value.Date.Day, hour, minute, seconds);

                    parameters.Add(new GPDate("Start_Time__UTC_", start.ToUniversalTime()));
                    parameters.Add(new GPDate("Stop_Time__UTC_", stop.ToUniversalTime()));

                    //gpAircraftRouteGen.OutputSpatialReference = new SpatialReference(102100);
                    gpAircraftRouteGen.OutputSpatialReference = new SpatialReference(4326);
                    gpAircraftRouteGen.SubmitJobAsync(parameters);

                    if (_mapWidget != null)
                    {
                        _mapWidget.Map.MouseClick -= Map_MouseClick;
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("error");
            }
        }
        private async void StartGP_Click(object sender, RoutedEventArgs e)
        {
            StartGP.IsEnabled = false;
            ClearGraphics();
            ClearButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ProcessingTextBlock.Visibility = Visibility.Collapsed;

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

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

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

            string message = null;

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

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

                }

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

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

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

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


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

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

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

			viewshedLayer.Graphics.Clear();

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

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

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


			var result = await task.SubmitJobAsync(parameter);

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

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


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

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

				//Reset the UI
				StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
				StartButton.IsEnabled = true;
				ClearResultsButton.Visibility = Visibility.Visible;
				MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
				MyProgressRing.IsActive = false;
			}
		}
예제 #25
0
        /// <summary>
        /// マップビュータップ時の処理
        /// </summary>
        private async void mainMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            //解析手順のメッセージを非表示
            analyzeTextBox.Visibility = System.Windows.Visibility.Collapsed;

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

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

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

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

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

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

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

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

                    await Task.Delay(2000);
                }


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

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

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

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

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

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

                //到達圏解析ボタンを表示
                analyzePanel.Visibility = System.Windows.Visibility.Visible;
            }
        }
예제 #26
0
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;

            if (_displayViewshedInfo && resultLayer != null)
            {
                ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                {
                    Geometry         = mapPoint,
                    MapExtent        = MyMap.Extent,
                    Width            = (int)MyMap.ActualWidth,
                    Height           = (int)MyMap.ActualHeight,
                    LayerOption      = LayerOption.visible,
                    SpatialReference = MyMap.SpatialReference
                };

                IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
                identifyTask.ExecuteCompleted += (s, ie) =>
                {
                    if (ie.IdentifyResults.Count > 0)
                    {
                        foreach (var identifyresult in ie.IdentifyResults)
                        {
                            if (identifyresult.LayerId == 1)
                            {
                                Graphic g = identifyresult.Feature;
                                MyInfoWindow.Anchor  = e.MapPoint;
                                MyInfoWindow.Content = g.Attributes;
                                MyInfoWindow.IsOpen  = true;
                                break;
                            }
                        }
                    }
                };
                identifyTask.ExecuteAsync(identifyParams);
            }
            else
            {
                _geoprocessorTask.CancelAsync();

                graphicsLayer.Graphics.Clear();

                mapPoint.SpatialReference = new SpatialReference(102100);

                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_Features", mapPoint));
                parameters.Add(new GPString("Height", HeightTextBox.Text));
                parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));


                _geoprocessorTask.OutputSpatialReference = new SpatialReference(102100);
                _geoprocessorTask.SubmitJobAsync(parameters);
            }
        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

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

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

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

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

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


            var result = await task.SubmitJobAsync(parameter);

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

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


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

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

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

                }

                //Reset the UI
                StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                StartButton.IsEnabled = true;
                ClearResultsButton.Visibility = Visibility.Visible;
                MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                MyProgressRing.IsActive = false;
            }
        }
예제 #28
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 RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geoprocessor gpAircraftComms = new Geoprocessor(_serviceURL);
                gpAircraftComms.JobCompleted += gpAircraftComms_JobCompleted;
                gpAircraftComms.Failed += gpAircraftComms_Failed;

                List<GPParameter> parameters = new List<GPParameter>();
                FeatureSet pFeatures = new FeatureSet(_graphicsLayer.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("Waypoints", pFeatures));
                parameters.Add(new GPString("Aircraft_Model", aircraftmodel.Text));
                FeatureSet pPolygon = new FeatureSet(_graphicsLayerPoly.Graphics);
                parameters.Add(new GPFeatureRecordSetLayer("AreaTarget", pPolygon));

                parameters.Add(new GPDouble("Grid_Point_Granularity__deg_", System.Convert.ToDouble(gridgranularity.Text)));
                string[] theTimevals = startTime.Text.Split(' ');
                string[] theTime = theTimevals[0].Split(':');
                int hour = 0;
                int minute = 0;
                int seconds = 0;
                if (theTimevals[1] == "PM")
                    hour = System.Convert.ToInt16(theTime[0]) + 12;
                else
                    hour = System.Convert.ToInt16(theTime[0]);
                minute = System.Convert.ToInt16(theTime[1]);
                seconds = System.Convert.ToInt16(theTime[2]);
                DateTime start;
                if (StartDate.SelectedDate == null)
                    start = new DateTime(StartDate.DisplayDate.Date.Year, StartDate.DisplayDate.Date.Month, StartDate.DisplayDate.Day, hour, minute, seconds);
                else
                    start = new DateTime(StartDate.SelectedDate.Value.Date.Year, StartDate.SelectedDate.Value.Date.Month, StartDate.SelectedDate.Value.Date.Day, hour, minute, seconds);

                string[] theTimevalsStop = stopTime.Text.Split(' ');
                string[] theTimeStop = theTimevalsStop[0].Split(':');
                if (theTimevalsStop[1] == "PM")
                    hour = System.Convert.ToInt16(theTimeStop[0]) + 12;
                else
                    hour = System.Convert.ToInt16(theTimeStop[0]);
                minute = System.Convert.ToInt16(theTimeStop[1]);
                seconds = System.Convert.ToInt16(theTimeStop[2]);

                DateTime stop;
                if (StopDate.SelectedDate == null)
                    stop = new DateTime(StopDate.DisplayDate.Year, StopDate.DisplayDate.Month, StopDate.DisplayDate.Day, hour, minute, seconds);
                else
                    stop = new DateTime(StopDate.SelectedDate.Value.Date.Year, StopDate.SelectedDate.Value.Date.Month, StopDate.SelectedDate.Value.Date.Day, hour, minute, seconds);

                parameters.Add(new GPDate("Start_Time__UTC_", start.ToUniversalTime()));
                parameters.Add(new GPDate("Stop_Time__UTC_", stop.ToUniversalTime()));

                gpAircraftComms.ProcessSpatialReference = new SpatialReference(4326);
                gpAircraftComms.SubmitJobAsync(parameters);

                if (_mapWidget != null)
                {
                    _mapWidget.Map.MouseClick -= Map_MouseClick;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in run: " + ex.Message);
            }
        }
예제 #30
0
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geoprocessor gpSateEphemeris = new Geoprocessor(_serviceURL);
                gpSateEphemeris.JobCompleted += gpSateEphemeris_JobCompleted;
                gpSateEphemeris.Failed       += gpSateEphemeris_Failed;

                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPString("SscNumber", sscnumber.Text));
                parameters.Add(new GPString("SensorProperties", "{'definition':'rectangular','horizontalHalfAngle':'20','verticalHalfAngle':'85.5'}"));
                parameters.Add(new GPDouble("TimeStepSeconds", System.Convert.ToDouble(timestep.Text)));
                string[] theTimevals = startTime.Text.Split(' ');
                string[] theTime     = theTimevals[0].Split(':');
                int      hour        = 0;
                int      minute      = 0;
                int      seconds     = 0;
                if (theTimevals[1] == "PM")
                {
                    hour = System.Convert.ToInt16(theTime[0]) + 12;
                }
                else
                {
                    hour = System.Convert.ToInt16(theTime[0]);
                }
                minute  = System.Convert.ToInt16(theTime[1]);
                seconds = System.Convert.ToInt16(theTime[2]);
                DateTime start;
                if (StartDate.SelectedDate == null)
                {
                    start = new DateTime(StartDate.DisplayDate.Date.Year, StartDate.DisplayDate.Date.Month, StartDate.DisplayDate.Date.Day, hour, minute, seconds);
                }
                else
                {
                    start = new DateTime(StartDate.SelectedDate.Value.Date.Year, StartDate.SelectedDate.Value.Date.Month, StartDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                }

                string[] theTimevalsStop = stopTime.Text.Split(' ');
                string[] theTimeStop     = theTimevalsStop[0].Split(':');
                if (theTimevalsStop[1] == "PM")
                {
                    hour = System.Convert.ToInt16(theTimeStop[0]) + 12;
                }
                else
                {
                    hour = System.Convert.ToInt16(theTimeStop[0]);
                }
                minute  = System.Convert.ToInt16(theTimeStop[1]);
                seconds = System.Convert.ToInt16(theTimeStop[2]);

                DateTime stop;
                if (StartDate.SelectedDate == null)
                {
                    stop = new DateTime(StopDate.DisplayDate.Date.Year, StopDate.DisplayDate.Date.Month, StopDate.DisplayDate.Day, hour, minute, seconds);
                }
                else
                {
                    stop = new DateTime(StopDate.SelectedDate.Value.Date.Year, StopDate.SelectedDate.Value.Date.Month, StopDate.SelectedDate.Value.Date.Day, hour, minute, seconds);
                }

                parameters.Add(new GPDate("StartTimeUtc", start.ToUniversalTime()));
                parameters.Add(new GPDate("StopTimeUtc", stop.ToUniversalTime()));

                gpSateEphemeris.OutputSpatialReference = new SpatialReference(4326);
                gpSateEphemeris.SubmitJobAsync(parameters);

                if (_mapWidget != null)
                {
                    _mapWidget.Map.MouseClick -= Map_MouseClick;
                }
            }
            catch
            {
                MessageBox.Show("Error in run");
            }
        }
        private void RunButton_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_graphicsLayer.Graphics.Count > 0)
                {
                    //Geoprocessor gpFarthest = new Geoprocessor("http://dtcrugmo01.esri.com:6080/arcgis/rest/services/Tasks/FarthestOnCircle/GPServer/Farthest%20On%20Circle");
                    Geoprocessor gpFarthest = new Geoprocessor(_serviceURL);
                    gpFarthest.JobCompleted += gpFarthest_JobCompleted;
                    gpFarthest.Failed += gpFarthest_Failed;
                    List<GPParameter> parameters = new List<GPParameter>();
                    FeatureSet pFeatures = new FeatureSet(_graphicsLayer.Graphics);
                    parameters.Add(new GPFeatureRecordSetLayer("Position_Last_Seen", pFeatures));
                    parameters.Add(new GPString("Range_for_Analysis_in_Nautical_Miles", Range.Text));
                    parameters.Add(new GPString("Average_Speed_in_Knots__kts__for_Analysis", Speed.Text));
                    gpFarthest.OutputSpatialReference = new SpatialReference(102100);

                    gpFarthest.SubmitJobAsync(parameters);

                    if (_mapWidget != null)
                    {
                        _mapWidget.Map.MouseClick -= Map_MouseClick;
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("error");
            }
        }