Visualize UAV Flight Path on 2-D and 3-D Maps
This example visualizes a simulated unmanned aerial vehicle (UAV) flight from the Mauna Loa Baseline Observatory to the top of the Mauna Loa Volcano in Hawaii. First, display the track on geographic axes and a geographic globe. Then, synchronize the view and visualize the flight path by using camera navigation functions. Finally, view the top of the Mauna Loa volcano as a panorama.
Visualize Region of Interest in 2-D
The use of UAVs to track characteristics of changing topology, gasses, and ash clouds around volcanos is becoming an important area of research for scientists . A UAV can travel in regions that are hazardous for a volcanologist. Simulating the flight path of the UAV prior to sending it out on a mission can assist with understanding the topology and terrain. To gain an overview and 2-D perspective of the region, view the locations of the Mauna Loa Baseline Observatory and the Mauna Loa Volcano in a geographic axes.
Get Coordinates of Mauna Loa Baseline Observatory
Specify the coordinates of the Mauna Loa Baseline Observatory . The height of the observatory is in meters above mean sea level (MSL).
obslat = 19.5362; obslon = -155.5763; obsH = 3397.00;
Get Coordinates of Mauna Loa Volcano
Specify the coordinates of the top of Mauna Loa . The height of the volcano is orthometric and is in meters.
mllat = 19.475; mllon = -155.608; mlH = 4169;
View Mauna Loa Baseline Observatory and Mauna Loa Volcano in 2-D
For a 2-D perspective of the region, use
geoplot to plot the location of the observatory and the top of the volcano.
figure geoaxes("Basemap","satellite","ZoomLevel",12); hold("on") geoplot(obslat,obslon,"ow","MarkerSize",10,"MarkerFaceColor","magenta", ... "DisplayName","Mauna Loa Observatory"); geoplot(mllat,mllon,"ow","MarkerSize",10,"MarkerFaceColor","blue", ... "DisplayName","Mauna Loa Volcanao"); legend
Synchronize View of Mauna Loa Baseline Observatory in 2-D and 3-D
Use the geographic axes to view the observatory in 2-D and the geographic globe to view the observatory in 3-D.
Create Geographic Axes and Geographic Globe in Same Figure
Set up a 2-D and 3-D map display by creating geographic axes and a geographic globe in the same UI figure. To view more of the 2-D map, set the
InnerPosition of the geographic axes to its
OuterPosition. To view both map displays with the same basemap, set the basemap of the geographic axes to "satellite".
figpos = [1000 500 800 400]; uif = uifigure("Position",figpos); ug = uigridlayout(uif,[1,2]); p1 = uipanel(ug); p2 = uipanel(ug); gx = geoaxes(p1,"Basemap","satellite"); gg = geoglobe(p2); gx.InnerPosition = gx.OuterPosition; gg.Position = [0 0 1 1];
View Observatory in 2-D
View the observatory from 200 meters above the terrain. Control the view of the geographic axes by changing its map center and zoom level. You can synchronize the view of the geographic axes with the view of the geographic globe by converting the camera height of the globe to a zoom level for the axes. Calculate an approximate zoom level from terrain height by using the
heightToZoomLevel local function.
heightAboveTerrain = 200; gx.MapCenter = [obslat, obslon]; zoomLevel = heightToZoomLevel(heightAboveTerrain, obslat); gx.ZoomLevel = zoomLevel;
View Observatory in 3-D
Control the view of the geographic globe by changing the position of the camera. The
campos function requires you to specify ellipsoidal height (relative to the WGS84 ellipsoid) instead of orthometric height (relative to mean sea level). Convert the height of the observatory to ellipsoidal height. All heights are in meters.
N = egm96geoid(obslat, obslon); obsh = obsH + N; ellipsoidalHeight = obsh + heightAboveTerrain; campos(gg,obslat,obslon,ellipsoidalHeight) drawnow
Import Flight Track Data and Calculate Heading and 3-D Distance
Import the simulated flight track from the Mauna Loa Baseline Observatory to the top of the Mauna Loa volcano. The file contains the latitudes, longitudes, and altitudes of the UAV path, referenced to mean sea level.
T = readgeotable("sample_uavtrack.gpx","Layer","track_points"); tlat = T.Shape.Latitude'; tlon = T.Shape.Longitude'; talt = T.Elevation';
Calculate Flight Headings
Calculate the UAV heading at each track point using the
wgs84 = wgs84Ellipsoid; theading = azimuth(tlat(1:end-1),tlon(1:end-1),tlat(2:end),tlon(2:end),wgs84); theading = [theading(1);theading(:)];
Calculate 3-D Distances
Calculate the cumulative distance for the UAV flight track. The
distance function does not take into account changes in elevation or altitude. In order to calculate the distance the UAV moves from point to point in 3-D, you need to work in geocentric Cartesian coordinates (X, Y, Z). Compute the point-to-point offset components (in meters) using the
ecefOffset function. The altitude data of the UAV flight is referenced to the mean sea level. To use the
ecefOffset function, the heights must be referenced to the ellipsoid. Convert the orthometric heights of the flight track to ellipsoidal height (relative to the WGS84 ellipsoid). All heights are in meters.
N = egm96geoid(tlat,tlon); h = talt + N;
Compute distance offsets.
lat1 = tlat(1:end-1); lat2 = tlat(2:end); lon1 = tlon(1:end-1); lon2 = tlon(2:end); h1 = h(1:end-1); h2 = h(2:end); [dx,dy,dz] = ecefOffset(wgs84,lat1,lon1,h1,lat2,lon2,h2);
Calculate the Euclidean distance between each pair of adjacent points using the
hypot function. The distance is in meters.
distanceIncrementIn3D = hypot(hypot(dx, dy), dz);
Compute cumulative distance in 3-D and the total distance in meters.
cumulativeDistanceIn3D = cumsum(distanceIncrementIn3D); totalDistanceIn3D = sum(distanceIncrementIn3D); fprintf("Total UAV track distance is %f meters.\n",totalDistanceIn3D)
Total UAV track distance is 8931.072120 meters.
Assign a variable for the cumulative distance to be used for plotting the animation.
tdist = [0 cumulativeDistanceIn3D];
Plot Flight Line from Mauna Loa Baseline Observatory to top of Mauna Loa Volcano
Plot the simulated flight line from the Mauna Loa Baseline Observatory to the top of the Mauna Loa volcano.
Plot the flight line. By default, the geographic globe places the line at the center of the display. Hold the geographic axes to preserve the basemap. Its location will not change because you have previously set the
geoplot3(gg,tlat,tlon,talt,"c","LineWidth",2,"HeightReference","geoid") hold(gx,"on") ptrack = geoplot(gx,tlat,tlon,"c","LineWidth",2);
Set the map center and zoom level to be consistent with the 3-D view by converting the camera height for the globe to the zoom level for the axes.
[clat,clon,cheight] = campos(gg); gx.MapCenter = [clat,clon]; gx.ZoomLevel = heightToZoomLevel(cheight, clat); drawnow
Set Initial View from Mauna Loa Baseline Observatory to Top of Mauna Loa Volcano
View the flight line from the start position by setting the camera position to the first coordinate of the track. For a better perspective, set the camera height to 75 meters about the height of the track. View straight down to the observatory by setting the camera pitch to -90. View the track by setting the heading to the third element of the calculated heading array since the first two points of the track are the same location and the calculated heading for those locations is 0.
campos(gg,tlat(1),tlon(1)) camheight(gg,talt(1) + 75) campitch(gg,-90) camheading(gg,theading(3))
Show the location of the UAV in the 2-D map, and the start and end locations of the flight track with markers. Create a legend for the UAV track and markers.
marker = geoplot(gx,tlat(1),tlon(1),"ow","MarkerSize",10,"MarkerFaceColor","k"); mstart = geoplot(gx,tlat(1),tlon(1),"ow","MarkerSize",10,"MarkerFaceColor","magenta"); mend = geoplot(gx,tlat(end),tlon(end),"ow","MarkerSize",10,"MarkerFaceColor","blue"); marker.DisplayName = "Current Location"; mstart.DisplayName = "Start Location"; mend.DisplayName = "End Location"; ptrack.DisplayName = "UAV Track"; legend(gx)
View the topology of the region by changing the basemap.
gx.Basemap = "topographic";
View the coordinate location, altitude, and heading of the UAV by using a custom data tip that corresponds with the location of the UAV. Include the distance from the observatory.
dt = datatip(ptrack,"DataIndex",1,"Location","southeast"); dtrow = dataTipTextRow("Distance",tdist); dtrow(end+1) = dataTipTextRow("Altitude",talt); dtrow(end+1) = dataTipTextRow("Heading",theading); ptrack.DataTipTemplate.DataTipRows(end+1:end+3) = dtrow;
Fly from Mauna Loa Baseline Observatory to Top of Mauna Loa Volcano
Animate a flight from the Mauna Loa Baseline Observatory to the top of the Mauna Loa volcano. View the location of the UAV on the 2-D map by animating a marker and data tip. Animate the 3-D flight by setting the camera position. For a better view of the UAV track, set the camera height to 100 meters above the flight track. Update the camera pitch value for a better view of the flight track as the UAV navigates to the top of the volcano. To view the current location, altitude, and heading of the UAV, update the data tip with the current index.
pitch = -2.7689; campitch(gg,pitch) for k = 2:(length(tlat)-1) campos(gg,tlat(k),tlon(k)) camheight(gg,talt(k)+100) camheading(gg,theading(k)) set(marker,"LatitudeData",tlat(k),"LongitudeData",tlon(k)); dt.DataIndex = k; drawnow pause(.25) end campos(gg,tlat(end),tlon(end),talt(end)+100) dt.DataIndex = length(tlat);
View a 360-Degree Panorama from Top of Mauna Loa Volcano
View a 360-degree panorama from the top of Mauna Loa by rotating the camera heading 360 degrees. Rotate clockwise with a step size of 5-degrees and start at the next 5 degree step. Update the heading data tip.
initialHeading = camheading(gg); increment = 5; initialHeading = initialHeading + (increment - mod(initialHeading,increment)); filename = 'panoramic.gif'; for degree = initialHeading:increment:initialHeading+360 heading = mod(degree,360); ptrack.DataTipTemplate.DataTipRows(end).Value(dt.DataIndex) = heading; camheading(gg,heading); drawnow end
Convert Height (in meters above WGS84 ellipsoid) to Zoom Level
function zoomLevel = heightToZoomLevel(height, lat) earthCircumference = 2 * pi * 6378137; zoomLevel = log2((earthCircumference *cosd(lat)) / height) + 1; zoomLevel = max(0, zoomLevel); zoomLevel = min(19, zoomLevel); end
 Williams, Sarah C. P. “Studying Volcanic Eruptions with Aerial Drones.” Proceedings of the National Academy of Sciences of the United States of America 110, no. 27 (July 2, 2013): 10881. https://doi.org/10.1073/pnas.1309922110.
 NOAA. “Mauna Loa Baseline Observatory.” Global Monitoring Laboratory. Accessed June 16, 2020. https://gml.noaa.gov/obop/mlo/.
 USGS. “Mauna Loa.” Hawaiian Volcano Observatory. Accessed June 16, 2020. https://www.usgs.gov/volcanoes/mauna-loa.