Skip to contents

Use elevation data to compute the locations that can be seen, or how much higher they would have to be to be seen, from a certain position. The raster data coordinate reference system must planar (not lon/lat), with the elevation values in the same unit as the distance unit of the coordinate reference system.


# S4 method for class 'SpatRaster'
viewshed(x, loc, observer=1.80, target=0, curvcoef=6/7, output="yes/no", filename="", ...)



SpatRaster, single layer with elevation values. Values should have the same unit as the map units


location (x and y coordinates) or a cell number


numeric. The height above the elevation data of the observer


numeric. The height above the elevation data of the targets


numeric. Coefficient to consider the effect of the curvature of the earth and refraction of the atmosphere. The elevation values are corrected with: elevation = elevation - curvcoeff * (distance)^2 / (earth_diameter). This means that with the default value of 0.85714, you lose sight of about 1 meter of elevation for each 385 m of planar distance


character. Can be "yes/no" to get a binary (logical) output showing what areas are visible; "land" to get the height above the current elevation that would be visible; or "sea" the elevation above sea level that would be visible


character. Output filename


Options for writing files as in writeRaster

See also


The algorithm used is by Wang et al.:


if (gdal() >= 3.1) {
  f <- system.file("ex/elev.tif", package="terra")
  r <- rast(f)
  x <- project(r, "EPSG:2169")
  p <- cbind(70300, 96982)
  v <- viewshed(x, p, 0, 0, 0.85714)