OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>

Join the forum, it's quick and easy

OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>
OruxMaps
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Automatically calculating custom waypoints (left/right) for route

3 posters

Go down

Automatically calculating custom waypoints (left/right) for route Empty Automatically calculating custom waypoints (left/right) for route

Post  RandyBobandy Sun Jun 16, 2013 12:26 pm

Hi,

I stumbled upon this post:
https://oruxmaps.forumotion.com/t2652-maybe-egg-of-columbus-navigation-by-voice-with-minimal-change-in-app

OziExplorerCE works out the turn angle and direction itself and selects the appropriate symbol (.bmp) and sound file to play (.wav).

So I was wondering how effective that would be and thought I'd try it out since Oruxmaps supports custom waypoints with turn directions. I hacked together a perl script to read a gpx track file, calculate the angles and spit out a gpx waypoint file that you can load into orux.

It seems to work OK but I make no guarantees.

To try it out copy the code below and paste it into:
http://www.compileonline.com/execute_perl_online.php

Then paste the contents of your track file into the input.txt thing on that site and run the script.

Finally, click "download files" at the top right. Your waypoint.gpx file will be inside the tar.gz (you have unzip and then untar it. use 7zip in windows).

Here is a screenshot of a generated waypoint file and corresponding route file in oruxmaps:
Automatically calculating custom waypoints (left/right) for route Kyv6f

UPDATE: Now detects distance between two points on route. If distance < 1m the point will be ignored. This avoids false positive turn detection in some cases.



Here is the code:
Code:
use constant PI => 4 * atan2(1, 1);
use Math::Trig qw(deg2rad pi great_circle_distance asin acos);

$turndetect = 60; # Min angle difference from straight line for turn
$mindist = 1; # Min distance between waypoints


open INF, "input.txt" or die $!;
@data =  <INF>;
close INF;

foreach $row (@data){
 if ($row =~ /lat="(.*?)"/i)
 {
 $track[$j]=$row;
 $j++;
 }
}

#print @track; die;

open OUTF, ">waypoints.gpx" or die $!;

header();

for ($i;$i<$j;$i++){
 $track[$i]   =~ /lat="(.*?)".*?lon="(.*?)"/i; $lat1 = $1; $lon1 = $2;
 $track[$i+1] =~ /lat="(.*?)".*?lon="(.*?)"/i; $lat2 = $1; $lon2 = $2;
 #print "$lat1 $lon1 $lat2 $lon2\n";
 $dist = distance ($lat1, $lon1, $lat2, $lon2);
 if ($dist < 1){print "$i $lat1 $lon1 $lat2 $lon2 $dist <<< LESS THAN $mindist"."m DISTANCE, SKIPPING >>>\n"; next}
 if ($lat1 ne ""){
 $x = $lat2 - $lat1;
 $y = $lon2 - $lon1;
 $dir[$k] = angle($x,$y);
 $diff = $dir[$k] - $dir[$k-1];
 if ($diff < 0) {$diff = 360 - ($diff * -1)}
 if ($diff < 180) {$turndir = "links"; $diff = $diff}
 if ($diff > 180) {$turndir = "rechts"; $diff = 360 - $diff}
 print "$i $lat1 $lon1 $lat2 $lon2 $dist"."m"." $turndir";
 if ($diff > $turndetect){
 print " <<< $diff >>>\n";
 $wpcount++;
 print OUTF"<wpt lat=\"$lat1\" lon=\"$lon1\">\n";
 print OUTF"<ele>0.00</ele>\n";
 print OUTF"<time>2013-06-15T11:48:37Z</time>\n";
 print OUTF"<name><![CDATA[WP$wpcount]]></name>\n";
 print OUTF"<desc><![CDATA[]]></desc>\n";
 print OUTF"<sym>Waypoint</sym>\n";
 print OUTF"<type>Folgen, $turndir abbiegen</type>\n";
 print OUTF"</wpt>\n";
 } else {print" $diff\n"}
 $k++;
 }
}
print "\nWAYPOINTS: $wpcount\n";

print OUTF "</gpx>";

close OUTF;

sub angle{
 $tan = atan2($x,$y);
 if ($tan < 0) {$tan += 2 * PI}
 $tan = $tan * 180 / PI;
}

sub header{
 print OUTF <<ENDHEADER;
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="OruxMaps" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name><![CDATA[Waypoints]]></name>
<desc><![CDATA[]]></desc>
<link href="http://www.oruxmaps.com">
<text>OruxMaps</text>
</link>
<time>2013-06-15T12:01:23Z</time><bounds maxlat="0.0" maxlon="0.0" minlat="0.0" minlon="0.0"/>
</metadata>
ENDHEADER
}

sub distance{
#$lat1 = $_[0]; $long = $_[1]);
#$lat2 = $_[2]; $long2 = $_[3]);

my $rr=3956;

  my $dist = acos(sin(deg2rad($_[0]))*
                sin(deg2rad($_[2]))+
                cos(deg2rad($_[0]))*
                cos(deg2rad($_[2]))*
                cos(deg2rad($_[3])- deg2rad($_[1])))
               * $rr;
  return $dist*1.6093*1000;
}


Last edited by orux on Wed Jun 19, 2013 6:19 pm; edited 5 times in total (Reason for editing : corrected an error in the code that made the output invisible)

RandyBobandy

Cantidad de envíos : 7
Fecha de inscripción : 2012-01-21

Back to top Go down

Automatically calculating custom waypoints (left/right) for route Empty Re: Automatically calculating custom waypoints (left/right) for route

Post  orux Wed Jun 19, 2013 6:21 pm

RandyBobandy wrote:Hi,



Thanks!

interesting contribution.

orux
orux
orux

Cantidad de envíos : 3946
Fecha de inscripción : 2009-07-06

Back to top Go down

Automatically calculating custom waypoints (left/right) for route Empty Re: Automatically calculating custom waypoints (left/right) for route

Post  cyberdude Tue Sep 17, 2013 3:08 pm

I'm trying to get this to work but have never used custom waypoints in Oruxmaps before. I've created the waypoint file for my route but what do I do with it? I've put it into the custom waypoint folder but does it need to be renamed to the same name as the route file or not because my route is not finding the waypoints? Also, how or where do the turn icons appear as shown in the screen shot above?


cyberdude

Cantidad de envíos : 57
Fecha de inscripción : 2011-12-16

Back to top Go down

Automatically calculating custom waypoints (left/right) for route Empty Re: Automatically calculating custom waypoints (left/right) for route

Post  cyberdude Fri Sep 27, 2013 12:03 pm

Sorry to bump this, but can anyone offer any help on how to get this working or a tutorial on how to make custom waypoints work? I can't get the routing to work with the generated waypoints.
Thanks.

cyberdude

Cantidad de envíos : 57
Fecha de inscripción : 2011-12-16

Back to top Go down

Automatically calculating custom waypoints (left/right) for route Empty Re: Automatically calculating custom waypoints (left/right) for route

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum