Update generate.

This commit is contained in:
Mikaël Capelle 2018-03-01 22:18:27 +01:00
parent 02ff4962b3
commit 5d642f288a
2 changed files with 109 additions and 9 deletions

View File

@ -2,9 +2,16 @@
DEFAULT_OUTPUT_FOLDER=outputs
DEFAULT_WRITER=insa2018
bounding_box=
bounding_poly=
map_id=
debug=false
graph_only=false
mapsforge_only=false
input_file=
output_name=
@ -12,7 +19,7 @@ output_name=
#
# Print short usage information.
function help_short() {
echo "Usage: $0 [-h|--help] [-d|--debug] [-b|--bounding-box] [-o|--output OUTPUT_NAME] INPUT_FILE"
echo "Usage: $0 [-h|--help] [-d|--debug] [-i|--id MAP_ID] [-b|--bounding-box FILE|BBOX] [-g|--graph-only] [-f|--mapsforge-only] [-p|--bounding-polygon FILE] [-o|--output OUTPUT_NAME] INPUT_FILE"
}
# FUNCTION help_long()
@ -21,7 +28,9 @@ function help_short() {
function help_long() {
help_short
printf "\t-d,--debug\tEnable debug mode.\n"
printf "\t-b,--bounding-box \tSpecify a bounding-box, either via a string or a file.\n"
printf "\t-i,--id\tMap ID.\n"
printf "\t-b,--bounding-box\tSpecify a bounding-box, either via a string or a file.\n"
printf "\t-p,--bounding-polygon\tSpecify a bounding-polygon, only used for OSM2Graph.\n"
printf "\t-h,--help\tPrint this help.\n"
}
@ -29,7 +38,7 @@ function help_long() {
#
# Print error composed of arguments, then exit.
function error() {
echo "$0: $*" >> /dev/stderr
echo "ERROR: $0: $*" >> /dev/stderr
exit 1
}
@ -37,7 +46,7 @@ function error() {
#
# Print error composed of arguments, followed by help, then exit.
function error_and_usage() {
echo "$0: $*" >> /dev/stderr
echo "ERROR: $0: $*" >> /dev/stderr
help_short
exit 1
}
@ -46,9 +55,18 @@ function error_and_usage() {
#
# Print warning / information composed of arguments.
function warning() {
echo "$0: $*" >> /dev/stderr
echo "WARNING: $0: $*" >> /dev/stderr
}
# FUNCTION warning(...)
#
# Print information composed of arguments.
function info() {
echo "INFO: $0: $*" >> /dev/stderr
}
# FUNCTION run(...)
#
# Execute given command if debug mode is disabled, otherwize
@ -61,7 +79,7 @@ function run() {
# FUNCTION check_input_file()
#
# Check if input file exists and has read access.
function() check_input_file() {
function check_input_file() {
if [ -z "${input_file}" ]; then
error_and_usage "Missing input file."
@ -84,11 +102,11 @@ function() check_input_file() {
# FUNCTION check_output_file()
#
# Check output file.
function() check_input_file() {
function check_output_file() {
if [ -z "${output_file}" ]; then
output_file=${DEFAULT_OUTPUT_FOLDER}/$(basename -s .pbf ${input_file})
warning "No output file specific, switching to ${output_file}."
info "No output file specific, switching to ${output_file}."
fi
}
@ -104,6 +122,20 @@ do
bounding_box="$2"
shift
;;
-p|--bounding-polygon)
bounding_poly="$2"
shift
;;
-f|--mapsforge-only)
mapsforge_only=true
;;
-g|--graph-only)
graph_only=true
;;
-i|--id)
map_id="$2"
shift
;;
-d|--debug)
debug=true
;;
@ -124,3 +156,71 @@ done
check_input_file
check_output_file
if [ -z "${map_id}" ]; then
error_and_usage "No map ID specified."
fi
if [ ! -z "${bounding_box}" ] && [ -e "${bounding_box}" ]; then
bounding_box=$(cat ${bounding_box})
fi
if [ -z "${bounding_box}" ] && echo ${input_file} | grep "merge"; then
error_and_usage "Using a merged file (_merge) without bounding box is not possible."
fi
if ${graph_only}; then
info "Skipping mapsforge generation... "
else
CMD_MF="bin/osmosis --rb ${input_file} --lp --mapfile-writer file=${output_file}.mapfg threads=4"
if [ ! -z "${bounding_box}" ]; then
CMD_MF="${CMD_MF} bbox=${bounding_box}"
fi
nohup ${CMD_MF} > nohup_mf_$(basename ${output_file}).out &
fi
if ${mapsforge_only}; then
info "Skipping graph generation... "
else
# Merge file as input...
if echo ${input_file} | grep "merge"; then
# Try to find the originl (.osm.pbf)...
input_file=$(echo ${input_file} | sed 's/_merge.pbf/.osm.pbf/')
# ...or a generated .pbf...
if [ ! -e ${input_file} ]; then
input_file=$(echo ${input_file} | sed 's/.osm//')
fi
# If nothing is found, warn the user...
if [ ! -e ${input_file} ]; then
warning "Merge file specified but the original file was not found, the graph file may not be generated correctly from the merged file."
else
info "Merge file detected, original file was found: ${input_file}."
fi
fi
CMD_GR="bin/osmosis --rb ${input_file} --lp"
if [ ! -z "${bounding_polygon}" ]; then
CMD_GR="${CMD_GR} --bounding-polygon file=${bounding_polygon} completeWays=yes --lp"
else
if [ ! -z "${bounding_box}" ]; then
osmbbox=$(echo ${bounding_box} | \
tr "," " " | \
xargs printf "bottom=%f left=%f top=%f right=%f")
CMD_GR="${CMD_GR} --bounding-box ${osmbbox} completeWays=yes --lp"
fi
fi
CMD_GR="${CMD_GR} --tf reject-relations"
CMD_GR="${CMD_GR} --tf accept-ways highway=$(cat inputs/highway-filter.cmd) natural=coastline junction=roundabout"
CMD_GR="${CMD_GR} --used-node --osm2graph writer=${DEFAULT_WRITER} file=${output_file}.mapgr map-id=${map_id}"
nohup ${CMD_GR} > nohup_gr_$(basename ${output_file}).out &
fi

@ -1 +1 @@
Subproject commit af6bad663a1aa316343e3586d8a9925c4bc83d44
Subproject commit 6f57841e814010848722f1df28b10d0f3ad0dc25