- Use Our Data
- Integrations
- ArcGIS
Power Outage Data in ArcGIS
To get power outage data into ArcGIS, run an ArcGIS Online notebook that calls the PowerOutage.us v2 REST API with your key from notebook secrets, writes the active outages as GeoJSON, and overwrites hosted feature layers from a notebook task every 15 minutes. Utilities report some outages as points and others as polygons, and a hosted feature layer holds one geometry type, so the notebook keeps two layers. Add them to any web map, dashboard or app and they stay current on their own. This guide covers the notebook, the one-time publish, the task, and running the same code from ArcGIS Pro.
What you'll have
- Two hosted feature layers, outage points and outage polygons, with customers out, cause and estimated restoration for every active outage in the states you choose.
- Layers that keep their item ids, URLs, symbology and pop-ups each time the data is replaced, so the web maps, dashboards and apps built on them keep working.
- An API key held in notebook secrets, never typed into a cell that anyone opening the notebook can read.
- A notebook task that refreshes both layers every 15 minutes on the Standard runtime, billed at 1.5 credits per hour of run time.
What you need
An API key (request one with the form below) and these endpoints. Full details are in the API reference.
| Endpoint | Method | Used for | Package |
|---|---|---|---|
/geojson/outages | GET | Every active outage as a GeoJSON feature, requested once with geometryType=point and once with geometryType=polygon so each file holds a single geometry type. | Standard |
Step 1: Check your privileges and store the key as a notebook secret
Your ArcGIS Online role needs the Create and edit notebooks and Schedule notebooks privileges, plus the privileges to create content and publish hosted feature layers. Only a layer's owner or an administrator can overwrite it, so the person who publishes the layers in step 3 should own the notebook and its task. Create a notebook on the Standard runtime, version 15.0 or later, which secrets require. Then open Secrets on the notebook ribbon, choose Register secret, and save your API key under the name poweroutage_api_key. The notebook reads it with get_secret from arcgis.notebook; if you share the notebook, the value does not go with it.
Step 2: Fetch the outages and write one GeoJSON file per geometry type
Paste this into the first cell. It requests /geojson/outages twice, once per geometry type, with the key in an Authorization: Bearer header, and waits the Retry-After seconds if the API answers 429. Each feature is rewritten with the same eight attributes: outageKey (utilityId and outageId joined with a colon), utilityId, outageId, customersOut, cause (Not reported when the utility gives none), estimatedRestorationAt, firstSeenAt, and generatedAt from the response's meta. Timestamps are ISO 8601 in UTC. minCustomersOut=1 leaves out outages reported without a customer count, so customersOut is always a number. The files go to /arcgis/home, the notebook's workspace.
import json
import time
import requests
from arcgis.features import FeatureLayerCollection
from arcgis.gis import GIS
from arcgis.notebook import get_secret
gis = GIS('home')
API_KEY = get_secret('poweroutage_api_key')
# 44 is Florida and 45 is Georgia. List ids with GET /outages/states.
STATE_IDS = '44,45'
# A hosted feature layer holds one geometry type, so each type gets its own file and layer.
FILES = {
'point': '/arcgis/home/outage_points.geojson',
'polygon': '/arcgis/home/outage_polygons.geojson',
}
def get_outages(geometry_type):
"""GET one geometry type of outages, waiting out a 429 for as long as Retry-After says."""
for attempt in range(3):
response = requests.get(
'https://poweroutage.us/api/v2/geojson/outages',
params={'stateId': STATE_IDS, 'geometryType': geometry_type, 'minCustomersOut': 1},
headers={'Authorization': f'Bearer {API_KEY}'},
timeout=60,
)
if response.status_code != 429:
response.raise_for_status()
return response.json()
if attempt < 2:
time.sleep(int(response.headers.get('Retry-After', '10')))
raise RuntimeError('Still rate limited after 3 tries')
def to_feature(feature, generated_at):
"""The same eight attributes on every feature, so the layer's fields never change."""
p = feature['properties']
return {
'type': 'Feature',
'geometry': feature['geometry'],
'properties': {
'outageKey': f"{p['utilityId']}:{p['outageId']}",
'utilityId': p['utilityId'],
'outageId': p['outageId'],
'customersOut': p['customersOut'],
'cause': p['cause'] or 'Not reported',
'estimatedRestorationAt': p['estimatedRestorationAt'],
'firstSeenAt': p['firstSeenAt'],
'generatedAt': generated_at,
},
}
counts = {}
for kind, path in FILES.items():
collection = get_outages(kind)
features = [to_feature(f, collection['meta']['generatedAt']) for f in collection['features']]
with open(path, 'w') as file:
json.dump({'type': 'FeatureCollection', 'features': features}, file)
counts[kind] = len(features)
print(counts) Step 3: Publish the two layers once
Run the cell and check the counts it prints. Open the Files pane, go to home, and download outage_points.geojson and outage_polygons.geojson. In Content, choose New item, then Your device, pick outage_points.geojson, choose to add it and create a hosted layer, and give it a title; repeat for the polygons file. ArcGIS reads each layer's fields from its file, so each file needs at least one feature now: if one came back empty, add states to STATE_IDS for this first run. Keep the file names, because an overwrite must use the same file name and format as the original. Open each new hosted feature layer and copy its item id, the value after id= in the item page URL.
Step 4: Overwrite the layers on every run
Add this as the second cell and paste in the two item ids. overwrite replaces every feature from the file but keeps the layer's URL, item id, symbology and pop-ups. It returns a dictionary instead of raising on failure, so the cell raises itself, which marks the task run as failed. When a geometry type has no outages, the cell empties that layer with truncate rather than leaving cleared outages on the map. Object IDs are reassigned on every overwrite; use outageKey to follow an outage from one run to the next.
# Item ids of the two hosted feature layers you published from the files above
LAYER_ITEMS = {
'point': '<POINTS_LAYER_ITEM_ID>',
'polygon': '<POLYGONS_LAYER_ITEM_ID>',
}
for kind, item_id in LAYER_ITEMS.items():
item = gis.content.get(item_id)
if counts[kind] == 0:
# A file with no features has nothing to overwrite from, so empty the layer instead.
item.layers[0].manager.truncate()
continue
result = FeatureLayerCollection.fromitem(item).manager.overwrite(FILES[kind])
# overwrite reports failure in its return value instead of raising
if not result.get('success'):
raise RuntimeError(f'Overwriting the {kind} layer failed: {result}')
print('Layers updated:', counts) Step 5: Schedule it as a notebook task
Save the notebook, then choose Tasks on the ribbon and Create task. Give it a title, skip parameters, and set it to repeat every 15 minutes, the most often ArcGIS Online allows. The data updates every minute, so the layer can be up to 15 minutes behind. Under Advanced, turn on Use workspace, since the notebook writes to /arcgis/home, and set a run-time limit of 10 minutes so a stuck run stops. Scheduled runs on the Standard runtime cost 1.5 credits per hour, calculated per minute: a run that takes two minutes every 15 minutes uses about 4.8 credits a day. Start times are approximate and can drift when the system is busy.
Step 6: Run the same code from ArcGIS Pro
ArcGIS Pro includes the ArcGIS API for Python, so both cells run there with three changes: connect with GIS('pro'), read the key from an environment variable because notebook secrets exist only in ArcGIS Notebooks, and write the files to a local folder under the same file names. Put the code in a Python script tool, then choose Schedule from the Run menu. Pro runs scheduled tools through Windows Task Scheduler, the machine must be signed in, and with a Named User license you need to check Sign in automatically when you sign in to ArcGIS Pro.
import os
from arcgis.gis import GIS
gis = GIS('pro') # the portal ArcGIS Pro is signed in to
# Notebook secrets exist only in ArcGIS Notebooks. Set this variable for the Windows user
# that runs the scheduled tool.
API_KEY = os.environ['POWEROUTAGE_API_KEY']
# Same file names as the files the layers were published from
FILES = {
'point': 'C:/poweroutage/outage_points.geojson',
'polygon': 'C:/poweroutage/outage_polygons.geojson',
} Tips for ArcGIS
- Map Viewer cannot load the API directly. Add layer from URL can append custom parameters to a GeoJSON URL but cannot send request headers, and the v2 API accepts the key only in the
Authorizationheader, so the request is refused. Add the hosted layers to your maps instead. - ArcGIS Velocity can poll the API itself with an HTTP Poller feed: set the GeoJSON URL, add a custom header named
Authorizationwith the valueBearerfollowed by your key, and pick GeoJSON as the format. Feeds poll every minute by default, so set the polling interval to 10 or 15 minutes, and filter bystateId, because a polled response cannot exceed 16 MB. Velocity is licensed separately, and Esri does not describe custom headers as encrypted, so use a key restricted to the areas the feed needs. - Each person can have up to 10 active notebook tasks, and an organization up to 50. Both layers update from one task.
- Overwrite needs the same fields on every run. The notebook writes the same eight attributes on every feature, so the files never gain or lose a column. If you add an attribute later, publish new layers rather than overwriting the old ones.
- Overwrite is not available while sync or data change tracking is turned on for a layer, so leave both off on these two layers.
- Both requests call
/geojson/outages, which covers only utilities that publish outage locations, so county totals from/outages/countiescan be higher than the sum of these layers.
Used by
Related integrations
FAQ
Here are some commonly asked questions
Request API access
Tell us what you're building and we'll set you up with a trial key.