Main Content

campos

Set or query position of camera for Site Viewer

Since R2025a

    Description

    Geographic Coordinates

    campos(viewer,lat,lon) sets the latitude and longitude of the camera for the specified Site Viewer. You can set the camera position using geographic coordinates when the CoordinateSystem property of the Site Viewer object is "geographic".

    campos(viewer,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.

    example

    campos(viewer) displays the latitude, longitude, and ellipsoidal height of the camera as a three-element vector. The function displays geographic coordinates when the when the CoordinateSystem property of the Site Viewer is "geographic".

    [latOut,lonOut,heightOut] = campos(___) returns the latitude, longitude, and height of the camera when the CoordinateSystem property of the Site Viewer is "geographic". You can return the camera position using any of the input argument combinations from the previous syntaxes.

    example

    Cartesian Coordinates

    campos(viewer,x,y,z) sets the xyz-coordinates of the camera for the specified Site Viewer. You can set the camera position using Cartesian coordinates when the CoordinateSystem property of the Site Viewer object is "cartesian".

    example

    campos(viewer) displays the xyz-coordinates of the camera as a three-element vector. The function displays Cartesian coordinates when the CoordinateSystem property of the Site Viewer is "cartesian".

    [xOut,yOut,zOut] = campos(___) returns the xyz-coordinates of the camera when the CoordinateSystem property of the Site Viewer is "cartesian". You can return the camera position using any of the input argument combinations from the previous syntaxes.

    example

    Examples

    collapse all

    Create a Site Viewer. By default, Site Viewer displays a 3-D globe using satellite imagery.

    viewer = siteviewer;

    Satellite imagery of Earth

    Query the CoordinateSystem property of the Site Viewer object. The result, "geographic", indicates that the Site Viewer represents the camera position using latitude, longitude, and ellipsoidal height values.

    viewer.CoordinateSystem
    ans = 
    "geographic"
    

    Query the latitude, longitude, and ellipsoidal height of the camera. The latitude and longitude are in degrees, and the ellipsoidal height is in meters above the WGS84 reference ellipsoid.

    [latOut,lonOut,heightOut] = campos(viewer)
    latOut = 
    35.1576
    
    lonOut = 
    -82.5000
    
    heightOut = 
    1.7190e+07
    

    Specify the latitude and longitude of Mount Washington, and specify a height that is 2400 meters above the ellipsoid. Use these values to move the camera.

    lat = 44.2706;
    lon = -71.3033;
    h = 2400;
    campos(viewer,lat,lon,h)

    Satellite imagery of Mount Washington

    Create a Site Viewer that displays a 3-D model from an STL file. The file models a small conference room with one table and four chairs.

    viewer = siteviewer(SceneModel="conferenceroom.stl");

    3-D model of a table and four chairs. The camera points at the backs of two chairs.

    Query the CoordinateSystem property of the Site Viewer object. The result, "cartesian", indicates that the Site Viewer represents the camera position using xyz-coordinates.

    viewer.CoordinateSystem
    ans = 
    "cartesian"
    

    Query the xyz-coordinates of the camera. The coordinates are in meters.

    [xOut,yOut,zOut] = campos(viewer)
    xOut = 
    0
    
    yOut = 
    -6.0000
    
    zOut = 
    1.2500
    

    Specify new camera coordinates. Use these values to move the camera.

    x = -6;
    y = 0;
    z = 1.5;
    campos(viewer,x,y,z)

    When you change the position of the camera, the pitch and heading angles remain the same. As a result, for this combination of xyz-coordinates, the conference room disappears from the view. Point the camera toward the conference room by changing the heading angle of the camera.

    camheading(viewer,-90)

    The same 3-D model, with the camera pointing at the sides of two chairs.

    When you display data in a Site Viewer, the Site Viewer focuses on the data by moving the camera. To preserve the camera view, before you plot the data, query the camera position and camera angles. Then, after you plot the data, reset the camera position and camera angles.

    Create a Site Viewer that displays buildings in Manhattan. For more information about the OpenStreetMap® file, see [1]. Navigate to an area of interest by interacting with the Site Viewer.

    viewer = siteviewer(Buildings="manhattan.osm",Basemap="openstreetmap");

    Site Viewer with buildings

    Query the position of the camera and the heading, pitch, and roll angles of the camera. Assign each value to a variable.

    [lat,lon,height] = campos(viewer);
    heading = camheading(viewer);
    pitch = campitch(viewer);
    roll = camroll(viewer);

    Create and display a transmitter site. Note that the camera zooms to the site.

    tx = txsite(Latitude=40.704,Longitude=-74.0155);
    show(tx)

    Close-up view of a transmitter site

    Reset the view using the stored camera position and camera angles.

    campos(viewer,lat,lon,height)
    camheading(viewer,heading)
    campitch(viewer,pitch)
    camroll(viewer,roll)

    The original camera view, including the transmitter site

    [1] The OpenStreetMap file is downloaded from https://www.openstreetmap.org, which provides access to crowd-sourced map data all over the world. The data is licensed under the Open Data Commons Open Database License (ODbL), https://opendatacommons.org/licenses/odbl/.

    Input Arguments

    collapse all

    Site Viewer, specified as a siteviewer object.1

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

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

    Ellipsoidal height of the camera, in meters, specified as a numeric scalar. Site Viewer objects use the WGS84 reference ellipsoid. For more information about ellipsoidal height, see Find Ellipsoidal Height from Orthometric Height (Mapping Toolbox).

    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.

    x-coordinate of the camera, in meters, specified as a numeric scalar.

    y-coordinate of the camera, in meters, specified as a numeric scalar.

    z-coordinate of the camera, in meters, specified as a numeric scalar.

    Output Arguments

    collapse all

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

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

    Ellipsoidal height of the camera, in meters, returned as a numeric scalar. Site Viewer objects use the WGS84 reference ellipsoid. For more information about ellipsoidal height, see Find Ellipsoidal Height from Orthometric Height (Mapping Toolbox).

    x-coordinate of the camera, in meters, returned as a numeric scalar.

    y-coordinate of the camera, in meters, returns as a numeric scalar.

    z-coordinate of the camera, in meters, returned as a numeric scalar.

    Version History

    Introduced in R2025a

    See Also

    Functions

    Objects


    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®.