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_ElevationSync/Profi…
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;
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)
Hi,
Here's the Python script I use with Local Server in a similar scenario:
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> math inputLine <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> inputRaster <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> outputShapeZ <SPAN class="operator token">=</SPAN> <SPAN class="string token">"in_memory\\outShapeZ"</SPAN> outputShapeM <SPAN class="operator token">=</SPAN> <SPAN class="string token">"in_memory\\outShapeM"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ddd<SPAN class="punctuation token">.</SPAN>InterpolateShape<SPAN class="punctuation token">(</SPAN>inputRaster<SPAN class="punctuation token">,</SPAN> inputLine<SPAN class="punctuation token">,</SPAN> outputShapeZ<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CreateRoutes_lr<SPAN class="punctuation token">(</SPAN>outputShapeZ<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ident"</SPAN><SPAN class="punctuation token">,</SPAN> outputShapeM<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LENGTH"</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> outputShapeM<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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
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); }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.