Difference between revisions of "User:Korrosa"

From Navit's Wiki
Jump to: navigation, search
(Removed table.)
(Android development environment)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{Userboxtop|}}
 +
{{User irc|korrosa}}
 +
{{User trac|korrosa}}
 +
{{user gb}}
 +
{{user en}}
 +
{{user nl}}
 +
{{user fr-1}}
 +
{{programming php}}
 +
{{programming javascript}}
 +
{{os linux}}
 +
{{os windows}}
 +
{{Userboxbottom|}}
 +
 +
=UK Postcode search with Navit=
 +
Using an external file containing full postcode centroids in lat/lon, a script can be used to pass the relevant postcode to Navit via dbus. This method was developed on Ubuntu (Linux). Postcodes do not include NI.
 +
 +
==Quickstart==
 +
# [[Dbus#Enabling | Enable dbus in navit.xml]]
 +
# Download the script and postcode file from: http://www.tiiiim.com/navit/p2n.tar.bz2 (23MB)
 +
# In the script, change the path to the postcode file. Set the executable bit of the script, then call the script with the postcode as arguments:
 +
 +
./p2n BA2 4HJ
 +
 +
If the postcode is valid, choose from the option to centre the map to the postcode, route to the postcode or set the postcode as your position.
 +
 +
==More Info==
 +
 +
===The script===
 +
The script is written in php, and requires <tt>php5-cli</tt> to be installed on your system.
 +
sudo apt-get install php5-cli
 +
 +
