Skip to content

XForms OSM Upload Media Type

Nicholas Hallahan edited this page Feb 18, 2015 · 8 revisions

XForms OSM Upload Media Type for OpenDataKit

With minimal modification to JavaRosa, we have created a new upload media type called "osm" that will point to OSM XML files generated by OpenMapKit.

The changes to JavaRosa can be found here:

https://bitbucket.org/m.sundt/javarosa/branch/OpenStreetMap#diff

A compiled JavaRosa build with these changes available here:

https://www.dropbox.com/s/nl56ww2re904s61/javarosa-libraries-osm-2015-02-17.jar

OSM XForms XML Example

This is an example XForms Form XML that utilizes the OSM Upload Media Type:

<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
  <h:head>
    <h:title>ona_osm_tag4</h:title>
    <model>
      <instance>
        <data id="ona_osm_tag4">
          <meta>
            <instanceID/>
          </meta>
          <photo/>
          <osm_road/>
          <osm_building/>
          <fav_color>
            red
          </fav_color>
          <form_completed/>
        </data>
      </instance>
      <itext>
        <translation lang="eng">
          <text id="/data/photo:label">
            <value>Take a picture of something.</value>
          </text>
          <text id="/data/photo:hint">
            <value>We don't care what it is.</value>
          </text>
          <text id="/data/fav_color:label">
            <value>What is your favorite color?</value>
          </text>
          <text id="/data/fav_color:hint">
            <value>You must pick one of our choices.</value>
          </text>
          <text id="/data/osm_road:label">
            <value>Road</value>
          </text>
          <text id="/data/osm_road:hint">
            <value>Tag the road in front of the building.</value>
          </text>
          <text id="/data/osm_building:label">
            <value>Building</value>
          </text>
          <text id="/data/osm_building:hint">
            <value>Tag attributes about this building.</value>
          </text>
          <text id="/data/fav_color:option0">
            <value>red</value>
          </text>
          <text id="/data/fav_color:option1">
            <value>green</value>
          </text>
          <text id="/data/fav_color:option2">
            <value>blue</value>
          </text>
          <text id="/data/fav_color:option3">
            <value>The color of the sun.</value>
          </text>
        </translation>
      </itext>
      <bind nodeset="/data/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/>
      <bind nodeset="/data/photo" type="binary"/>
      <bind nodeset="/data/osm_road" type="binary"/>
      <bind nodeset="/data/osm_building" type="binary"/>
      <bind nodeset="/data/fav_color" type="select1"/>
      <bind nodeset="/data/form_completed" type="dateTime" jr:preload="timestamp" jr:preloadParams="end"/>
    </model>
  </h:head>
  <h:body>
    <upload ref="/data/photo" mediatype="image/*">
      <label ref="jr:itext('/data/photo:label')"/>
      <hint ref="jr:itext('/data/photo:hint')"/>
    </upload>
    <upload ref="/data/osm_road" mediatype="osm/*">
      <label ref="jr:itext('/data/osm_road:label')"/>
      <hint ref="jr:itext('/data/osm_road:hint')"/> 
      <tag key="highway">
        <label>highway</label>
      </tag>        
      <tag key="name">
        <label>Name</label>
      </tag>        
      <tag key="maxspeed">
        <label>maxspeed</label>
      </tag>        
      <tag key="maxspeed:winter">
        <label>maxspeed:winter</label>
      </tag>
    </upload>
    <upload ref="/data/osm_building" mediatype="osm/*">
      <label ref="jr:itext('/data/osm_building:label')"/>
      <hint ref="jr:itext('/data/osm_building:hint')"/>     
      <tag key="name">
        <label>Name</label>
      </tag>
      <tag key="name:fr">
        <label>Nom en Francais</label>
      </tag>
      <tag key="building_type">
        <label>Building Type</label>
        <item>
            <value>office</value>
            <label>ofisi</label>
        </item>
        <item>
            <value>church</value>
            <label>Kanisa</label>
        </item>
      </tag>
    </upload>
    <select1 ref="/data/fav_color">
      <label ref="jr:itext('/data/fav_color:label')"/>
      <hint ref="jr:itext('/data/fav_color:hint')"/>
      <item>
        <label ref="jr:itext('/data/fav_color:option0')"/>
        <value>red</value>
      </item>
      <item>
        <label ref="jr:itext('/data/fav_color:option1')"/>
        <value>green</value>
      </item>
      <item>
        <label ref="jr:itext('/data/fav_color:option2')"/>
        <value>blue</value>
      </item>
      <item>
        <label ref="jr:itext('/data/fav_color:option3')"/>
        <value>yellow</value>
      </item>
    </select1>
  </h:body>
</h:html>

Excel XLS survey Tab

The example XForms XML survey that you see above would have the following Excel tab data

list name name label hint
photo photo Photo of Building Preferably including Sign
osm osm_road osm_road Road Nearest Road to Building
osm osm_building osm_building Building Surveyed Building
select_one colors bdg_color Color of Building Most common color
end form_completed

Excel XLS osm Tab

We store the lists of OSM Tags in a separate osm tab in Excel, similar to what you find in the choice tab -- except this is exclusively for OpenStreetMap oriented data.

list name name label
osm_building name Name of Building
osm_building name:fr Nom en Francais
osm_building addr:housenumber House Number
osm_building addr:street Street Name
osm_building addr:city City
osm_building addr:postcode Zip Code
osm_building amenity:education
building yes Yes
building no No
amenity:education school School
amenity:education high school High School
amenity:education university University
amenity:health clinic Clinic
amenity:health hospital Hospital
osm_road name Name of Road
osm_road highway Highway Type
osm_road maxspeed Speed Limit
osm_road maxspeed:winter Winter Speed Limit

ODK Collect OSM Question

Below, you can see the first UI iteration of an OSM form question showing a launch button and a list of the required OSM tags: OSM Question