Help with call to Profile Task...

614
4
02-27-2019 02:48 PM
TimB
by
New Contributor III

Any good pointers or examples to help with the call and return data of this task from .Net code?

Task: Profile 

https://elevation.arcgis.com/arcgis/rest/directories/arcgisoutput/Tools/ElevationSync_GPServer/Tools... 

0 Kudos
4 Replies
TimB
by
New Contributor III

OK,

So i used the geoprocessing/viewshed example to come up with the code below.  It makes the call and receives a reply.  However, the geometry that gets returned is only a polyline, and not a polylineZ (containing z values of the ground).  Does anyone have an idea why it does not appear to be working?  I thought it was something in the fieldlist but i tried multiple things there (including none), but nothing seemed to change the returned result. 

            var myProfileTask = await GeoprocessingTask.CreateAsync(new Uri(_viewshedUrl));

            List<Field> fieldList = new List<Field>();
            fieldList.Add(new Field(FieldType.OID, "ObjectID", "ObjectID", 10));
            fieldList.Add(new Field(FieldType.Float64, "Shape_Length", "Shape_Length", 10));

            var myInputFeatures = new FeatureCollectionTable(new List<Field>(), GeometryType.Polyline, SpatialReferences.WebMercator);

            Feature myInputFeature = myInputFeatures.CreateFeature();

            _selectedGraphics[0].Attributes.Add("ObjectID", 1);
            _selectedGraphics[0].Attributes.Add("Shape_Length", GeometryEngine.LengthGeodetic(_selectedGraphics[0].Geometry,LinearUnits.Meters,GeodeticCurveType.Geodesic));

            myInputFeature.Geometry = _selectedGraphics[0].Geometry;

            await myInputFeatures.AddFeatureAsync(myInputFeature);

            GeoprocessingParameters myProfileParameters =
                new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute);

            myProfileParameters.OutputSpatialReference = SpatialReferences.WebMercator; ;

            myProfileParameters.Inputs.Add("InputLineFeatures", new GeoprocessingFeatures(myInputFeatures));

            var myViewshedJob = myProfileTask.CreateJob(myProfileParameters);

            try
            {
                GeoprocessingResult myAnalysisResult = await myViewshedJob.GetResultAsync();

                GeoprocessingFeatures myProfileResultFeatures = myAnalysisResult.Outputs["OutputProfile"] as GeoprocessingFeatures;

                // Add all the results as a graphics to the map
                IFeatureSet myViewshedAreas = myProfileResultFeatures.Features;
                foreach (var myFeature in myViewshedAreas)
                {
                    _resultOverlay.Graphics.Add(new Graphic(myFeature.Geometry));
                }
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem
                //if (myViewshedJob.Status == JobStatus.Failed && myViewshedJob.Error != null)
                //    _userViewModel.UserMessage="Executing geoprocessing failed. " + myViewshedJob.Error.Message, "Geoprocessing error";
                //else
                //    MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
            }
            finally
            {
                // Indicate that the geoprocessing is not running
                //SetBusy(false);
            }

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Here's the Python script I use with Local Server in a similar scenario:

import arcpy, math
inputLine = arcpy.GetParameterAsText(0)
inputRaster = arcpy.GetParameterAsText(1)
outputShapeZ = "in_memory\\outShapeZ"
outputShapeM = "in_memory\\outShapeM"
arcpy.ddd.InterpolateShape(inputRaster, inputLine, outputShapeZ)
arcpy.CreateRoutes_lr(outputShapeZ, "ident", outputShapeM, "LENGTH")
arcpy.SetParameterAsText(2, outputShapeM)

  

Create_Routes is optional, but that adds measure values along the line.

Using it with Local Server is the same workflow you probably already have:

- Import the Python Script to a Toolbox (ensure you check the relative path option)

- Define any parameters needed (in my case above that's two input strings and one derived/output parameter)

- Run the new script tool in ArcGIS Pro / ArcMap

- Run the Package Result tool and check the option to enable for ArcGIS Runtime

Cheers

Mike

0 Kudos
TimBranscomb
New Contributor

Thanks for the reply.  Unfortunately, in my use case scenario, i won't have localserver available.  Any insight into why the call my be just returning a 2d line, and not the expected polylineZ?  Are my inputs wrong?  What i am most unsure about are my 'fieldlist' inputs as well as my attributing for the input line.  The GP Task expects the following fields: OID, Shape_Length

BTW, hope you are doing well! -Tim B (you can guess the last name)

0 Kudos
TimBranscomb
New Contributor

Finally!  Figured it out.  I will post the entire code in a bit, but in the mean time, this is what i was missing:

Snippet

myProfileParameters.ReturnZ = true;myProfileParameters.ReturnM = true;
0 Kudos