User:Contrapunctus

From OpenStreetMap Wiki
Jump to: navigation, search
OSM Logo This user submits data to OpenStreetMap under the name
contrapunctus.
Debian-logo-notext.svg Contrapunctus uses a Debian-based computer.
OsmAnd icon Contrapunctus uses OsmAnd, mobile map viewing & navigation app.
Babel
en-4 This user speaks English at a near-native level.
Template:User hi
de-2 Dieser Benutzer hat fortgeschrittene Deutschkenntnisse.

Scripts for geo: URIs

I hope these are useful to whoever finds them :)

coord2geo

 1 #!/bin/bash
 2 
 3 # Tests
 4 # coord2geo "28.5484586, 77.2566089"
 5 # coord2geo "-24.09498, -48.36436"
 6 
 7 if [[ $# == 0 ]]; then
 8     read -t 1 coordinates
 9 else
10     coordinates="$1"
11 fi
12 
13 if [[ "$coordinates" == "" ]]; then
14     printf "Usage: coord2geo [COORDINATES]\n\n"
15     printf "Makes a geo: link from COORDINATES, where COORDINATES is
16 \"<latitude>, <longitude>\"\n\n"
17     printf "If COORDINATES is omitted, stdin is used instead.\n\n"
18 else
19     lat="$(echo $coordinates | sed -n "s|\(.*\),.*|\1|p")"
20     lon="$(echo $coordinates | sed -n "s|.*, \(.*\)|\1|p")"
21     # printf "lat - $lat\nlon - $lon\n"
22     printf "geo:$lat,$lon\n"
23 fi

geo2osm

 1 #!/bin/bash
 2 
 3 # Test
 4 # geo2osm "geo:-24.09498,-48.36436?z=19"
 5 
 6 if [[ $# == 0 ]]; then
 7     read -t 1 link
 8 else
 9     link="$1"
10 fi
11 
12 if [[ "$link" == "" ]]; then
13     printf "Usage: geo2osm [GEO]\n\n"
14     printf "Makes an osm.org link from GEO, where GEO is a geo:
15 URI.\n\n"
16     printf "If GEO is omitted, stdin is used instead.\n\n"
17 else
18     lat="$(echo "$link" | sed -En "s|geo:([0-9\.-]*),.*|\1|p")"
19     lon="$(echo "$link" | sed -En "s|geo:.*,([0-9\.-]*).*|\1|p")"
20     zoom="$(echo "$link" | sed -En "s|.*\?z=([0-9]*)|\1|p")"
21 
22     # test printf -
23     # printf "lat $lat\nlon $lon\nzoom $zoom\n"
24 
25     if [[ "$zoom" == "" ]]; then
26         # doesn't need a zoom value, adds a nice pointer
27         printf "https://www.openstreetmap.org/?mlat=$lat&mlon=$lon\n"
28     else
29         printf "https://openstreetmap.org/#map=$zoom/$lat/$lon/\n"
30     fi
31 fi

geo2osm-browse

1  #!/bin/bash
2 
3  if [[ $# == 0 ]]; then
4      read -t 1 link
5  else
6      link="$1"
7  fi
8  xdg-open "$(geo2osm $link)"

Having geo: URIs open on osm.org in your browser

Save the geo2osm and geo2osm-browse scripts in files of the same name in ~/bin/

Make them executable.

cd ~/bin/
chmod u+x geo2osm geo2osm-browse

Open ~/.local/share/applications/mimeapps.list in a text editor and add the following line.

x-scheme-handler/geo=geo.desktop

In the same directory, create a file called geo.desktop containing the following.

[Desktop Entry]
Version=1.0
Type=Application
Exec=/home/YOUR-USERNAME-HERE/bin/geo2osm-browse %u
Icon=geo2osm-browse
StartupNotify=true
Terminal=false
Categories=Utility;
MimeType=x-scheme-handler/geo
Name=Geo: Launcher
Comment=Open geo: links on osm.org

Voila! xdg-open should now open geo: URIs on osm.org in your preferred browser! :D