Skip navigation
All People > PHuls-esristaff > Patrick Huls's Blog > 2019 > July
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("https://your.portal.here/", '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]
warningsLayer.manager.truncate()

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))
##print(warningsResult)

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

warningsLayer.edit_features(adds=warningsResult)

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

For a variety of planning, engineering, or inspection workflows, you may want to leverage street view applications with ArcGIS in lieu of, or before sending someone to the field.  There are many options for integrating street view with ArcGIS.  In this blog we'll outline the options for using Esri Partner solutions as well as options for linking to Bing and Google within an ArcGIS web map pop-up.

 

Esri Partners

Esri has partners which offer integrated street view solutions with ArcGIS.  These street view solutions can be used directly in ArcGIS Enterprise/Online, ArcGIS Pro, or Web AppBuilder for ArcGIS. 

 

Cyclomedia - The Street SmartTM Widget for ArcGIS introduces high resolution street-level imagery to Web Apps that you build with the Web AppBuilder.

 

Mapillary -  With the Mapillary widget for ArcGIS, you can bring Mapillary's street-level imagery into custom web applications built with Web AppBuilder. 

 

GeoCam - 3D urban modeling for microwave line of sign analysis, macro/small cell RF propagation modeling, and road-based aerial fiber mapping.

 

Feature Pop-up Street View Hyperlinks

Using Arcade within feature pop-ups in a web map, you can dynamically build a URL hyperlink that will pass a map features coordinates to Google's Street View or Bing's StreetSide to automatically open up street view in a new browser tab and zoom you to a location. Here is how:

 

First, configure a pop-up for a feature layer in your web map and Add an attribute expression.

 

 

Second, use the following Arcade expression to create your hyperlink.

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

function AuxSphereToLatLon(x, y) {
  Console("Converting...");
  // Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
  var rMajor = 6378137;
  var shift = PI * rMajor;
  Longitude = x / shift * 180.0;
  Latitude = y / shift * 180.0;
  Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
  Console("4326 Spatial Reference - No Conversion Necessary");
  Latitude = ArcadeY;
  Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
  Console("102100 Spatial Reference - Conversion Necessary");
  AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
  Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

var url = "https://www.bing.com/maps?&style=x&cp=" + text(Latitude) + "~" + text(Longitude);
return url;

 

Let's break down the expression. The first section grabs the X and Y coordinates and the spatial reference from the feature's Geometry and stores them as variables.  Since these features are Lines, we'll grab the Centroid of the line $feature as the location we zoom to in street view.

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

 

Then we'll check the spatial reference system of the web map to see if the coordinates need converting to Lat and Long for use by Google or Bing. If the web map is in Web Mercator (102100) then the coordinates will be converted to Lat and Long.  If the web map is in WGS84 (4326) then no conversion necessary since the feature coordinates will already be in Lat and Long. 

 

function AuxSphereToLatLon(x, y) {
  Console("Converting...");
  // Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
  var rMajor = 6378137;
  var shift = PI * rMajor;
  Longitude = x / shift * 180.0;
  Latitude = y / shift * 180.0;
  Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
  Console("4326 Spatial Reference - No Conversion Necessary");
  Latitude = ArcadeY;
  Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
  Console("102100 Spatial Reference - Conversion Necessary");
  AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
  Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

 

And finally, we'll build the URL and return it as a hyperlink.  For Google, use the following syntax:

var url = "http://maps.google.com/maps?q=&layer=c&cbll=" + text(Latitude) + "," + text(Longitude);
return url;

 

And for Bing, use the following syntax:

var url = "https://www.bing.com/maps?&style=x&cp=" + text(Latitude) + "~" + text(Longitude);
return url;

 

Once you have your Arcade expression built, the X and Y geometry of the feature will be added to the street view URL.

The URL will come through as a hyperlink in your web map pop-up.

 

 

Patrick Huls

Solution Engineer Team Lead - Telecommunications

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