File indexing completed on 2024-04-21 14:52:05

0001 #!/bin/bash
0002 
0003 # SPDX-License-Identifier: LGPL-2.1-or-later
0004 #
0005 # SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org>
0006 #
0007 
0008 #
0009 # Creates a .xml file suitable to pass to osm-sisyphus
0010 #
0011 
0012 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0013 echo "<regions>"
0014 
0015 cat "${1}" | while read pbf
0016 do
0017     file="$(basename $pbf)"
0018 
0019     count=$(echo $pbf | awk -F"/" '{ print NF-1}')
0020     if [[ $count -eq 1 ]]
0021     then
0022       continent="$(dirname $pbf)"
0023       country=""
0024     elif [[ $count -eq 2 ]]
0025     then
0026       continent="$(dirname $(dirname $pbf))"
0027       country="$(basename $(dirname $pbf))"
0028     elif [[ $count -eq 3 ]]
0029     then
0030       continent="$(dirname $(dirname $(dirname $pbf)))"
0031       country="$(basename $(dirname $(dirname $pbf)))"
0032     fi
0033 
0034     name="${file/.osm.pbf/}"
0035     name="${name//-/ }"
0036     name="${name//_/ }"
0037     name=( $name )
0038     name="${name[@]^}"
0039 
0040     country="${country/_/ }"
0041     country=( ${country/_/ } )
0042 
0043     continent="${continent/us-west/usa}"
0044     continent="${continent/us-midwest/usa}"
0045     continent="${continent/us-northeast/usa}"
0046     continent="${continent/us-south/usa}"
0047     continent="${continent/us-pacific/usa}"
0048 
0049     if [[ "${continent}" == "usa" ]]
0050     then
0051       continent="north-america"
0052       country="USA"
0053       pbf="${pbf/us-west/north-america/us}"
0054       pbf="${pbf/us-midwest/north-america/us}"
0055       pbf="${pbf/us-northeast/north-america/us}"
0056       pbf="${pbf/us-south/north-america/us}"
0057       pbf="${pbf/us-pacific/north-america/us}"
0058     fi
0059 
0060     continent="${continent/-/ }"
0061     continent=( ${continent/-/ } )
0062 
0063     echo "  <region>"
0064     echo "    <id>${file/.osm.pbf/}</id>"
0065     echo "    <continent>${continent[@]^}</continent>"
0066     echo "    <country>${country[@]^}</country>"
0067     echo "    <name>${name}</name>"
0068     echo "    <path>${pbf/.osm.pbf/}</path>"
0069     echo "    <pbf>${pbf}</pbf>"
0070     echo "  </region>"
0071 done
0072 
0073 echo "</regions>"