There are many out-of-the-box raster analysis tools available in ArcGIS API for Python. In this guide, we will demonstrate a few examples such as creating viewshed, interpolating points, converting raster to feature, and converting feature to raster.
Let's first import the packages and make a connection to our GIS.
import arcgis from arcgis.gis import GIS gis = GIS(url='https://pythonapi.playground.esri.com/portal', username='arcgis_python', password='amazing_arcgis_123')
Viewshed indentifies the cells in an input raster that can be seen from one or more observation points or lines. Each cell in the output raster receives a value that indicates how many points or lines can be seen from each location. Viewshed is very useful when you want to know how visible objects might be, such as finding well-exposed places for communication towers.
In order to create viewshed, we need an input surface raster layer and an observer feature layer. In this example, we will use an elevation layer as the input raster and a few points representing schools as the observer layer.
items1 = gis.content.search("title: elevation, owner:portaladmin", item_type="Imagery Layer") items1
input_raster = items1.layers # elevation/DEM raster layer
map1 = gis.map('Stowe, Vermont, USA') map1
map1.legend = True
items2 = gis.content.search("title: schools, owner:portaladmin", item_type="Feature Layer") items2
observer_layer = items2.layers # school points as observer layer map1.add_layer(observer_layer)
As you can see, we have added five schools on the map. Now we have the input layers in place, we are ready to create viewshed.
from arcgis.raster.analytics import create_viewshed res = create_viewshed(input_elevation_surface = input_raster, input_observer_features= observer_layer) res
Let's visualize the viewshed output.
map2 = gis.map('Stowe, Vermont, USA') map2