OSMand Audio-nodes in JOSM zien

Hoi,

Ik heb een superlelijk scriptje gemaakt om de locatie van audio/video-notieties die je in OSMand kan maken in JOSM te zien. In JOSM kan je op elk waypoint klikken om de audio van het bestandje te horen.

createAVnotesGPX.sh


#!/bin/bash
#created by IIVQ
# Uses a modified makeShortCode algorithm inspired from:
# https://github.com/openstreetmap/openstreetmap-website/blob/e84b2bd22f7c92fb7a128a91c999f86e350bf04d/app/assets/javascripts/application.js
echo  "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" > avnotes.gpx
echo "<gpx version=\"1.1\" creator=\"createNotesGPS \\ IIVQ\" xmlns=\"http://www.topografix.com/GPX/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\">" >> avnotes.gpx
cd AVnotesTodo
for i in *.[3mj][gp][p4g]
	do ../osmdecodeshortlink.pl $i >> ../avnotes.gpx
done
cd ..
echo  "</gpx>" >> avnotes.gpx

Dit scriptje heeft een perl-script nodig, OSMdecodeshortlink.pl, dat ik hier gevonden heb en lichtelijk aangepast heb.

osmdecodeshortlink.pl


#!/usr/bin/perl

# License: GNU General Public License 2.0, http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

# makeShortCode algorithm inspired from:
# https://github.com/openstreetmap/openstreetmap-website/blob/e84b2bd22f7c92fb7a128a91c999f86e350bf04d/app/assets/javascripts/application.js

use POSIX;
use Math::BigInt;

if($#ARGV!=0) { die("Syntax: osmmakeshortlink.pl shortcode\n"); }

($scl)=@ARGV;

$scu=substr($scl,0,8); 
$sc = $scu; 
$sc =~ s/@/_/g; # replace "@" from osmand avnotes to "_", which is the apparent shortcode implementation.
#print "Long URL: http://www.openstreetmap.org/#map=$z/$lat/$lon\n";
#$sc=&makeShortCode($lat,$lon,$z);
#print "Short Code: $sc\n";
#print "Short URL: http://osm.org/go/$sc\n";
($lat,$lon,$z)=&decodeShortCode($sc);
print "<wpt lat=\"$lat\" lon=\"$lon\"><name>$scu</name><link href=\"AVnotesTodo/$scl\" /></wpt>\n";


sub makeShortCode {
  $char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
  my $x=floor(($_[1] + 180.0) * ((1 << 30) / 90.0) +.5);
  my $y=floor(($_[0] + 90.0) * ((1 << 30) / 45.0) + .5);
  my $z=$_[2];
  if($z<1 || $z>22) { 
    print STDERR "makeShortCode: Zoom $z will probably not give a reasonable result\n";
  }
  my $str="";
  my $c=&interleave($x,$y);
  foreach my $i (1 .. ceil(($z + 8) / 3.0)) {
    $digit = ($c->copy()->brsft(64 - 6 * $i))->band(0x3f);
    $str.=substr($char_array,$digit,1);
  }
  foreach $i (1 .. ($z+8)%3) {
    $str.="-";
  }
  return $str;
}

sub interleave {
  # combine 2 32 bit integers to a 64 bit integer
  $c=Math::BigInt->bzero();
  (my $x,my $y)=@_;
  foreach $i (-31 .. 0) {
    $c1 = $c->copy()->blsft(1); $c=$c1->copy()->bior(($x >> -$i) & 1);
    $c1 = $c->copy()->blsft(1); $c=$c1->copy()->bior(($y >> -$i) & 1);
  }
  return $c;
}

sub decodeShortCode {
  $char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
  my $sc=$_[0];
  my $x=0;
  my $y=0;
  my $i;
  my $z=-8;
  if($sc!~/^[A-Za-z0-9_~]{1,10}-{0,2}$/) {
    print STDERR "decodeShortCode: not a valid short code\n";
    return ($y,$x,$z);
  }
  for ($i=0; $i<length($sc); $i++) {
    $ch=substr($sc,$i,1);
    $digit=index($char_array,$ch);
    last if $digit == -1;
    # distribute 6 bits into $x and $y
    $x <<= 3;
    $y <<= 3;
    foreach my $j (-2 .. 0) {
      $x|= (($digit & (1 << (2*-$j+1))) == 0 ? 0 : (1 << -$j));
      $y|= (($digit & (1 << (2*-$j))) == 0 ? 0 : (1 << -$j));
    }
    $z+=3;
  }
  $x = $x * 2**(2-3*$i) * 90 - 180;
  $y = $y * 2**(2-3*$i) * 45 - 90;
  # adjust $z
  if($i<length($sc) && substr($sc,$i,1) eq "-") {
    $z-=2;
    if($i+1<length($sc) && substr($sc,$i+1,1) eq "-") { $z++; }
  }
  return ($y,$x,$z);
}


Kopieer je AVnotes van je android-apparaat (directory /sdcard/osmand/AVnotes/) naar de directory AVnotesTodo (in dezelfde directory als dit scriptje staat), draai het scriptje en laad vervolgens avnotes.gpx in in jOSM. Je ziet nu de exacte locaties van alle notes.

Het resultaat is
waarbij je bij inzoomen ziet wat de naam van het 3gp-bestand is en een x op de exacte plek waar je begonnen bent met opnemen.