Created
September 26, 2020 11:54
-
-
Save answerquest/daba8d82b7485773e8a9c85ba9223ad2 to your computer and use it in GitHub Desktop.
osm_pbf_generation.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # script for downloading fresh OSM extract for India and making regional extracts | |
| printf "\n\n$(date)\n" | |
| # This stores absolute path of this shell script into $DIR. Similar to python's root = os.path.dirname(__file__) | |
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | |
| # user-set variables | |
| websiteFolder="/var/www/html/dump" | |
| cd "${DIR}/" | |
| echo "working dir: $(pwd)" | |
| echo "Retrieving latest OSM data if updated" | |
| wget -N --timeout=20 http://download.geofabrik.de/asia/india-latest.osm.pbf | |
| # -N : Check server timestamp and skip download if it's the same as local. | |
| echo "Making statewise pbfs. The .poly's are stored under states_poly/" | |
| cd "${DIR}/states_poly/" | |
| # starting for loop | |
| for f in *.poly | |
| do | |
| echo ${f} | |
| a=`echo ${f} | cut -d'.' -f1` | |
| osmconvert ../india-latest.osm.pbf -B=${f} --complete-ways -o="${websiteFolder}"/temp_${a}.pbf | |
| # after creating, rename to proper state file name. To avoid people downloading while its in midst of being created. | |
| mv "${websiteFolder}"/temp_${a}.pbf "${websiteFolder}"/${a}.pbf | |
| echo "$(date): ${a}.pbf created" | |
| done | |
| # end of for loop | |
| # quirk : files were created at the locations but didn't have any read permissions also so weren't downloadable. Fix for that: | |
| chmod 644 "${websiteFolder}"/*.pbf | |
| echo "$(date): done with script" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment