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.
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> FeatureLayer
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features<SPAN class="punctuation token">.</SPAN>managers <SPAN class="keyword token">import</SPAN> FeatureLayerManager
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>geometry <SPAN class="keyword token">import</SPAN> filters
<SPAN class="keyword token">from</SPAN> IPython<SPAN class="punctuation token">.</SPAN>display <SPAN class="keyword token">import</SPAN> display
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://your.portal.here/"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
<SPAN class="comment token">#assets layer</SPAN>
cellSiteFeatureLayer <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'88b5acd4444343b3bdaea40918d070bf'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#storm track layer</SPAN>
hurricaneFeatureLayer <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'6c8256c93c0e40debe46d9dcf79d0049'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#alarms layer</SPAN>
warningsFeatureLayer <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'6f735776f0c246b1ba602a774dbc1b1d'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Next, well truncate and clear out previous alarms and vulnerable assets from the alarms layers.
warningsLayer <SPAN class="operator token">=</SPAN> warningsFeatureLayer<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
warningsLayer<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>truncate<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="operator token">=</SPAN> hurricaneFeatureLayer<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN>
queryHurricane <SPAN class="operator token">=</SPAN> hurricaneFeatures<SPAN class="punctuation token">.</SPAN>query<SPAN class="punctuation token">(</SPAN>where<SPAN class="operator token">=</SPAN><SPAN class="string token">'1=1'</SPAN><SPAN class="punctuation token">)</SPAN>
hurricaneGeometry <SPAN class="operator token">=</SPAN> queryHurricane<SPAN class="punctuation token">.</SPAN>features<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>geometry
<SPAN class="comment token">##print (hurricaneGeometry)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Now we'll the use the geometry we just stored as the spatial geometry filter for our query on the assets layer.
cellSiteFeatures <SPAN class="operator token">=</SPAN> cellSiteFeatureLayer<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
warningsResult <SPAN class="operator token">=</SPAN> cellSiteFeatures<SPAN class="punctuation token">.</SPAN>query<SPAN class="punctuation token">(</SPAN>where<SPAN class="operator token">=</SPAN><SPAN class="string token">'1=1'</SPAN><SPAN class="punctuation token">,</SPAN> out_fields<SPAN class="operator token">=</SPAN><SPAN class="string token">'SiteID'</SPAN><SPAN class="punctuation token">,</SPAN> geometry_filter<SPAN class="operator token">=</SPAN>filters<SPAN class="punctuation token">.</SPAN>intersects<SPAN class="punctuation token">(</SPAN>hurricaneGeometry<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">##print(warningsResult)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Finally, take the feature set returned by the query and add the features to the alarm layer.
warningsLayer<SPAN class="punctuation token">.</SPAN>edit_features<SPAN class="punctuation token">(</SPAN>adds<SPAN class="operator token">=</SPAN>warningsResult<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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:
- Locally in your own IDE
- Within ArcGIS Pro as a GP tool
- Shared as a GP service and leveraged in the GP widget of Web AppBuilder
- Brought into ArcGIS Notebook server
- Ran automatically using Windows Task Scheduler
Ninja Pro Tip: Leverage Operations Dashboard for ArcGIS to view the results of the analysis.

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