Corso Systems

View Original

Importing Geolocation Data Into Ignition

During Corso Systems’ Ignition Community Live webinar, “Ignition Around the World” we received some interesting questions from the audience. Specifically, how to import non-mobile device geolocation data into Ignition. Examples of this type of data includes KML files from Google Maps or other GIS applications, or GPX files from GPS devices like a Garmin.

We have imported plenty of data from these formats for various projects, and as part of the Community piece of Ignition Community Live, have added the code and process for importing this data. Your exact file formats might be different than our examples, however this code is easy to modify to handle any format you may need to use.

Our example in this article assumes that we will be sending the data to Tags in Ignition and storing the data with timestamps. If you are importing data without timestamps or for some other purpose than historical storage, you will need to make some adjustments to the code to handle the data for your particular use case.

GPS Exchange (GPX)

The first file we discuss is a GPS Exchange or GPX file. This is file in XML format that describes GPS data. It can contain information on waypoints, routes, or individual tracking points. In our case we will import a file made up of a series of tracks and segments, each of which contains specific points. This will allow us to draw a line in Ignition to track the journey from Bakersfield to DC on an Amtrak train. The data in question came from a Garmin GPS unit we used during the trip.

These files are available in raw format in our Github repository.

Let’s first take a look at the explore.gpx file:

Screenshot of the code in explore.gpx, to view on github, please click the image

Here you can see the XML structure of the file, with an overall <gpx> element at the top, followed by <trk> elements defining each route during the trip, with segments and points below that. This file provides an overall view of the trip as a whole, including coordinates and timestamps. Next, we will import this file into Ignition with the following script:

Screenshot of tagImportFromGPX.py, please click image to view the code in github

In this file, we are importing the explore.gpx file above. The script performs basic XML parsing, and dives into the various elements in the file to drill down to the coordinate data and timestamp data.

You can easily run this script in the Script Console in the Ignition Designer, either passing in the file path if you know it, or use the openFile() function if you don’t. You will need to update your tag paths, tag provider and history provider to match your system’s configuration, and then you will be able to import the data into your historian using this script.

Updated - 12/9/2022