ArcGIS Online

Using Python to push updates to a hosted feature service from an external source

We all know the power of using feature services with ArcGIS.com to share our data and maps. These maps become even more powerful when the content automatically updates. GeoRSS feeds allow you to quickly pull content into your map. Well, what happens if you find an API or some geo-enabled information that doesn’t provide a GeoRSS feed but you want to get that information into your feature service? Python can act as the “glue” to combine the geo-information from the web into your hosted feature service.

Dave MacLean from the Centre of Geographic Sciences (COGS) has a webmap that captures tweets and photos from the astronauts on the International Space Station (ISS). Recently he worked with us (at Esri) to write a Python script that captures the ISS location from a website supplying the location as JSON and then pushes the relevant information into a hosted feature service. The current ISS location on his map allows viewers to prepare for an ISS sighting. ISS Webmap

Dave found a website that provides the real-time location of the ISS making the  information available in JSON, which the Python script parses. The script runs on an old laptop with a 60-second delay (You could investigate a cloud or other hosting solution to run your script if you can’t dedicate a computer to running it). With the script updating the feature service, he used the refresh layer method while building his web application to refresh the layer every minute.

You can download, fork or just explore the Python code we wrote to upload the ISS location from the github repo. Detailed instructions to setup and deploy the script are also provided. Here are some of the key points you should note about the script before modifying it to fit your workflows.

Once you have setup the script, you could run it from any computer that has Python 2.6+ installed (no ArcGIS desktop software required!).

The ISS position is just one example of a website that serves geo-enabled information. USGS earthquake reporting services provides useful information with geographic coordinates. Many other websites provide an API which may not include geographic coordinates, but you could use Python to combine this data with your own local data before pushing updates to your feature service. For example, data.gov provides an API and Python code examples for consuming it.

Next Article

Make This Dymaxion Globe Ornament Please

Read this article