commit cd5cc9a080461f9d0c3d58927d71906a6f2a8abf
parent 34870c7a1094904bc1c9202cea963ec0a355d732
Author: Tomas Hlavaty <tom@logand.com>
Date: Sat, 15 Jun 2019 07:16:20 +0200
first working version on cli
OSMQ_ZOOM=14 osqm alberobello
Diffstat:
M | osmq | | | 23 | ++++++++++++++++------- |
M | osmtile.c | | | 35 | +++++++++++++++++++++++++++++++++++ |
2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/osmq b/osmq
@@ -1,10 +1,19 @@
#!${bash}/bin/bash
set -e
set -o pipefail
-curl \
- -s \
- "https://nominatim.openstreetmap.org/search?q=$*&format=json" \
- | jq \
- -r \
- 'map([.lat, .lon, .display_name] | join(", ")) | join("\n")' \
- | fzf -0 -1 --with-nth=3..
+DIR=~/.cache/osmq
+URL=$(curl \
+ -s \
+ "https://nominatim.openstreetmap.org/search?format=json&q=$*" \
+ | jq \
+ -r \
+ 'map([.lat, .lon, .display_name] | join(", ")) | join("\n")' \
+ | fzf -0 -1 --with-nth=3.. \
+ | osmtile url $OSMQ_ZOOM)
+CACHE=$(echo "$URL" | osmtile cache $DIR)
+if test ! -f $CACHE; then
+ mkdir -p $(dirname "$CACHE")
+ curl -s "$URL" >"$CACHE"
+fi
+test -f $CACHE
+fbi -a $CACHE
diff --git a/osmtile.c b/osmtile.c
@@ -107,6 +107,39 @@ static int url(int argc, char *argv[]) {
return 0;
}
+static int cache(int argc, char *argv[]) {
+ char *dir = argv[0];
+ if(!dir) goto fail;
+ for(int c = getchar(); c != ':'; c = getchar()) {
+ if(EOF == c) {
+ fprintf(stderr, "expected ':'\n");
+ return 1;
+ }
+ }
+ for(int i = 0; i < 2; i++) {
+ if('/' != getchar()) {
+ fprintf(stderr, "expected '/'\n");
+ return 1;
+ }
+ }
+ for(int c = getchar(); c != '/'; c = getchar()) {
+ if(EOF == c) {
+ fprintf(stderr, "expected '/'\n");
+ return 1;
+ }
+ }
+ int z, x, y;
+ if(3 != scanf("%d/%d/%d.png", &z, &x, &y)) {
+ fprintf(stderr, "expected z/x/y.png\n");
+ return 1;
+ }
+ printf("%s/%d/%d/%d.png\n", dir, z, x, y);
+ return 0;
+ fail:
+ fprintf(stderr, "unexpected dir %s\n", dir);
+ return 1;
+}
+
static int version(int argc, char *argv[]) {
printf("%s\n",
#include "VERSION"
@@ -121,6 +154,7 @@ static int help(int argc, char *argv[]) {
printf(" x zoom longitude\n");
printf(" y zoom latitude\n");
printf(" url zoom\n");
+ printf(" cache dir\n");
printf(" --version\n");
printf(" --help\n");
return 0;
@@ -138,6 +172,7 @@ int main(int argc, char *argv[]) {
{"x", x},
{"y", y},
{"url", url},
+ {"cache", cache},
{"--version", version},
{"--help", help},
{NULL}