Where are the Teams Now?! Building Walking with the Wounded Widgets Part 1

Retired
6th December 2013

In the first of three blog articles about our work supporting the Walking with the Wounded expedition to Antarctica, I will introduce the ‘Where are the teams now?’ widget.  The widget shows current and historic location information for the three teams on top of a custom basemap. This blog post will introduce the components that make up the widget and provide detail into the technology behind it.

 

Creating the Basemap

We put the basemap together in ArcGIS for Desktop. This allowed us to bring a number of data sources together including hillshade data from SCAR and world vector data from AcrGIS Online. The grid proved particularly challenging to create as we wanted it to be different depending on the scale. We overcame this problem by using the multiple ring buffer geoprocessing tool to create the grid. This allowed for accuracy, freedom of symbolisation and the ability to create scale-specific views. We then converted dynamically created labels to annotations, which gave us the freedom to move and display labels where required at different scales.

We created a tile cache of the completed basemap at fixed scales. To keep the size of the cache down, we chose different extents to be cached at different scales. This was stitched together at the end by creating an empty tile cache and copying relevant completed cache folders into this structure. We then exported the tile cache as a tile package and it was ready to be uploaded to ArcGIS Online! The process of uploading a tile package to ArcGIS Online is very simple – you simply add a new item and select the tile cache you wish to upload – that’s it! There’s a geoprocessing tool that will do the same thing if you’d prefer to publish from Desktop. You can keep track of the publishing progress of the cache on its item page.

A little known ArcGIS Online item property is ‘credits’, which lets you add text information that will be displayed in the bottom right of a web map when it uses the item as a basemap. We used this property to guarantee that wherever the widget was displayed, it would always contain the necessary acknowledgements.

Receiving and Publishing Locations

The teams are equipped with Iridium satellite phones that have been configured to send location update information to our servers at regular intervals. We wrote a number of Python scripts to handle and process this incoming data. The ArcPy site-package allows us to take the raw WGS84 longitude and latitude data, and re-project it into the same coordinate system as the basemap.

point = arcpy.Point(locationLongitude,locationLatitude)

pointGeometry = arcpy.PointGeometry(point, arcpy.SpatialReference(4326))

pointGeometry102020 = pointGeometry.projectAs(arcpy.SpatialReference(102020))

x = str(pointGeometry102020.lastPoint.X)

y = str(pointGeometry102020.lastPoint.Y)

We also developed some logic to automatically handle the incoming points and determine whether a team was walking or camping. We achieved this by buffering every point that comes in and then running a client-side spatial query to see whether the latest point falls within the buffer of the point that came before it.

lastPoint = arcpy.Point(lastPointX,lastPointY)

lastPointGeometry = arcpy.PointGeometry(lastPoint, arcpy.SpatialReference(102020))

bufferResult = lastPointGeometry.buffer(100) #Buffer amount is in meters

if pointGeometry102020.within(bufferResult):

infoType = 2 #Type for camping

else:

infoType = 1 #Type for walking

After processing the data, we are ready to publish it to our ArcGIS Online feature services. We have two feature services; one for all point information and one just for the latest point for each of the teams. The ArcGIS REST API allows you to add, update and delete features in services hosted on ArcGIS Online using HTTP requests. Authorization is token based, which is particularly important given the importance of the project. We make our updates by first requesting a token from ArcGIS Online using the json, urllib and urllib2 site-packages.

def getToken():

url = “https://www.arcgis.com/sharing/generateToken”

values = {‘username’ : USERNAME,

‘password’ : PASSWORD,

‘referer’ : ‘localhost’,

‘expiration’ : 60,

‘f’: ‘json’}

data = urllib.urlencode(values)

req = urllib2.Request(url=url,data=data)

response = urllib2.urlopen(req).read()

responseDict = json.loads(response)

token = responseDict.get(‘token’)

return token

We generate the token using an ‘Administrator’ ArcGIS Online account. This is important as we need to update feature services on our Portal that are non-editable and this is only possible using an admin account. Once we have the token, we package the data up as JSON and make the request to our feature service REST endpoints to add (historic points feature service) or update (latest point feature service) information.

def makeAgolRequest(url, json):

agolToken =getToken()

values = {‘features’: json,

‘token’ : agolToken,

‘f’: ‘json’}

data = urllib.urlencode(values)

req = urllib2.Request(url=url,data=data)

response = urllib2.urlopen(req).read()

return response

Displaying Locations

Once we had our system for pushing data to ArcGIS Online, it was time to build the front-end of the widget. We started by using the JavaScript API to bring in a web map containing our basemap with a scale bar. We then make requests using the REST API to get only the data we require from our feature services. This time, our requests are made using the JavaScript API as opposed to Python – so long as the programming language can handle HTTP requests, you can use it to work with the ArcGIS REST API! Once we have access to this information, we are able to add points to the map as well as populate the table in the top right of the widget. As the project progressed, we had to reactively amend the widget on a number of occasions – the JavaScript API allowed us to do this quickly and easily without neededing to change the underlying data. For more information on the JavaScript API visit the ArcGIS for Developers website. We will be going into more detail on working with the API in a future blog post about the ‘Would you be able to keep up with the teams?’ widget.

Wrap-Up

I hope you have enjoyed reading about how we put this widget together. It makes use of a number of technologies and products that are part of the ArcGIS Platform. I hope some of the information and code snippets may be of use and inspire you to build applications of your own! Keep an eye on the blog for the next instalment in our Walking with the Wounded widget series.

Retired