I use Open Data Kit (ODK) to do field collection of points of interest. ODK outputs each collected point as an XML-file with a structure like so:

<?xml version='1.0' ?>
<data id="build_My_POI_Type_1234">
<NAME>Place name</NAME>
<KOORD>56.1234 13.1234 70.1234 7.1234</KOORD>

Is there a simple solution for reading this as a point feature in QGIS, or do I have to parse it via Python console or something?

  • wondered why you have 4 values for a point? Which are the coords? – Steven Kay Sep 22 '15 at 15:18
  • Not sure. I'm guessing elevation and circular error. [Edit: The first two are correct WGS84 coords though. I verified that.] – hexamon Sep 23 '15 at 7:07

They are many Python modules to parse XML files (PiPy:xml) but xml.etree.ElementTree is a standard module

With your example

from xml.etree import ElementTree as ET 
with open("testodk.xml") as odk:
   tree = ET.parse(odk)
coords = tree.find('KOORD')
print coords.text
56.1234 13.1234 70.1234 7.1234
name = tree.find('NAME')
print name.text
Place name

To extract the coordinates, you can use a regular expression

import re
coords =re.findall(r'\d+[\.|\s]*.\d+',coords.text)
coords = [float(c) for c in coords]
print coords
[56.123399999999997, 13.1234, 70.123400000000004, 7.1234000000000002]

You have the name and the coordinates so you can create a layer in the Python console (if you want to also extract the id and instance_id values look at the many tutorials on ElementTree)

Problem, why two coordinates for a point ( or two points ?)

  • Okay, thanks for this. I'm going to wait a bit before marking it as the answer though, just in case someone is sitting on a more GUI-based solution. As for the extra coordinates, I'm fairly certain they are elevation and circular error (the third number corresponds roughly to the elevation in the collection area). – hexamon Sep 23 '15 at 7:20
  • Although this solves the problem, it's not very user friendly. It would be great if QGIS could natively read ODK output at some point. Fingers crossed. In the end I used FME to convert the data. – hexamon Sep 25 '15 at 12:24

I realize you asked explicitly for ODK. Nevertheless, there are other similar options that work in QGIS. This video show QGIS editing with iOS or Android devices (and includes offline support) that will not require any complicated workflow to load/extract data.

QGIS Editing with iOS and Android https://youtu.be/El2-tXZBfKM

Disclaimer: I wrote portions of it.

  • 1
    This is cool, and good to know of! – hexamon Sep 25 '15 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.