Skip To Content ArcGIS for Developers Sign In Dashboard

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(profile="your_enterprise_profile")

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 = gis.content.search("title: elevation, owner:portaladmin", item_type="Imagery Layer")
items1[0]
Out[3]:
elevation
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 = gis.map('Stowe, Vermont, USA')
map1

In [6]:
map1.add_layer(input_raster)
In [10]:
map1.legend = True
In [7]:
items2 = gis.content.search("title: schools, owner:portaladmin", item_type="Feature Layer")
items2[0]
Out[7]:
schools
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
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.

In [9]:
from arcgis.raster.analytics import create_viewshed

res = create_viewshed(input_elevation_surface = input_raster,
                      input_observer_features= observer_layer)
res
Out[9]:
CreateViewshed_CGU80D
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 = gis.map('Stowe, Vermont, USA')
map2