ST_ComputeFrustum computes the view frustum of a viewpoint and returns it as a meshgeom object for downstream spatial analysis.
Syntax
meshgeom ST_ComputeFrustum(cstring viewpoint);Parameters
| Parameter | Description |
|---|---|
| viewpoint | Viewpoint configuration in JSON format. See the field reference below. |
Viewpoint JSON fields
All fields are optional and fall back to their defaults if omitted.
{
"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, // horizontal direction, in degrees clockwise from north (y-axis)
"pitch": 0, // vertical angle above (positive) or below (negative) the XOY plane, 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 resolution; higher values produce a finer frustum mesh
}| 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 | Horizontal viewing direction, measured in degrees clockwise from north (the positive y-axis). | 0 | [-180, 180] |
| pitch | Vertical viewing angle relative to the XOY plane. Positive values point above the plane; negative values point below. | 0 | [-90, 90] |
| distance | Maximum viewing distance. Larger values extend the frustum's reach. | 100 | (0, +inf) |
| horizontalFov | Horizontal field of view (FOV), in degrees. | 90 | (0, 180) |
| verticalFov | Vertical FOV, in degrees. | 60 | (0, 180) |
| depthMapSize | Depth map resolution. Larger values produce a finer frustum mesh. | 128 | (0, 2048] |
Description
ST_ComputeFrustum builds a 3D view frustum from the given viewpoint parameters and returns it as a meshgeom geometry composed of triangular patches.
View frustum (top view)

View frustum (side view)

Examples
Count the number of triangular patches in the computed frustum:
SELECT ST_NumPatches(ST_ComputeFrustum('{"x" : 2938, "y" : 750, "z" : 90, "h" : 1.8, "azimuth" : 90, "pitch" : -35, "horizontalFov" : 90, "verticalFov" : 60, "distance" : 600, "depthMapSize" : 128}'));
--------
32766The result 32,766 is the number of 3D triangles that make up the frustum mesh. A higher depthMapSize produces more triangles and a more precise frustum boundary.