Select to view content in your preferred language

I need help with GeoprocessingTask and Elevation Profile!

347
4
Jump to solution
02-20-2025 07:02 AM
Labels (3)
AndreyTsar
Emerging Contributor

I couldn't fully figure out GeoprocessingTask and the Elevation Profile.  Help me understand why outputFeatures.CanGetOutputFeatures is always false? My code:

var _elevationServiceUrl = new Uri("https://elevation.arcgis.com/arcgis/rest/services/Tools/ElevationSync/GPServer/Profile");
var geoprocessingTask = await GeoprocessingTask.CreateAsync(_elevationServiceUrl);

var fields = new List<Field>
{

};

var featureTable = new FeatureCollectionTable(fields, GeometryType.Polyline, SpatialReferences.Wgs84);
var feature = featureTable.CreateFeature();
feature.Geometry = polyline;
await featureTable.AddFeatureAsync(feature);

var parameters = await geoprocessingTask.CreateDefaultParametersAsync();
parameters.Inputs["InputLineFeatures"] = new GeoprocessingFeatures(featureTable);
parameters.Inputs["DEMResolution"] = new GeoprocessingString("FINEST");
parameters.Inputs["MaximumSampleDistance"] = new GeoprocessingDouble(200);

parameters.ReturnM = true;
parameters.ReturnZ = true;


var job = geoprocessingTask.CreateJob(parameters);
var result = await job.GetResultAsync();

if (result.Outputs.ContainsKey("OutputProfile"))
{
var outputFeatures = result.Outputs["OutputProfile"] as GeoprocessingFeatures;

if (outputFeatures != null && outputFeatures.CanGetOutputFeatures)
{
var featureSet = await outputFeatures.GetOutputFeaturesAsync();
foreach (var outputFeature in featureSet)
{
var geometry = outputFeature.Geometry as Polyline;
// Подальша обробка геометрії
}
}
else
{
MessageBox.Show("Помилка: OutputProfile не містить даних або не підтримує отримання результатів.");
}

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

As I understand from API reference, it must be like that:

 

IFeatureSet featureSet;   
if (outputFeatures.CanGetOutputFeatures)
    featureSet = await outputFeatures.GetOutputFeaturesAsync();
else
    featureSet = outputFeatures.Features ;

 

 

View solution in original post

4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

As I understand from API reference, it must be like that:

 

IFeatureSet featureSet;   
if (outputFeatures.CanGetOutputFeatures)
    featureSet = await outputFeatures.GetOutputFeaturesAsync();
else
    featureSet = outputFeatures.Features ;

 

 

AndreyTsar
Emerging Contributor

I really appreciate your response.This check should work

0 Kudos
AndreyTsar
Emerging Contributor

My final code: 

        public async Task<List<MapPoint>?> GetElevationProfile(Polyline polyline)
        {
            List<MapPoint> resultPoints = new();

            var _elevationServiceUrl = new Uri("https://elevation.arcgis.com/arcgis/rest/services/Tools/ElevationSync/GPServer/Profile");
            var geoprocessingTask = await GeoprocessingTask.CreateAsync(_elevationServiceUrl);
            var featureTable = new FeatureCollectionTable(new List<Field>(), GeometryType.Polyline, polyline.SpatialReference);
            var feature = featureTable.CreateFeature();
            feature.Geometry = polyline;

            await featureTable.AddFeatureAsync(feature);

            var parameters = await geoprocessingTask.CreateDefaultParametersAsync();
            parameters.Inputs.Add("InputLineFeatures", new GeoprocessingFeatures(featureTable));
            parameters.Inputs.Add("DEMResolution", new GeoprocessingString("FINEST"));
            parameters.Inputs.Add("MaximumSampleDistance", new GeoprocessingDouble(200));
            parameters.OutputSpatialReference = SpatialReferences.Wgs84;
            parameters.ReturnM = false;
            parameters.ReturnZ = true;

            try
            {
                var job = geoprocessingTask.CreateJob(parameters);
                var result = await job.GetResultAsync();

                if (result?.Outputs?.ContainsKey("OutputProfile") == true)
                {
                    var outputFeatures = result.Outputs["OutputProfile"] as GeoprocessingFeatures;
                    if (outputFeatures != null)
                    {
                        IFeatureSet? featureSet = outputFeatures!.CanGetOutputFeatures ? await outputFeatures!.GetOutputFeaturesAsync() : outputFeatures!.Features;
                        if (featureSet != null)
                            foreach (var outputFeature in featureSet)
                            {
                                if (outputFeature?.Geometry?.GeometryType == GeometryType.Polyline)
                                {
                                    var poly = outputFeature.Geometry as Polyline;
                                    var points = poly?.Parts.SelectMany(x => x.Points);
                                    if (points != null) resultPoints.AddRange(points);
                                }
                            }
                        return resultPoints;
                    }
                    else MessageBox.Show("Помилка: OutputProfile не містить даних або не підтримує отримання результатів.");
                }
                else MessageBox.Show("Помилка: GetResultAsync не містить даних");
            }
            catch
            {
                MessageBox.Show("Помилка: OutputProfile не містить даних або не підтримує отримання результатів.");
            }
            return null;
        }
0 Kudos
AndreyTsar
Emerging Contributor

Several results:

AndreyTsar_1-1740140630003.pngAndreyTsar_2-1740140650662.png

 

AndreyTsar_3-1740140687374.png