The script is shown below:
 +
{| width="100%" class="collapsible collapsed wikitable"
 +
|-
 +
! Postcode script (PHP)
 +
|-
 +
|
 +
<pre>
 +
#! /usr/bin/php5
 +
 +
<?php
 +
 +
$csvfilename="/home/netbook/.navit/maps/pc_lat_lon_gb.csv";
 +
 +
if($argc>=2){
 +
 +
// Add arguments to array
 +
$arr_postcode = $argv;
 +
// Remove name of script from array
 +
array_shift($arr_postcode);
 +
// Extract clean postcode from array
 +
$postcode = parse_postcode($arr_postcode);
 +
 +
echo "Searching for ". $postcode ." ... ";
 +
 +
if(!$file_handle = open_file($csvfilename)){
 +
exit("Error opening file. Check file is valid.\n");
 +
}
 +
 +
// Try searching for the postcode using divide and conquer algorithm
 +
if($array_postcode = pc2coord($postcode,$file_handle)){
 +
// DEBUG
 +
#print_r($array_postcode);
 +
}
 +
else{
 +
// Get first letter of the postcode
 +
$postcode_id = substr($postcode,0,1);
 +
// DEBUG
 +
#echo $postcode_id."\n";
 +
 +
// Set pointer to start of postcode letter
 +
$array_postcode = pc2coord($postcode_id,$file_handle);
 +
// DEBUG
 +
#print_r($array_postcode);
 +
 +
// Slowly go through the file to find the postcode
 +
$array_postcode = pc2coord_slow($postcode,$file_handle,$array_postcode[3]);
 +
// DEBUG
 +
#print_r($array_postcode);
 +
}
 +
 +
close_file($file_handle);
 +
 +
if($array_postcode){
 +
echo "Found  ".$array_postcode[0]. ": " .$array_postcode[1]." ".$array_postcode[2]."\n";
 +
 +
$keyboard = fopen("php://stdin","r");
 +
 +
echo "[R]oute to postcode, [v]iew postcode or set as [p]osition\n";
 +
 +
$answer = strtoupper(fgets($keyboard,2));
 +
 +
if($answer=="R"){
 +
echo "Routing to postcode.\n";
 +
navit_dbus("navit","set_destination","string:\"geo: ".$array_postcode[2]." ".$array_postcode[1]."\" string:\"Post Code Point\"");
 +
navit_dbus("navit","draw");
 +
}
 +
elseif($answer=="V"){
 +
echo "Centering map.\n";
 +
navit_dbus("navit","set_center_by_string","string:\"geo: ".$array_postcode[2]." ".$array_postcode[1]."\"");
 +
navit_dbus("navit","draw");
 +
}
 +
elseif($answer=="P"){
 +
echo "Setting as position.\n";
 +
navit_dbus("navit","set_position","string:\"geo: ".$array_postcode[2]." ".$array_postcode[1]."\"");
 +
navit_dbus("navit","draw");
 +
}
 +
else{
 +
echo "No choice made. Exit\n";
 +
}
 +
}
 +
else{
 +
echo "Postcode not found. Please try again.\n";
 +
}
 +
 +
}
 +
else{
 +
echo "No postcode specified. Please try again.\n";
 +
}
 +
 +
function open_file($filename){
 +
// Open file for reading and return handle
 +
return fopen($filename,"r");
 +
}
 +
 +
function close_file($file_handle){
 +
return fclose($file_handle);
 +
}
 +
 +
function parse_postcode($arr_postcode){
 +
# Clean up postcode formatting
 +
if(count($arr_postcode)>1){
 +
# There is more than one string in the postcode
 +
if(strlen($arr_postcode[0])<=3){
 +
# Postcode format entered is "B29 5AU"
 +
$postcode = strtoupper($arr_postcode[0]. " " . $arr_postcode[1]);
 +
}
 +
else{
 +
# Postcode format entered is "BN15 9RJ"
 +
$postcode = strtoupper($arr_postcode[0]. "" . $arr_postcode[1]);
 +
}
 +
}
 +
else{
 +
# Postcode is made up of only one string
 +
if(strlen($arr_postcode[0])<=6){
 +
# Postcode format entered is "B299RJ"
 +
$postcode = str_split($arr_postcode[0],3);
 +
$postcode = strtoupper($postcode[0] . " " . $postcode[1]);
 +
}
 +
else{
 +
# Postcode format entered is "BN159RJ"
 +
$postcode = strtoupper($arr_postcode[0]);
 +
}
 +
}
 +
 +
return $postcode;
 +
}
 +
 +
function navit_dbus($path,$method,$arguments=""){
 +
// Executes a dbus command, with the specified parameters.
 +
// Returns the dbus return as a string
 +
return shell_exec("dbus-send  --print-reply --session --dest=org.navit_project.navit /org/navit_project/navit/default_navit org.navit_project.navit.".$path.".".$method." ".$arguments);
 +
}
 +
 +
function pc2coord($postcode,$csvfilehandle){
 +
 +
$low=0;
 +
$found = false;
 +
 +
fseek($csvfilehandle,0,SEEK_END);
 +
$high=ftell($csvfilehandle);
 +
 +
while($low<=$high){
 +
// Move to mid point between low and high
 +
$mid=floor(($low+$high)/2);
 +
fseek($csvfilehandle, $mid);
 +
 +
// Moves to end of line
 +
$line=fgets($csvfilehandle); // Is this actually doing anything of value?
 +
 +
// Turn line into an array.
 +
$array_postcode_data=fgetcsv($csvfilehandle, 100, ",");
 +
 +
// Extract the postcode
 +
$csv_postcode = $array_postcode_data[0];
 +
#echo $csv_postcode;
 +
 +
// Compare postcodes
 +
$compare = strncasecmp($array_postcode_data[0],$postcode,7);
 +
 +
if(!$compare){
 +
#echo " Found it!\n";
 +
#echo $array_postcode_data[1].",".$array_postcode_data[2]."\n";
 +
$low=999999999;
 +
$found=true;
 +
//break;
 +
}
 +
elseif($compare<0){
 +
$low=$mid+1;
 +
#echo " Move up"."\n";
 +
}
 +
elseif($compare>0){
 +
$high=$mid-1;
 +
#echo " Move down"."\n";
 +
}
 +
else{
 +
echo "Something's gone wrong.\n";
 +
$low=999999999;
 +
}
 +
}
 +
 +
$array_postcode_data[] = $mid;
 +
 +
unset($line);
 +
if($found)
 +
return $array_postcode_data;
 +
else
 +
return false;
 +
}
 +
 +
function pc2coord_slow($postcode,$csvfilehandle,$line){
 +
$found = false;
 +
$postcode_id = substr($postcode,0,1);
 +
 +
fseek($csvfilehandle, $line-1);
 +
 +
while (!feof($csvfilehandle)) {
 +
 +
$array_postcode_data = fgetcsv($csvfilehandle, 44, ",");
 +
 +
#echo $array_postcode_data[0]." --> ".$postcode."\n";
 +
 +
if(trim($array_postcode_data[0]) == trim($postcode)){
 +
$found=true;
 +
break;
 +
}
 +
 +
// Stop checking if the postcode id becomes different
 +
if(substr($array_postcode_data[0],0,1)!=$postcode_id){
 +
break;
 +
}
 +
}
 +
 +
if($found)
 +
return $array_postcode_data;
 +
else
 +
return false;
 +
}
 +
 +
?>
 +
</pre>
 +
|}
 +
 +
===The postcode file===
 +
