Skip to main content

viewshed

Fast, exact line-of-sight viewsheds for Python and Rust.

Most fast viewshed tools approximate line of sight; GDAL's, for example, wrongly hid 1–5% of visible ground in our tests. The exact ones are slow to call or hard to install. viewshed aims to be both exact and fast: a Rust core, NumPy in and out, pip install on any platform with no GDAL, GRASS or compiler, and first-class support for many observers (cumulative viewsheds, visibility index, wind-turbine ZTV).

Status

0.1.0, the first release. See the repository for the plan and the conformance suite that checks every result.

  • Exact, and checked. The default surface model is GRASS r.viewshed's, and results match GRASS 8.4 on every cell, with and without earth curvature and refraction. Two independent checkers back this up: an exact bilinear line-of-sight oracle (closed form, float decisions certified by rigorous rounding-error bounds, ties in rational arithmetic), and an r.viewshed-model oracle written from the method's description. The "bilinear" surface is exact line of sight on the bilinear surface and matches that oracle on every cell (see Bilinear surface). Accuracy against real geometry is measured on analytic scenes and continuous surfaces.
  • Fast. A radial sweep in Rust on all cores: a 1,000-cell radius (4 million cells) takes about 1 s and 100 MB on a 4-core laptop, against 8–9 s for r.viewshed.
  • Wind-farm ZTV. Counts how many turbine tips every cell can see, either by the definition (every cell an observer) or by the usual reciprocal shortcut (one viewshed per tip, about 5× faster and within a few hundredths of a percent of the definition). On an 8 km square at 10 m with 8 turbines, the definition takes about 7 s on a 4-core laptop.
  • Earth curvature and refraction, on by default, as in GRASS r.viewshed -c -r.
Package Install Code
Python pip install viewshed (abi3 wheels for Python ≥ 3.9) python/
Rust cargo add viewshed crates/viewshed/

Python

import numpy as np
import viewshed

dem = np.zeros((41, 41)); dem[15, :] = 5.0          # flat ground with a 5 m wall
gt = (0.0, 1.0, 0.0, 41.0, 0.0, -1.0)               # GDAL-style geotransform
seen = viewshed.viewshed(dem, gt, observer=(20.5, 20.5), observer_height=1.6)   # bool array

# zone of theoretical visibility: how many blade tips each cell can see from 2 m
tips = [(10.5, 30.5, 150.0), (30.5, 30.5, 150.0)]
counts = viewshed.ztv(dem, gt, tips, observer_height=2.0)                      # uint32 array

Options: observer_height, target_height, max_distance, curvature (default on), refraction (0.13), earth_radius (mean earth radius), surface ("rviewshed", or "bilinear": exact line of sight on the bilinear surface, observer at its exact point). The computation runs in Rust with the GIL released. viewshed.reference is the original pure-NumPy implementation, kept as an independent check.

Surface model

Heights at cell centres, bilinearly interpolated between them. A cell is visible when the straight line from the observer's eye to the point target_height above the cell centre stays on or above the surface. With curvature on, every point is lowered by d²/(2R)·(1 − refraction) at horizontal distance d. No-data (NaN) never blocks and is never visible.

Bilinear surface

surface="bilinear" treats the DEM as heights at cell centres joined by bilinear interpolation, puts the observer at its exact point (not snapped to a cell centre) and decides line of sight to every cell exactly on that surface. Each decision is made in floating point only when rigorous rounding-error bounds prove it; the rare undecided sightlines are settled in rational arithmetic. So the output is identical, cell for cell, to the exact oracle in conformance/. No-data (NaN) never blocks and is never visible; a patch (the square between four cell centres) with a no-data corner has no surface. A sightline is blocked only where it passes strictly below the surface along a stretch of positive length, so touching a single grid vertex between two patches without surface (possible only on exact lattice directions at the edge of no-data areas) doesn't block it.

Large rasters (32,768 cells or more) are computed outward from the observer in rings, split into 64 angular sectors that run in parallel. Each sector keeps an analytic horizon of the terrain inserted so far. A cell certainly below that horizon is hidden without a sightline walk, whole 4×4 blocks of such cells are skipped together, and a cell certainly above it only has its last few cells walked. Small rasters walk each sightline with a max-height pyramid.

