Main Content

campos

Set or query position of camera for geographic globe

Description

Set Position

campos(g,lat,lon) sets the latitude and longitude of the camera for the specified geographic globe.

example

campos(g,lat,lon,height) sets the latitude, longitude, and ellipsoidal height of the camera. If you want to set only the height of the camera, then use the camheight function instead.

Set Mode

campos(g,'auto') sets the camera position to an automatic mode, enabling the geographic globe to determine the latitude and longitude of the camera based on the plotted data. The mode defaults to automatic when you create a geographic globe. If you change the camera position using your mouse, then the mode switches to automatic. To control the mode for the height of the camera, use the camheight function instead.

example

campos(g,'manual') sets the camera position to a manual mode, specifying that the geographic globe preserve the latitude and longitude of the camera when the plotted data changes. If you change the camera position using the campos function, then the mode switches to manual.

Query Position

campos(g) displays the latitude, longitude, and ellipsoidal height of the camera as a three-element vector.

example

[latOut,lonOut,heightOut] = campos(___) sets the position or mode and then returns the latitude, longitude, and height of the camera. You can return the camera position using any of the previous syntaxes.

Examples

collapse all

Create a geographic globe. Specify the latitude and longitude of the Eiffel Tower, and specify a height that is 400 meters above the WGS84 reference ellipsoid. Use these values to move the camera.

uif = uifigure;
g = geoglobe(uif);

lat = 48.8584;
lon = 2.2945;
h = 400;
campos(g,lat,lon,h)

Get the position and the heading, pitch, and roll angles of the camera. Use this information to control the view of a different geographic globe or to automate navigation.

Create a geographic globe. Navigate to an area of interest using your mouse or gestures. For this example, navigate to an area around Hawaii.

uif = uifigure;
g = geoglobe(uif);

Bird's-eye view of Hawaii

Query the latitude, longitude, and ellipsoidal height of the camera, and assign each to a variable.

[camlat,camlon,camh] = campos(g)
camlat =

   18.1781


camlon =

 -155.9297


camh =

   6.6664e+04

Query the heading, pitch, and roll angles of the camera, and assign each to a variable.

heading = camheading(g)
pitch = campitch(g)
roll = camroll(g)
heading =

   16.7613


pitch =

  -24.1507


roll =

  359.9977

Use these values to control the view of a different geographic globe. For example, create a new geographic globe and programmatically set the view.

uif2 = uifigure;
g2 = geoglobe(uif2);
campos(g2,camlat,camlon,camh)
camheading(g2,heading)
campitch(g2,pitch)
camroll(g2,roll)

Preserve the position and the heading, pitch, and roll angles of the camera by setting the camera modes to manual. If you do not set the camera modes to manual, then the camera view resets when you plot new data.

Import a sample route along roads in Massachusetts using the gpxread function. Create a geographic globe with a road map and no terrain data. Preserve the basemap and terrain settings by using the hold function. Then, navigate to an area near Eastern Massachusetts using your mouse.

track = gpxread('sample_tracks.gpx','Index',2);
lat = track.Latitude;
lon = track.Longitude;
height = track.Elevation;

uif = uifigure;
g = geoglobe(uif,'Basemap','streets','Terrain','none');
hold(g,'on')

Map of an area around Eastern Massachusetts with labeled cities and roads

Set the camera modes to manual and plot the data. Note that the camera position does not change.

campos(g,'manual')
camheight(g,'manual')
camheading(g,'manual')
campitch(g,'manual')
camroll(g,'manual')
geoplot3(g,lat,lon,height,'LineWidth',3)

The same map with a blue line plotted along several roads

Input Arguments

collapse all

Geographic globe, specified as a GeographicGlobe object.[1]

Geodetic latitude of the camera, specified as a numeric scalar in the range [–90, 90] degrees.

Geodetic longitude of the camera, specified as a numeric scalar in the range [–360, 360].

Ellipsoidal height of the camera, specified as a numeric scalar in meters. Geographic globe objects use the WGS84 reference ellipsoid. For more information about ellipsoidal height, see Find Ellipsoidal Height from Orthometric Height.

If you specify the height so that the camera is level with or below the terrain, then the campos function sets the height to a value one meter above the terrain.

Output Arguments

collapse all

Geodetic latitude of the camera, returned as a numeric scalar in degrees.

Geodetic longitude of the camera, returned as a numeric scalar in degrees.

Ellipsoidal height of the camera, returned as a numeric scalar in meters. Geographic globe objects use the WGS84 reference ellipsoid. For more information about ellipsoidal height, see Find Ellipsoidal Height from Orthometric Height.

Introduced in R2020b

[1] Alignment of boundaries and region labels are a presentation of the feature provided by the data vendors and do not imply endorsement by MathWorks®.