The postcode data comes from Ordnance Survey CodePoint Open data: https://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/index.html. The original data uses OSGB Northing and Easting to define the postcode centroids, but the data can be processed into a csv file with lat/lon coordinates using the method found here: http://baroque.posterous.com/uk-postcode-latitudelongitude. The result of this method is what's included in the download at http://www.tiiiim.com/navit/p2n.tar.bz2.
 +
 
=OSM Layout=
 
=OSM Layout=
 
[http://wiki.navit-project.org/index.php/Layouts/mapnik Mapnik-style rendering]
 
[http://wiki.navit-project.org/index.php/Layouts/mapnik Mapnik-style rendering]
Line 109: Line 365:
 
[[User:Korrosa/OpenStreetMap]]
 
[[User:Korrosa/OpenStreetMap]]
  
=Wiki Index=
 
''Attempting to create a sorted/obvious wiki index, or wiki map''
 
  
[[User:Korrosa/Index]]
+
 
 +
=Notable Tickets=
 +
* sort items by distance in the adress search dialog {{trac|35}}
 +
* It'd be nice to have several waypoints, not only a destination {{trac|46}}
 +
* do not announce when following a curved way/road {{trac|171}}
 +
* Incorrect ETA and TR - new method required? {{trac|417}}
 +
* Change Default Menu that Appears {{trac|560}}
 +
 
 +
=Configuring Navit=
 +
''Complete re-style of conifguration page''
 +
 
 +
[[User:Korrosa/Configuring Navit]]
 +
 
 +
=Android development environment=
 +
Setting up an environment in which you can compile your own Android versions of Navit
 +
==Pre-requisites ==
 +
Ensure that a java jdk is installed. On Ubuntu:
 +
sudo apt-get install openjdk-6-jdk
 +
Ensure that '''ant''' is installed. On Ubuntu:
 +
sudo apt-get install ant1.8
 +
 
 +
==Android development files==
 +
* Download Android SDK
 +
wget http://dl.google.com/android/android-sdk_r16-linux.tgz
 +
* Unzip to a directory of your choice. We shall use '''~/src'''
 +
* Move to the SDK directory, and initiate the download of the Android API's
 +
cd ~/src/android-sdk-linux
 +
tools/android update sdk --no-ui
 +
* Download Android NDK
 +
wget http://dl.google.com/android/ndk/android-ndk-r6b-linux-x86.tar.bz2
 +
* Unzip to a directory of your choice. We shall use '''~/src'''
 +
 
 +
==Download Navit source==
 +
* Get the latest Navit from svn
 +
cd ~/src
 +
svn co https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit navit-svn
 +
 
 +
==Setup your environment==
 +
* Manually create a build directory
 +
cd ~/src
 +
mkdir android-build
 +
* Step into the build directory
 +
cd ~/src/android-build
 +
* Configure environment variables
 +
export ANDROID_NDK=~/src/android-ndk-r6b \
 +
export ANDROID_SDK=~/src/android-sdk-linux \
 +
export PATH=$PATH:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$ANDROID_SDK/tools \
 +
SOURCE_PATH=~/src/navit-svn
 +
 
 +
 
 +
==Building==
 +
* Ensure that you're in the build directory created in the previous step, then run '''cmake'''
 +
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" -DANDROID_API_VERSION=8 $SOURCE_PATH
 +
* Then make the package
 +
make && make apkg
 +
 
 +
==Install Navit==
 +
* The new Navit package is called ''navit-debug'' and can be found in:
 +
~/src/android-build/navit/android/bin
 +
** Copy navit/android/bin/Navit-debug.apk to your device (i.e. sd-card) and run it from there or
 +
** If debug bridge (adb) is enabled run adb install navit/android/bin/Navit-debug.apk

Latest revision as of 14:25, 1 March 2012

IRC Korrosa appears on irc with the nick korrosa.
Trac Korrosa appears on trac with the nick korrosa.
en This user is a native speaker of English.


nl Deze gebruiker heeft Nederlands als moedertaal.


fr-1 Cet utilisateur peut contribuer avec un niveau élémentaire de français.


PHP This user programs in PHP
Javascript This user programs in Javascript
Linux This user uses Linux
Windows This user uses Windows


UK Postcode search with Navit[edit]

Using an external file containing full postcode centroids in lat/lon, a script can be used to pass the relevant postcode to Navit via dbus. This method was developed on Ubuntu (Linux). Postcodes do not include NI.

Quickstart[edit]

  1. Enable dbus in navit.xml
  2. Download the script and postcode file from: http://www.tiiiim.com/navit/p2n.tar.bz2 (23MB)
  3. In the script, change the path to the postcode file. Set the executable bit of the script, then call the script with the postcode as arguments:
./p2n BA2 4HJ

If the postcode is valid, choose from the option to centre the map to the postcode, route to the postcode or set the postcode as your position.

More Info[edit]

The script[edit]

The script is written in php, and requires php5-cli to be installed on your system.

sudo apt-get install php5-cli

The script is shown below:

The postcode file[edit]

The postcode data comes from Ordnance Survey CodePoint Open data: https://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/index.html. The original data uses OSGB Northing and Easting to define the postcode centroids, but the data can be processed into a csv file with lat/lon coordinates using the method found here: http://baroque.posterous.com/uk-postcode-latitudelongitude. The result of this method is what's included in the download at http://www.tiiiim.com/navit/p2n.tar.bz2.

OSM Layout[edit]

Mapnik-style rendering

OSD: Speed Camera[edit]

Currently a patch at #702.

  • Provides visual and audible warnings of approaching speed cameras.
  • Uses speed camera data from an external file in IGO8 format: files available from http://speedcamerapoi.com/download.php. Example IGO8 format shown below:
X,Y,TYPE,SPEED,DIRTYPE,DIRECTION
13.74132,51.04641,2,50,0,0
8.34681,49.62934,2,50,0,0
12.11390,49.02778,3,0,0,0
8.83805,53.08262,3,0,0,0
9.14767,47.68987,3,0,0,0
6.94611,51.12167,1,30,0,0
7.82556,51.46417,1,70,0,0
14.17350,51.12366,5,50,0,0
13.89502,52.25109,5,100,0,0
  • Plans to also use speed camera data in OSM

Use[edit]

To use the speed_cam OSD type, the following OSD item must be added to navit.xml. This of course assumes that you have patched navit with the patch at #702:

    <osd enabled="yes" type="speed_cam" w="500" h="40"  x="30" y="350" font_size="450" text_color="#FF0000" announce_on="0" label=" ${distance} | ${camera_type} | ${camera_dir} | ${direction} | ${speed_limit}" path="speed_cam_data.txt" />

Configuration[edit]

Most parts are self explanatory:

  • announce_on is set by default to 1 (i.e. this osd item will announce upcoming cameras with a "Look out! Camera!" warning) if this attribute is not set.
  • label can display the following variables. The values in ${STRING} are replaced with the appropriate number or word when running Navit:
    • distance to the camera - ${distance}
    • type of camera - ${camera_type}. See User:Korrosa#Camera Types for possible types:
    • direction in which the camera operates - ${camera_dir}
      • all
      • single direction
      • both directions
    • direction which the camera is facing, in degrees (0-360, i.e. north, east, south, west etc) - ${direction}
    • the active speed limit which the camera may be enforcing - ${speed_limit}

Data Sources[edit]

Currently, the speed_cam OSD looks in the following locations for speed camera data, in the following order. Note that the speed_cam OSD will only use the first data source:

  • IGO8 file defined by the path= attribute in the <osd /> tag
  • speedcam.txt IGO8 file in your default navit directory (usually ~/.navit)
  • Speed camera bin mapfile (see User:Korrosa#Creating camera bin mapfiles) defined in the currently active mapset.

Note that if you use one of the first two options, the cameras will not actually appear on the map, but will still be announced. Only by using a binfile will the cameras appear on the map.

Creating camera bin mapfiles[edit]

The following steps will enable you to convert an IGO8 speed camera textfile into a Navit bin mapfile. The advantage is reduced resource usage when using a binfile, and that the cameras will appear on the map.

  • Using igo2navittext.pl, convert the IGO8 file into a standard navit textfile. The script reads its input on standard input and outputs navit textfile on stdout. Use in the following manner:
    perl igo2navittext.pl  < speedcam.txt  > speedcam_navit.txt
  • Copy the resulting speedcam_navit.txt to the /navit/maps folder in the source tree.
  • Issue the following command in the maps folder:
    make speedcam_navit.bin
  • Add the just-created speedcam_navit.bin to your active mapset in navit.xml. For example, having moved the binfile to ~/navit/maps:
    <map type="binfile" enabled="yes" data="~/.navit/maps/speedcam_navit.bin"/>

Next time you start Navit the cameras should appear on the map. If they don't try changing the zoom settings of the tec_common item type in your map layout in navit.xml.

Camera Types[edit]

  • None
  • Fix
    • Type: Fixed speed enforcement camera
    • Enforces: Speed
    • Description: Probably the most common type of traffic enforcement camera. Usually located on the side of the road, and uses radar to detect vehicle speed. Can take photos from either the front or the rear. Front facing cameras tend to use IR flash guns, instead of traditional bulb flashes, to ensure that the driver does not get blinded.
    • Suggested English name: Fixed.
  • Traffic lamp
    • Type: Traffic light enforcement camera
    • Enforces: Speed and/or red light (unsure)
    • Description: These cameras seem to be located inside (?) traffic lights. It is unknown whether these are for speed, red light or both.
    • Suggested English name: Traffic light.
  • Red detect
    • Type: Red light enforcement camera
    • Enforces: Red light
    • Description: Located close to traffic light controlled junctions, these cameras will detect if a car has run a red light. Usually, these cameras will face down the flow of traffic, thus take a picture from the rear.
    • Suggested English name: Red light.
  • Section
    • Type: Average speed check camera
    • Enforces: Speed
    • Description: In the UK at least, these cameras are used a lot on motorway roadwork sections. CCTV ANPR cameras are located at strategic locations along the works, and take average speed readings of vehicles by reading their number plates. Nightime use is facilitated through the use of IR lamps.
    • Suggested English name: Avg speed
  • Mobile
    • Type: Mobile speed enforcement camera
    • Enforces: Speed
    • Description: There are many types of mobile cameras: common ones are hand-held cameras, either held by an officer from the police car window, or mounted on a tripod. Other types include those mounted on the police car dashboard or rear parcel shelf, or those which point through windows of special speed camera vans (common in the UK)
    • Suggested English name: Mobile
  • Rail
    • Type: Railway level crossing enforcement camera
    • Enforces: barriers/access
    • Description: Used at railway level crossings, to enforce any barriers or warning lights. It's usually an offence to enter the level crossing once you've been warned not to (however far away the train is), hence the cameras.
    • Suggested English name: Level crossing
  • Traffipax(non persistent)
    • Type: Mobile speed enforcement camera
    • Enforces: Speed (?)
    • Description: Note: this is conjecture at the moment. This seems to be a specific type of mobile speed camera.
    • Suggested English name: Mobile

Configuration[edit]

  • Tags shown in order of appearance in the navit.xml shipped with Navit.
  • Bold values denote default values if attributes are not explicitly specified.
  • Value types:
    • int = integer
    • bool = boolean 1 or 0
    • dbl = double

OpenStreetMap[edit]

Drafting complete re-write of the OpenStreetMap page

User:Korrosa/OpenStreetMap


Notable Tickets[edit]

  • sort items by distance in the adress search dialog #35
  • It'd be nice to have several waypoints, not only a destination #46
  • do not announce when following a curved way/road #171
  • Incorrect ETA and TR - new method required? #417
  • Change Default Menu that Appears #560

Configuring Navit[edit]

Complete re-style of conifguration page

User:Korrosa/Configuring Navit

Android development environment[edit]

Setting up an environment in which you can compile your own Android versions of Navit

Pre-requisites[edit]

Ensure that a java jdk is installed. On Ubuntu:

sudo apt-get install openjdk-6-jdk

Ensure that ant is installed. On Ubuntu:

sudo apt-get install ant1.8

Android development files[edit]

  • Download Android SDK
wget http://dl.google.com/android/android-sdk_r16-linux.tgz
  • Unzip to a directory of your choice. We shall use ~/src
  • Move to the SDK directory, and initiate the download of the Android API's
cd ~/src/android-sdk-linux
tools/android update sdk --no-ui
  • Download Android NDK
wget http://dl.google.com/android/ndk/android-ndk-r6b-linux-x86.tar.bz2
  • Unzip to a directory of your choice. We shall use ~/src

Download Navit source[edit]

  • Get the latest Navit from svn
cd ~/src
svn co https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit navit-svn

Setup your environment[edit]

  • Manually create a build directory
cd ~/src
mkdir android-build
  • Step into the build directory
cd ~/src/android-build
  • Configure environment variables
export ANDROID_NDK=~/src/android-ndk-r6b \
export ANDROID_SDK=~/src/android-sdk-linux \
export PATH=$PATH:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$ANDROID_SDK/tools \
SOURCE_PATH=~/src/navit-svn


Building[edit]

  • Ensure that you're in the build directory created in the previous step, then run cmake
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" -DANDROID_API_VERSION=8 $SOURCE_PATH
  • Then make the package
make && make apkg

Install Navit[edit]

  • The new Navit package is called navit-debug and can be found in:
~/src/android-build/navit/android/bin
    • Copy navit/android/bin/Navit-debug.apk to your device (i.e. sd-card) and run it from there or
    • If debug bridge (adb) is enabled run adb install navit/android/bin/Navit-debug.apk