ArcGIS Developer

ArcGIS API for Python

Perform Analysis - Using out of the box tools

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.

Getting prepared

Let's first import the packages and make a connection to our GIS.

In [2]:
import arcgis
from arcgis.gis import GIS

gis = GIS(url='', username='arcgis_python', password='amazing_arcgis_123')

Creating viewshed

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.

Figure 1. An example of creating viewshed with a single observation point

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.

In [3]:
items1 ="title: elevation, owner:portaladmin", item_type="Imagery Layer")
testImagery Layer by portaladmin
Last Modified: September 19, 2019
0 comments, 0 views
In [4]:
input_raster = items1[0].layers[0] # elevation/DEM raster layer
In [ ]:
map1 ='Stowe, Vermont, USA')

In [6]:
In [10]:
map1.legend = True
In [7]:
items2 ="title: schools, owner:portaladmin", item_type="Feature Layer")
Schools in Stowe Vermont. This point feature class dataset is intended to be used as part of the Spatial Analyst tutorial.Feature Layer Collection by portaladmin
Last Modified: September 19, 2019
0 comments, 0 views
In [8]:
observer_layer = items2[0].layers[0] # school points as 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.

In [9]:
from import create_viewshed

res = create_viewshed(input_elevation_surface = input_raster,
                      input_observer_features= observer_layer)
Analysis Image Service generated from CreateViewshedImagery Layer by portaladmin
Last Modified: September 24, 2019
0 comments, 0 views

Let's visualize the viewshed output.

In [ ]:
map2 ='Stowe, Vermont, USA')