Select to view content in your preferred language

Geoprocessing question

469
3
01-03-2011 03:34 PM
DavidAshton
Occasional Contributor III
I was checking out the geoprocessing examples and I'm thinking of taking a crack at creating one for an application I have but I have two simple questions:

First: all the tasks seem to be kicking off by using the DrawEventArgs args complete call.  I was wondering can the tasks take more than one input ...more than one poly,line, or point?  If yes I will ask another question later.

Dave
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor

all the tasks seem to be kicking off by using the DrawEventArgs args complete call.

It's a good way to execute the task when this one is expecting a polygon or a polyline as input. But there are also samples executing the task on the mouse_click event.
You can execute the task at any time as soon as your input parameters are ready.

I was wondering can the tasks take more than one input ...more than one poly,line, or point?

Yes you can define multiple input parameters.
If your number of input geometry is not defined you can also consider to use a FeatureSetLayer as input.
0 Kudos
DavidAshton
Occasional Contributor III
Dominque,
Thanks for the reply.  O.K. what you told me is along the lines of what I was thinking.  So I'm trying to create a task that accepts a Polygon or muilitiple polygons for the input. At the end of this post you will find the Parameter from my endpoint.

I have created a button that triggers the polygon creation:
 private void CreateGeoPoly_Click(object sender, RoutedEventArgs e)
        {

            //Gives users ability to draw poly
            MyDrawObject = new Draw(Map)
            {
                DrawMode = DrawMode.Polygon,
                IsEnabled = true,
                FillSymbol = LayoutRoot.Resources["ClipFeaturesFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };

        

            //Start MyDrawObject_DrawComplete, which turns the drawn poly into a graphic
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
        }
        


Have the polygon is created I'm using the  DrawEventArgs complete to create the graphic, if the user wants to create another polygon she/he can just hit the CreateGeoPoly icon/button and create another and another and etc.

      private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            //Disable the drawing tool
            MyDrawObject.IsEnabled = false;

            //Start processing time bar
            ProcessingTextBlock.Visibility = Visibility.Visible;
            _processingTimer.Start();


            //Assign the graphic draw to a graphiclayer, the graphic layer is defined in xaml
            GraphicsLayer graphicsLayer = Map.Layers["MyGraphicsLayer"] as GraphicsLayer;

            //Ready the graphic to assign the graphic to the parameter
            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["ClipFeaturesFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol,
                Geometry = args.Geometry
            };
            //add graphic
            graphicsLayer.Graphics.Add(graphic);

          
        }



My thought is, now when the user wants to run the process I've created a simple start/run button but as you can see it errors out because  of parameter "args.Geometry" was declared in the last method (private void MyDrawObject_DrawComplete).

I'm having trouble figuring out what I need to swap out with args.Geometry maybe something like a referrence to my created graphicslayer geometry?  Is this something I can do, is it possible?  Or should I some how take the route
If your number of input geometry is not defined you can also consider to use a FeatureSetLayer as input.
  I guess I'm not sure if my input geometry is defined or not?

  private void RunGeoPolyButton_Click(object sender, RoutedEventArgs e)
        {


            //Declare GP Task and URL
            Geoprocessor geoprocessorTask = new Geoprocessor("http://servername/ArcGIS/rest/services/GPServer/CreatePoly");
            geoprocessorTask.UpdateDelay = 5000;


            //When Task Completes call method GeoprocessorTask_JobCompleted
            geoprocessorTask.JobCompleted += GeoprocessorTask_JobCompleted;


            //Input Parameters
           List<GPParameter> parameters = new List<GPParameter>();
                       parameters.Add(new GPFeatureRecordSetLayer("Draw_Polygon", args.Geometry));
            
            geoprocessorTask.SubmitJobAsync(parameters);




Parameter: Draw_Polygon
Data Type: GPFeatureRecordSetLayer
Display Name: Draw a polygon or multiple polygons.
Direction: esriGPParameterDirectionInput
Default Value:
Geometry Type: esriGeometryPolygon
Spatial Reference: 4326
Fields:
OBJECTID (Type: esriFieldTypeOID, Alias: OBJECTID)
SHAPE (Type: esriFieldTypeGeometry, Alias: SHAPE)
SHAPE_Length (Type: esriFieldTypeDouble, Alias: SHAPE_Length)
SHAPE_Area (Type: esriFieldTypeDouble, Alias: SHAPE_Area)
Parameter Type: esriGPParameterTypeOptional
Category:


Thanks for you time and help.

Dave
0 Kudos
DominiqueBroux
Esri Frequent Contributor

parameters.Add(new GPFeatureRecordSetLayer("Draw_Polygon", args.Geometry));



It's not working because you are using the GPFeatureRecordSetLayer constructor which is creating the recordset from only one geometry.
There is another constructor taking a FeatureSet as argument:
 
 parameters.Add(new GPFeatureRecordSetLayer("Draw_Polygon", new FeatureSet(
(Map.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics
)));
 
0 Kudos