Jørgen Elgaard Larsen's Diary
Recent diary entries
Today, I went on a car trip in an area where I knew that some roads needed surveying. But how could I find them easily in the real world?
I already use Navit for navigation, so I looked into what could be done with that. Quite a lot, it turned out.
In the following, all command examples are for the Linux commandline. Macs should have the same commands available. On windows, try running them in a Cygwin shell. For all three, you may have to install the commands “xsltproc” and “wget” from the relevant package repositores.
First of all, we need to get a list of all the places we want to survey.
That can be done using the XAPI.
Getting Relevant Data
In Denmark, we have imported all addresses from the official register. And we have tools to find addresses which do not have roads with the same name nearby. When we discover a row of adresses, and nothing is on the aerial photos (most of them are from 2005), we sometimes simply draw a way along the address nodes and tag it as highway=proposed, source=fantasy.
So let’s look for ways with tag source=fantasy:
wget -O fantasy.osm 'http://www.overpass-api.de/api/xapi?way[source=fantasy][bbox=11.56,54.86,12.57,55.32]'
This will find all ways with the source=fantasy in the southern Sjælland in Denmark and save them to the file “fantasy.osm”. You would want to change the coordinates to those for the area you is interested in. The sequence is left, bottom, right, top boundaries.
Similarly, this will find all ways that have a “fixme” tag at all:
wget -O fixme.osm 'http://www.overpass-api.de/api/xapi?way[fixme=*][bbox=11.56,54.86,12.57,55.32]'
Unfortunately, we do not have a tag that specificly says that someone needs to survey on site - yet. I think I will suggest fixme:survey for this.
Converting to POIs
When you have your .osm file, we need to convert it into a suitable POI file for Navit. Luckily, it is easy to convert XML files by using XSLT. I have created an XSLT file for this purpose: ways2poi.xsl. It will take the first node from every way in the .osm file and turn it into a POI. Use it like this:
xsltproc ways2poi.xsl fantasy.osm > user_poi.txt
If the ways2poi.xsl file is placed in another directory than the one where you are running the command, you will have to provide the full path. The same goes for fantasy.osm, of course.
It seems that navit ignores POI types it does not recognise, so for now, all the POI’s will be airports!!! I am looking into that. But it is usable enough for now.
Copy the user_poi.txt file to the SD card on your android, in the “navit” directory.
If you do not already have Navit on your Android, just install the latest development. Open a browser on your Android and enter the URL: http://download.navit-project.org/navit/android/svn/navit-current.apk
If it does not install automatically, you may need to go to Android’s settings under “Programs” and allow “Unknown Sources” - i.e. installing from other sites that Google Play.
When Navit is installed, press the Android menu button and choose “Download first map” to download map data for your area.
Unfortunately, Navit is not straightforward to configure on Android. But it should not be that bad if you follow these instructions:
Getting a configuration file
The biggest problem is to get a template navit configuration file.
You can download the one that I use: navit.xml. It has all the changes below, but note that it also changes the screen layout, so it may not be for you afterall.
If you want to get a fresh one to start with, you can just yse a standard unzip program on the navit APK file you used to install NAvit on your android. Copy the file res/raw/navithdpi.xml in the zip file and rename the copy to “navit.xml”. Note: The navithdpi.xml is for high resolution displays. If you have a low resolution (less than 800x480 / WVGA) display, use the -mdpi or -ldpi file to copy from instead.
Configure to use the POI file
Open the navit.xml file in your favourite text or XML editor (e.g. emacs, gedit, notepad, cat, vi, kate, nano).
Search for the word “mapset”. We want to find the one that has enables=”yes”. In a default installation, it is somewhere around line 630 and looks like this:
<mapset enabled="yes"> <map type="binfile" enabled="yes" data="/sdcard/navit/navitmap.bin"/> </mapset>
Add the line
<map type="textfile" enabled="yes" data="/sdcard/navit/user_poi.txt"/>
So it becomes
<mapset enabled="yes"> <map type="textfile" enabled="yes" data="/sdcard/navit/user_poi.txt"/> <map type="binfile" enabled="yes" data="/sdcard/navit/navitmap.bin"/> </mapset>
(The ordering is not important).
Of course, if you placed the user_poi.txt file another place on the SD card, you will have to change the path correspondingly.
Configure Navit To Record Your Trip
I also wanted Navit to record my trip. Of course, you could instead use another GPS device for recording, or just run OSM Tracker simultaneously with Navit.
But Navit can do it:
Open the navit.xml file in your editor. Find the <vehicle> tag that you want to record for. In a standard Navit installation on Android, just look around line 145 for
<vehicle name="Local GPS" profilename="car" enabled="yes" active="1" source="android:" follow="1">
Just after that line, insert:
<log enabled="yes" type="gpx" attr_types="position_time_iso8601,position_direction,position_radius,position_height,position_sats_used,position_hdop" data="/sdcard/navit/tracks/track_%Y%m%d-%%i.gpx" flush_size="1000" flush_time="30"/>
This tells Navit to create a log file in GPX format (suitable for JOSM or uploading to OSM), name it after the current date, and write to the SD card every 30 seconds, or every 1000 bytes, whichever comes first.
Remember to create the /navit/tracks directory on the SD card, or you will get no logging!!!
Also note that this will make Navit log all your trips, so you may get a lot of track data on your SD card.
Using The Configuration
Now copy the navit.xml file to the top directory of the SD card.
If you place it in a subdirectory, it will not be read!!!
On The Road
Whenever you are driving around, you can find the nearest sites to be surveyed: Simply touch the map in Navit, choose “POIs” and press the looking glass icon. Then search for “airport” (remember, the POIs were created as airports).
You will now see a list of sites to be surveyed, nearest first. Choose one and select “Set as destination”. Now, Navit will try to get you there - but beware, in areas in need of survey… the map may not be correct :-)
You will also notice that survey sites are shown on the map as small, blue aeroplanes!
This solution is good, but it can get better.
We need a special tag in OSM for things that needs survey on site, so that it becomes easier to make POI lists.
My XSLT should also handle nodes and even relations retrieved as searches via XAPI. For now it only does ways.
I need to get Navit to accept custom types of POIs. Of course, they are not visible until I create style information for them, but then I can set a unique symbol for it on the map.
I don’t know whether Navit supports it, but it would be nice to add a custom button to Navit that automatically searches for “survey needed” POIs. There are buttons for fuel, restaurants and parking, so why not custom POIs?
A really nice future feature in Navit would be the ability to search for any type of POI along your route. E.g. “Be on the lookout for ATMs along the route”, and then it would constantly show you the direction to the nearest ATM, and show how long a detour it would make. Perhaps an alarm when there is something really close. If such a feature existed in Navit, it could also be used for “survey needed” POIs.
Another wish for Navit would be the ability to choose any number of any POIs and then it would create the shortest route that covers all of them and still gets you to your destination. Classic Traveling Salesman. :-)
I found great help for this here:
Configuring Navit: http://wiki.navit-project.org/index.php/Configuring_Navit
Importing POIs in Navit: http://wiki.navit-project.org/index.php/Other_maps
MapQuest XAPI query builder: http://open.mapquestapi.com/xapi/
Overpass API XAPI reference: http://wiki.openstreetmap.org/wiki/Overpass_API#XAPI_Compatibility_Layer
My inspiration for messing with my Navit configuration: http://wiki.openstreetmap.org/wiki/Navit/Android