none
UWP Get Altitude for Latitude / Longitude RRS feed

  • Question

  • I am trying to find an API that would let me get the Altitude value for a location (lat/long).

    I have found a "hackish" way of doing it by adding a secondary MapControl then just moving the map to the lat / long then asking the MapControl of the location from position (0,0) center of map.

    var result = MapHelper.TrySetViewAsync(new Geopoint(new BasicGeoposition { Latitude = latitude, Longitude = longitude }), 20, 0, 0, MapAnimationKind.None).GetResults();
    if (result)
    {
    	while (MapHelper.TryGetLocationFromOffset(new Point(0, 0), AltitudeReferenceSystem.Geoid, out var point))
    	{
    		if (point.Position.Altitude > double.Epsilon)
    		{
    			return point.Position.Altitude;
    		}
    	}
    
    	return -1;
    }
    What I'm looking for is the "Terrain" altitude at a given location.


    Friday, March 8, 2019 5:37 PM

Answers

  • It sounds like your use case really isn't supported. If you need a fully offline elevation source that you want to query very frequently, the map control will never be terribly efficient (and mining or attempting to extract or reproduce the data from it is a violation of the terms of use). It creates a full 3D mesh and calculates the intersection using a ray cast into the visible scene which is fairly expensive in terms of processing.

    I would recommend looking into downloading a copy of one of the freely available raster elevation sources (either worldwide like SRTM data, or specific to your region like various national LIDAR sets). These typically will be several GB in size, but can be queried very efficiently and frequently.

    If offline isn't required, there is a REST elevation service available which can be used for either single queries or a batch of several queries in one call.

    Monday, March 11, 2019 5:00 PM
    Moderator

All replies

  • I know I can get the altitude (via location) by using TryGetLocationFromOffset but this only works for location show in the viewport (aka what the MapControl is presenting). However I want to be able to get the altitude of any lat/long location regardless if it's being present in the viewport.

    Also you may say, use the Bing API that works. I also need this to work offline. This works with the MapControl as I am able to download the map which contains all the data I need.

    Friday, March 8, 2019 5:39 PM
  • Hi Bobby,

    Can you please clarify the failure case? 

    Sincerely,

    IoTGirl

    Friday, March 8, 2019 8:08 PM
    Owner
  • Currently the only way to get altitude is through the map control. There is no independent services API for altitude. If you want to query the altitude, the best way would be to set the map view to your desired location, wait for the map rendered event to make sure all the data has loaded, then query the location.

    The call should work while offline, although the results may be less accurate. The offline data packages only download a smaller set of terrain data to save space.

    Friday, March 8, 2019 8:54 PM
    Moderator
  • Currently the only way to get altitude is through the map control. There is no independent services API for altitude. If you want to query the altitude, the best way would be to set the map view to your desired location, wait for the map rendered event to make sure all the data has loaded, then query the location.

    The call should work while offline, although the results may be less accurate. The offline data packages only download a smaller set of terrain data to save space.

    This is what I thought and this is exactly what I've done. I don't think this will scale with the amount of request I'm going to need to make though. I have ensured my MapControl is small 10x10 pixels and that all other features (landmarks, etc) are disabled to ensure most efficient results?

    Thanks for your time.

    Friday, March 8, 2019 9:07 PM
  • Hi Bobby,

    Can you please clarify the failure case? 

    Sincerely,

    IoTGirl

    The request is a way to read Altitude by provide a Latitude / Longitude location. Currently there isn't a way to do this or at least a way that I am aware.
    Friday, March 8, 2019 9:54 PM
  • It sounds like your use case really isn't supported. If you need a fully offline elevation source that you want to query very frequently, the map control will never be terribly efficient (and mining or attempting to extract or reproduce the data from it is a violation of the terms of use). It creates a full 3D mesh and calculates the intersection using a ray cast into the visible scene which is fairly expensive in terms of processing.

    I would recommend looking into downloading a copy of one of the freely available raster elevation sources (either worldwide like SRTM data, or specific to your region like various national LIDAR sets). These typically will be several GB in size, but can be queried very efficiently and frequently.

    If offline isn't required, there is a REST elevation service available which can be used for either single queries or a batch of several queries in one call.

    Monday, March 11, 2019 5:00 PM
    Moderator
  • It sounds like your use case really isn't supported. If you need a fully offline elevation source that you want to query very frequently, the map control will never be terribly efficient (and mining or attempting to extract or reproduce the data from it is a violation of the terms of use). It creates a full 3D mesh and calculates the intersection using a ray cast into the visible scene which is fairly expensive in terms of processing.

    I would recommend looking into downloading a copy of one of the freely available raster elevation sources (either worldwide like SRTM data, or specific to your region like various national LIDAR sets). These typically will be several GB in size, but can be queried very efficiently and frequently.

    If offline isn't required, there is a REST elevation service available which can be used for either single queries or a batch of several queries in one call.

    Thanks for this. I think we have altered our plans (changing the feature) to not require knowing the terrain altitude. I think if we do bring it back we'll probable using your recommendation. Thanks for your response.
    Monday, March 11, 2019 6:06 PM
  • Hi Bobby,

    Please don't hesitate to follow yup with whatever you decide to do.

    Sincerely,

    IoTGirl

    Monday, March 11, 2019 6:29 PM
    Owner