Computes the viewshed geometry for a viewpoint within an osg scene object, returning the mesh geometry formed by the visible areas of the view frustum.
Syntax
meshgeom ST_ComputeViewShed(scene sc, cstring viewpoint);Parameters
| Parameter | Description |
|---|---|
sc | The scene object. Must be of the osg type. |
viewpoint | The viewpoint configuration as a JSON string. See Viewpoint fields. |
Viewpoint fields
The viewpoint parameter accepts a JSON string with the following fields:
{
"x": 0, // x-coordinate of the viewpoint
"y": 0, // y-coordinate of the viewpoint
"z": 0, // z-coordinate of the viewpoint
"h": 0, // height of the viewpoint
"azimuth": 0, // azimuth angle in degrees
"pitch": 0, // pitch angle in degrees
"distance": 100, // maximum viewing distance
"horizontalFov": 90, // horizontal field of view (FOV) in degrees
"verticalFov": 60, // vertical FOV in degrees
"depthMapSize": 128 // depth map size
}| Field | Description | Default | Valid values |
|---|---|---|---|
x | The x-coordinate of the viewpoint. | 0 | (-inf, +inf) |
y | The y-coordinate of the viewpoint. | 0 | (-inf, +inf) |
z | The z-coordinate of the viewpoint. | 0 | (-inf, +inf) |
h | The height of the viewpoint. | 0 | [0, +inf) |
azimuth | The clockwise angle from north (the y-axis forward direction) to the viewing point. Unit: degrees. | 0 | [-180, 180] |
pitch | The angle between the viewing point and the XOY plane. Positive values indicate the viewpoint is above the XOY plane; negative values indicate below. Unit: degrees. | 0 | [-90, 90] |
distance | The maximum viewing distance. A larger value indicates a wider coverage of the view frustum. | 100 | (0, +inf) |
horizontalFov | The horizontal field of view (FOV). Unit: degrees. | 90 | (0, 180) |
verticalFov | The vertical FOV. Unit: degrees. | 60 | (0, 180) |
depthMapSize | The depth map size. A larger value produces a finer view frustum. | 128 | (0, 2048] |
Description
ST_ComputeViewShed computes the view frustum for the specified viewpoint within a scene object and returns only the geometry visible from that viewpoint (the viewshed). For details on how the view frustum is calculated, see ST_ComputeFrustum.
This function supports only scene objects of the osg type.
The following figures show a sample view frustum from the top and side views.
View frustum (top view)

View frustum (side view)

Examples
The following example computes the viewshed for a viewpoint at coordinates (2938, 750, 90) with a height of 1.8 m, an azimuth of 90°, a pitch of -35°, a 90°×60° field of view, and a maximum viewing distance of 600 m. ST_NumPatches returns the number of polygonal patches in the resulting mesh geometry.
SELECT ST_NumPatches(ST_ComputeViewShed(scene, '{"x" : 2938, "y" : 750, "z" : 90, "h" : 1.8, "azimuth" : 90, "pitch" : -35, "horizontalFov" : 90, "verticalFov" : 60, "distance" : 600, "depthMapSize" : 128}')) from t;
--------
32766