This is a work in progress package for a research project. The goal is to provide a fast and efficient binary viewshed program that can be run either on the command line programatically (via Python) to analyse large batches of data.
In order to make a composite viewshed, you can use the Faster Calculator to combine the output binary viewsheds.
./viewshed
--radius <value> or -r <value> : set the viewshed radius.
--centerX <value> or -x <value> : set x coordinate of observer.
--centerY <value> or -y <value> : set y coordinate of observer.
--resolution <value> or -z <value> : set the resolution of the input data.
--observerheight <value> or -o <value> : set the height a.g.l. of the observer.
--targetheight <value> or -t <value> : set the height a.g.l. of the target.
--pointtopoint or -p : calculate line of sight rather than viewshed
--pointtopointax <value> or -j <value> : set x coordinate of observer.
--pointtopointay <value> or -k <value> : set y coordinate of observer.
--pointtopointbx <value> or -l <value> : set x coordinate of target.
--pointtopointby <value> or -m <value> : set y coordinate of target.
--inputfile <value> or -i <value> : input file name (.tif).
--outputfile <value> or -f <value> : output file name (.tif).
For example:
./viewshed -r 20000 -x 345678 -y 456789 -z 50 -o 1.5 -t 100 -i DEM.tif -f VIEWSHED.tif
Would run a viewshed of 20km around the point 345678,456789 assuming a 1.5m tall person looking for a 100m tall object in the landscape. The input data (50m resolution) would be DEM.tif and the output file would be saved to VIEWSHED.tif
import viewshed
#calculate a viewshed
viewshed.doViewshed(radius, resolution, centreX, centreY, observerHeight, targetHeight, inputFile, outputFile)
#calculate a line of sight
viewshed.doLoS(resolution, observerX, observerY, targetX, targetY, observerHeight, targetHeight, inputFile)
To compile the command line program:
gcc viewshed.cpp -framework GDAL -o viewshed -O3
gcc viewshed.cpp -lgdal -lm -o viewshed -O3
To rebuild the Python Bindings (requires SWIG):
swig -python -c++ viewshed.i ; python setup.py build_ext --inplace