Locate Assets in Harms Way w/ ArcGIS API for Python

Blog Post created by PHuls-esristaff Employee on Jul 27, 2019

Updates to original script in comments below - 9/5/2019


With hurricane season upon us, I wanted to share a simple but powerful python script which locates assets that are in path of a major storm.  The script leverages the ArcGIS Python API and can be run manually or automatically from a variety of sources, which I'll cover later on.  The script also requires that your asset locations are in a feature layer within your GIS portal, along with a polygon feature layer used as a storm track, and a layer to add your alarms or vulnerable assets to. The script is attached below, but lets first break it down.


First, import the necessary ArcGIS python libraries and authenticate into your GIS portal.  Since this script uses feature layers, we'll mostly use the arcgis.features module.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features.managers import FeatureLayerManager
from arcgis.geometry import filters
from IPython.display import display
gis = GIS("", 'username', 'password')


Next we'll load in the feature layers used in the script. The script requires a point feature layer of your asset locations, a polygon feature layer of your storm track, and another point layer used as alarms or your vulnerable asset locations.


Ninja Pro Tip: Leverage the Active Hurricane live feed from Esri's Living Atlas as your storm strack.

#assets layer
cellSiteFeatureLayer = gis.content.get('88b5acd4444343b3bdaea40918d070bf')
#storm track layer
hurricaneFeatureLayer = gis.content.get('6c8256c93c0e40debe46d9dcf79d0049')
#alarms layer
warningsFeatureLayer = gis.content.get('6f735776f0c246b1ba602a774dbc1b1d')

Next, well truncate and clear out previous alarms and vulnerable assets from the alarms layers.

warningsLayer = warningsFeatureLayer.layers[0]

Then, well store the current geometry of the polygon layer or the storm track which will be used to query the assets that fall within it.

hurricaneFeatures = hurricaneFeatureLayer.layers[8]
queryHurricane = hurricaneFeatures.query(where='1=1')
hurricaneGeometry = queryHurricane.features[3].geometry
##print (hurricaneGeometry)

Now we'll the use the geometry we just stored as the spatial geometry filter for our query on the assets layer.

cellSiteFeatures = cellSiteFeatureLayer.layers[0]
warningsResult = cellSiteFeatures.query(where='1=1', out_fields='SiteID', geometry_filter=filters.intersects(hurricaneGeometry))

Finally, take the feature set returned by the query and add the features to the alarm layer.


And that's it. The result is new point locations showing you where assets fall within a storm track.



The script can be run in variety of locations depending on the experience you want for the end user.  Here some options:

  1. Locally in your own IDE
  2. Within ArcGIS Pro as a GP tool
  3. Shared as a GP service and leveraged in the GP widget of Web AppBuilder
  4. Brought into ArcGIS Notebook server
  5. Ran automatically using Windows Task Scheduler 


Ninja Pro Tip: Leverage Operations Dashboard for ArcGIS to view the results of the analysis.



Patrick Huls

Solution Engineer Team Lead - Telecommunications

LinkedIn: Patrick Huls| Twitter: @SpatialNinja| GeoNet:Phuls-esristaff