My goal: Using a .TIF DEM, I would like to conduct a viewshed analysis. This is to be used as one feature for a larger program written in Python that will significantly improve work quality in my profession. Ultimately, I am looking for a binary output raster that I can manipulate with GeoPandas or Shapely, then plot as polygons in Folium.
Raster data viewshed analysis with Python was extremely helpful, but I have been unable to implement the suggested methods successfully. Below is my closest successful attempt using GDAL, but I have not found a specific example of the required inputs in the documentation.
from osgeo import gdal
band = gdal.Open('elevation.TIF').GetRasterBand(1)
gdal.ViewshedGenerate(
srcBand = band,
driverName = 'GTiff',
targetRasterName = 'viewtest.TIF',
creationOptions = 'COMPRESS=NONE',
observerX = test_center[1],
observerY = test_center[0],
observerHeight = 1.9,
targetHeight = 2,
visibleVal = 1,
invisibleVal = 0,
outOfRangeVal = 0,
noDataVal = 0,
dfCurvCoeff = 1 - 1/7,
mode = 'NORMAL',
maxDistance = 1000)
I get the following error, related to the fourth line: creationOptions
File ~\anaconda3\envs\ARES\lib\site-packages\osgeo\gdal.py:4084, in ViewshedGenerate(*args, **kwargs)
4082 def ViewshedGenerate(*args, **kwargs):
4083 r"""ViewshedGenerate(Band srcBand, char const * driverName, char const * targetRasterName, char ** creationOptions, double observerX, double observerY, double observerHeight, double targetHeight, double visibleVal, double invisibleVal, double outOfRangeVal, double noDataVal, double dfCurvCoeff, GDALViewshedMode mode, double maxDistance, GDALProgressFunc callback=0, void * callback_data=None, GDALViewshedOutputType heightMode=GVOT_NORMAL, char ** papszOptions=None) -> Dataset"""
-> 4084 return _gdal.ViewshedGenerate(*args, **kwargs)
TypeError: in method 'ViewshedGenerate', argument 4 of type 'char **'
Here is the documentation I found related to creationOptions for drivers, but I was not able to discern how to implement it specifically in Python. I cannot find anywhere to describe what format needs to be passed into the function.
I am not invested in any specific method/GIS- I have also tried QGIS and GRASS APIs to no avail, and this package but I was unable to install it successfully.