Difference between revisions of "Other maps"

From Navit's Wiki
Jump to: navigation, search
m (Convert CSV POIs to Navit format)
(Convert CSV POIs to Navit format)
Line 32: Line 32:
  
 
=Convert CSV POIs to Navit format=
 
=Convert CSV POIs to Navit format=
Many commercial Navigators use the CVS format for Point of Interest files. You can convert them to the navit txt format using a script like this:
+
Many commercial Navigators use the CVS format for Point of Interest files.
 +
 
 +
You can convert them to the navit txt format using a script like these:
 +
== Bash version ==
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
Line 82: Line 85:
  
 
echo "POI file saved in $poitxtfile"
 
echo "POI file saved in $poitxtfile"
 +
</pre>
 +
== Python Version ==
 +
Much more quick.
 +
<pre>
 +
#!/usr/bin/python
 +
# Convert CSV-POI files to Navit
 +
# Marco Trevisan (3v1n0) -- 2009
 +
 +
import os, sys, re
 +
 +
poi_type = ""
 +
 +
csvmatch = re.compile("([^,]+),([^,]+),([^,]+)\n")
 +
outlist = list()
 +
 +
for i in range(1, len(sys.argv)):
 +
currentfile = sys.argv[i]
 +
if (os.path.exists(currentfile)):
 +
csvfile = open(currentfile, 'r')
 +
print "Parsing "+currentfile+"..."
 +
filelen = len(csvfile.readlines())
 +
linen = 1
 +
csvfile.seek(0)
 +
for line in csvfile:
 +
cvsparts = re.match(csvmatch, line)
 +
if cvsparts:
 +
lon = cvsparts.group(1)
 +
lat = cvsparts.group(2)
 +
name = cvsparts.group(3)
 +
 +
poi_label = name
 +
poi_desc = ""
 +
 +
if not len(poi_type):
 +
poi_type = "poi_attraction"
 +
 +
outlist.append("type="+poi_type+" label=\""+poi_label+"\"" \
 +
" description=\""+poi_desc+"\" gc_type=\"\"\n")
 +
outlist.append(lon+" "+lat+"\n")
 +
 +
status = "\t"+os.path.basename(currentfile)+" ("+str(linen)+"/"+str(filelen)+")"
 +
print status,"\r",
 +
sys.stdout.flush()
 +
 +
linen = linen+1
 +
 +
if (len(outlist)):
 +
outfile = os.path.splitext(currentfile)[0]+".txt"
 +
print "\nWriting output at "+outfile+"..."
 +
gpxfile = open(outfile, 'w')
 +
gpxfile.writelines(outlist)
 +
gpxfile.close
 
</pre>
 
</pre>

Revision as of 21:30, 26 April 2009

POI as Navit Text maps

You can display Points of Interest as a Navit map. Therefore was built a utility called gpx2navit_txt which converts gpx files to navit text map-Files. It is possible to convert waypoints and tracks.

Insert the text map Files into the navit.xml like this:

        <mapset enabled="yes">
               <map type="textfile" enabled="yes" data="/home/andi/osm_maps/navit_poi.txt"/>
               <map type="binfile" enabled="yes" data="$NAVIT_SHAREDIR/maps/osm_bbox_11.3,47.9,11.7,48.2.bin"/>

and you will get the poi-data on the map.

That will look like this: POI

Troubleshooting

If nothing is displayed

* check the area of the map
* check if the items of the textfile are defined in your 'navit.xml'
* this is also true for tracks - here it might be that the track is hidden by other objects, check the 'navit.xml'
* check if the xpm-Files are defined and accessible

For example imagine:

* in the text-map you converted with 'gpx2navit_txt' is a type='poi_gc_multi' for a Multicache
* Then the navit symbol will be 'poi_gc_multi' and has to be defined in 'navit.xml' (see for 'example poi_airport')
* the xpm file (normally under '/usr/local/share/navit/xpm') 'gc_multi.xpm' must be present
* for track-display the type is 'track' and 'track' must be defined in 'navit.xml'

If tracks or routes from gpx are not converted

* error message 'no move recorded' --> use '-f' flag of gpx2navit_txt

Convert CSV POIs to Navit format

Many commercial Navigators use the CVS format for Point of Interest files.

You can convert them to the navit txt format using a script like these:

Bash version

#!/bin/bash
# Marco Trevisan (Treviño) -- Copyright 2009
# Released under the GPLv2 terms.

csvfile="$1"
poitxtfile="$PWD/$(basename "$csvfile" .csv).txt"
poi_type=""

if [ ! -f "$csvfile" ] || !(echo "$(head "$csvfile" -n1)" | grep -q "[^,]\+,[^,]\+,[^,]\+"); then
	echo "You must provide a valid csv file"
	exit 1
fi

rm -f "$poitxtfile"
echo "Parsing file $csvfile..."
filelen=$(wc -l "$csvfile"|cut -f1 -d' ')
linen=1

while read line; do
	lon=$(echo "$line" | cut -f1 -d',')
	lat=$(echo "$line" | cut -f2 -d',')
	name=$(echo "$line" | cut -f3 -d',')
	
	poi_label="$name"
	poi_desc="$name"
	
	if [ -z "$poi_type" ]; then
		poi_type="poi_attraction"
	fi
	
	echo "type=$poi_type label=\"$poi_label\" description=\"$poi_desc\" gc_type=\"\"" >> $poitxtfile
	echo "$lon $lat" >> $poitxtfile
			
	status="\t$csvfile ($linen/$filelen)"
	if [ $linen -gt 1 ]; then
		for ((k=0; $k < $(expr length "$status"); k++)); do
			echo -n -e "\b"
		done
	fi
	
	if [ $linen != $filelen ]; then
		echo -e -n "$status"
	fi

	linen=$(($linen+1))
done < "$csvfile"

echo "POI file saved in $poitxtfile"

Python Version

Much more quick.

#!/usr/bin/python
# Convert CSV-POI files to Navit
# Marco Trevisan (3v1n0) -- 2009

import os, sys, re

poi_type = ""

csvmatch = re.compile("([^,]+),([^,]+),([^,]+)\n")
outlist = list()

for i in range(1, len(sys.argv)):
	currentfile = sys.argv[i]
	if (os.path.exists(currentfile)):
		csvfile = open(currentfile, 'r')
		print "Parsing "+currentfile+"..."
		filelen = len(csvfile.readlines())
		linen = 1
		csvfile.seek(0)
		for line in csvfile:
			cvsparts = re.match(csvmatch, line)
			if cvsparts:
				lon = cvsparts.group(1)
				lat = cvsparts.group(2)
				name = cvsparts.group(3)
				
				poi_label = name
				poi_desc = ""
				
				if not len(poi_type):
					poi_type = "poi_attraction"
				
				outlist.append("type="+poi_type+" label=\""+poi_label+"\"" \
							" description=\""+poi_desc+"\" gc_type=\"\"\n")
				outlist.append(lon+" "+lat+"\n")
			
			status = "\t"+os.path.basename(currentfile)+" ("+str(linen)+"/"+str(filelen)+")"
			print status,"\r",
			sys.stdout.flush()
			
			linen = linen+1
	
		if (len(outlist)):
			outfile = os.path.splitext(currentfile)[0]+".txt"
			print "\nWriting output at "+outfile+"..."
			gpxfile = open(outfile, 'w')
			gpxfile.writelines(outlist)
			gpxfile.close