#!/bin/bash # Download and extract Madrid features from OSM, sort and renumber # # Santiago Crespo 2022 if [ $# -eq 0 ]; then echo "Uso: $0 ID_inicial tag [valor]" echo "Ejemplo: $0 90000000000 leisure park" exit 1 fi INITIALID=$1 TAG=$2 VALOR=$3 DIA=`date +%Y-%m-%d` HORA=`date +%H-%M-%S` # https://overpass-turbo.eu/ # Asistente # $TAG=$VALOR in Madrid # Exportar > Consulta > Convertir a compact # copiar URL if [ -z "$VALOR" ]; then mkdir -p "$TAG" cd "$TAG" mkdir "$DIA-$HORA" cd "$DIA-$HORA" echo "Downloading Madrid's $TAG=*..." wget -nv "https://overpass-api.de/api/interpreter?data=%2F*%0AThis%20has%20been%20generated%20by%20the%20overpass-turbo%20wizard.%0AThe%20original%20search%20was%3A%0A%E2%80%9C$TAG%3D*%20in%20madrid%E2%80%9D%0A*%2F%0A%5Bout%3Axml%5D%2F*fixed%20by%20auto%20repair*%2F%5Btimeout%3A25%5D%3B%0A%2F%2F%20fetch%20area%20%E2%80%9Cmadrid%E2%80%9D%20to%20search%20in%0Aarea(3605326784)-%3E.searchArea%3B%0A%2F%2F%20gather%20results%0A(%0A%20%20%2F%2F%20query%20part%20for%3A%20%E2%80%9C$TAG%3D*%E2%80%9D%0A%20%20node%5B%22$TAG%22%5D(area.searchArea)%3B%0A%20%20way%5B%22$TAG%22%5D(area.searchArea)%3B%0A%20%20relation%5B%22$TAG%22%5D(area.searchArea)%3B%0A)%3B%0A%2F%2F%20print%20results%0Aout%20meta%3B%2F*fixed%20by%20auto%20repair*%2F%0A%3E%3B%0Aout%20meta%20qt%3B%2F*fixed%20by%20auto%20repair*%2F" -O tmp.osm || exit 1 # wget -nv "https://overpass-api.de/api/interpreter?data=%5Bout%3Axml%5D%5Btimeout%3A25%5D%3Barea%283605326784%29%2D%3E%2EsearchArea%3B%28node%5B%22$TAG%22%5D%28area%2EsearchArea%29%3Bway%5B%22$TAG%22%5D%28area%2EsearchArea%29%3Brelation%5B%22$TAG%22%5D%28area%2EsearchArea%29%3B%29%3Bout%20meta%3B%3E%3Bout%20meta%20qt%3B%0A" -O tmp.osm || exit 1 OUTFILE=$TAG"_madrid_OSM.osm" else # Cuando hay TAG+VALOR mkdir -p "$TAG-$VALOR" cd "$TAG-$VALOR" mkdir "$DIA-$HORA" cd "$DIA-$HORA" echo "Downloading Madrid's $TAG=$VALOR..." wget -nv "https://overpass-api.de/api/interpreter?data=%5Bout%3Axml%5D%5Btimeout%3A25%5D%3Barea%283605326784%29%2D%3E%2EsearchArea%3B%28node%5B%22$TAG%22%3D%22$VALOR%22%5D%28area%2EsearchArea%29%3Bway%5B%22$TAG%22%3D%22$VALOR%22%5D%28area%2EsearchArea%29%3Brelation%5B%22$TAG%22%3D%22$VALOR%22%5D%28area%2EsearchArea%29%3B%29%3Bout%20meta%3B%3E%3Bout%20meta%20qt%3B%0A" -O tmp.osm || exit 1 OUTFILE=$TAG"-"$VALOR"_madrid_OSM.osm" fi echo "Sorting and renumbering from $INITIALID..." osmium sort -o tmp-sorted.osm tmp.osm --overwrite || exit 1 echo "Si falla por "Node ID twice", abrir tmp-sorted.osm en JOSM, guardar y ejecutar osmium renumber de nuevo:" echo "osmium renumber --start-id=$INITIALID -o $OUTFILE tmp-sorted.osm --overwrite && cp $OUTFILE ../.. && echo $OUTFILE generado OK :)" osmium renumber --start-id=$INITIALID -o $OUTFILE tmp-sorted.osm --overwrite || exit 1 mkdir -p ../../current # normalmente ya existirá cp $OUTFILE ../../current/ || exit 1 echo "$OUTFILE generado correctamente :)" && exit 0