Speed on 2,001 × 2,001 windows of real terrain (wall time, best of three, 4 cores of an i5-8500T; observer 1.6 m above the ground, curvature and refraction on):

Terrain Observer Visible Exact bilinear r.viewshed-model sweep (approximate)
Alps (Copernicus 30 m) window centre 0.6% 0.21 s 0.43 s
Alps highest point 11% 0.42 s 0.55 s
Iowa (USGS 3DEP 10 m) window centre 1% 0.22 s 0.43 s
Iowa highest point 6% 0.34 s 0.50 s
Kansas (USGS 3DEP 10 m) window centre 14% 0.96 s 0.53 s
Kansas highest point 37% 0.89 s 0.62 s
Wellington (1 m LiDAR) window centre 17% 0.55 s 0.51 s
Wellington highest point 48% 0.85 s 0.65 s

The exact bilinear result is faster than this library's approximate r.viewshed-model sweep (same runs) on the Alps and Iowa windows, about level on the Wellington centre, and 1.3–1.8× slower where much of the terrain is visible (Kansas, the Wellington high point).

Licence

MIT OR Apache-2.0, at your option.

Metadata

Release files for viewshed 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viewshed 0.1.0
File Size Uploaded Provenance Actions
viewshed-0.1.0.tar.gz 64.6 kB With provenance Details for viewshed-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for viewshed 0.1.0
File Actions
viewshed-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for viewshed-0.1.0-cp39-abi3-win_amd64.whl
viewshed-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for viewshed-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
viewshed-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for viewshed-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
viewshed-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for viewshed-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
viewshed-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for viewshed-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 2.9 MB

Release files / viewshed-0.1.0.tar.gz

Download URL viewshed-0.1.0.tar.gz
Size 64.6 kB
Tags Source
SHA-256 checksum
How to use checksums
14ca5d06a8934de8976cbe8a036c4d20db1c150eee5d9f2986e690bde6ccf4f5
BLAKE2b-256 checksum
How to use checksums
34fddfdd46d2a83bca8dac2bfd9c7b5de5ee7ad1247008360209fa4a9f7bc60e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / viewshed-0.1.0-cp39-abi3-win_amd64.whl

Download URL viewshed-0.1.0-cp39-abi3-win_amd64.whl
Size 454.7 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
69730eb65f837f8474b675842832fc1baf7fca1beadb737045e9527fb17e35bc
BLAKE2b-256 checksum
How to use checksums
56bb2765324a3642b54a9f5ff0cd52ce98fe81ff16bd57019e99cc71afe79ec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / viewshed-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL viewshed-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 628.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f99bffca16fca09de0a5d98776172fdb1663ecd45fc15084bafd2b5c9c868c58
BLAKE2b-256 checksum
How to use checksums
9ecb19e3302b5e55ca737925463b7fdda0ae757c8325bd33116b627867e9da56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / viewshed-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL viewshed-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 602.5 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ffe33920864cc83119dc42541734881552804fb4b9b492a1b46e458274e0ca37
BLAKE2b-256 checksum
How to use checksums
0bfec505e06b4892e25055e06359b692b756c0645ed1fb9e22c664dedb5e0c24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / viewshed-0.1.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL viewshed-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 543.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fcd4a0e2b9cf7cbb30ba1aef8135b1287d56625f829a8b99e25209007d6512ec
BLAKE2b-256 checksum
How to use checksums
c541f7f2c46962ffa665ec1d8a2e0e8ebf8599d200f121fc36b7f3fa71d29c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / viewshed-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL viewshed-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 569.6 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
41f73aac40148dfb5a3ab83587e7f3ccc439648715af54ccbff01ed9e893753f
BLAKE2b-256 checksum
How to use checksums
f935e5c413a313194257b3fcc5ab41d71ce3a515830fd149736298a849506e28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for viewshed 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for viewshed-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page