Select to view content in your preferred language

Elevation not loaded + Profile Job

445
1
04-05-2022 04:50 AM
MichaelVowles
New Contributor

Hi,

I am trying to get the elevation at a point using code very similar to Get elevation at a point | ArcGIS Runtime API for .NET | ArcGIS Developer.

However the following throws an exception "Elevation must be loaded before you can get the elevation".

I am behind a proxy, could that be getting in the way of this working?

Code:

public class ArcGisAdapter
    {
        Surface Surface = new Surface();
        Uri _elevationUri = new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
        public async System.Threading.Tasks.Task<bool> InitializeAsync()
        {
            ArcGISRuntimeEnvironment.ApiKey = "<mykey>";
            
            ArcGISRuntimeEnvironment.Initialize();

            Surface.ElevationSources.Add(new ArcGISTiledElevationSource(_elevationUri));
            await Surface.LoadAsync();
            if (( Surface.LoadStatus == LoadStatus.FailedToLoad ) ||
                    Surface.LoadStatus == LoadStatus.NotLoaded)
            {
                Console.WriteLine($"Failed to load {Surface.LoadError.Message}");
                return false;
            }
            else
            {
                Console.WriteLine($"Loaded elevation {Surface.LoadStatus.ToString()}");
                return true;
            }
        }

        public async System.Threading.Tasks.Task<double> GetElevation()
        {
            try
            {
                // Get the elevation value.
                var point = new MapPoint(83.9, 28.42);
                var elevation = await Surface.GetElevationAsync(point);

                // Set the text displaying the elevation.
                Console.WriteLine($"{Math.Round(elevation)} m");
                return elevation;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return -1;
            }
        }
    }
}

Stack trace:

MichaelVowles_0-1649159195084.png

 

0 Kudos
1 Reply
KoushikHajra
Esri Contributor

Hi @MichaelVowles,

Thank you for reaching out to us. After taking a look at your code, I have a quick question.

Where are you calling your `GetElevation()` from? Without getting a broader context, it seems like you are loading the surface on a different thread than where you're trying to get the elevation from the surface? What happens if you move these two lines

var point = new MapPoint(83.9, 28.42);
var elevation = await Surface.GetElevationAsync(point);

 to after the 

await Surface.LoadAsync();

in the InitializeAsync() func? 

0 Kudos