be-graphes-map-generator/inputs/coastline-fix.sh

90 lines
2.1 KiB
Bash
Raw Normal View History

2018-02-24 21:43:28 +00:00
#!/bin/bash
# Mapsforge map creation (with coastlines) - Modified by Mikael
# Osmosis folder
2018-02-24 22:17:41 +00:00
OSMOSIS=$(pwd)/../bin/osmosis
2018-02-24 21:43:28 +00:00
# Input folder
2018-02-24 22:17:41 +00:00
INPUTS=$(pwd)
2018-02-24 21:43:28 +00:00
2018-02-27 18:48:47 +00:00
# Input PBF
inpbf=$1
2018-02-24 22:17:41 +00:00
2018-02-27 18:48:47 +00:00
if [ -z "${inpbf}" ]; then
echo "Usage: $0: PBF_FILE"
2018-02-24 22:17:41 +00:00
exit 1
fi
2018-02-27 18:48:47 +00:00
region_dir=$(dirname $(realpath ${inpbf}))
region_name=$(basename ${inpbf} .pbf)
region_name=$(basename ${region_name} .osm)
poly_file=${region_dir}/${region_name}.poly
2018-03-14 10:11:54 +00:00
bbox_file=${region_dir}/${region_name}.bbox
2018-02-27 18:48:47 +00:00
if [ ! -e "${inpbf}" ]; then
echo "${inpbf} does not exist, you may want to download it from https://download.geofabrik.de/index.html."
2018-02-24 22:17:41 +00:00
exit 1
fi
2018-02-27 18:48:47 +00:00
if [ ! -e "${poly_file}" ]; then
poly_file=${INPUTS}/bbox/${region_name}.poly
fi
if [ ! -e "${poly_file}" ]; then
echo "Unable to find polygon file, you may want to download it from https://download.geofabrik.de/index.html."
2018-02-24 22:17:41 +00:00
exit 1
fi
if [ ! -e "$INPUTS/land-polygons-split-4326/land_polygons.shp" ]; then
echo "Land polygons shapefile does not exist, did you forget to run init.sh?"
exit 1
fi
2018-02-24 21:43:28 +00:00
# Bounds
2018-02-27 18:48:47 +00:00
olddir=$(pwd)
cd ${INPUTS}/mapsforge-creator
BBOX=$(perl poly2bb.pl "${poly_file}")
2018-03-14 10:11:54 +00:00
echo "$BBOX" > ${bbox_file}
2018-02-25 00:15:29 +00:00
2018-02-24 21:43:28 +00:00
BBOX=(${BBOX//,/ })
BOTTOM=${BBOX[0]}
LEFT=${BBOX[1]}
TOP=${BBOX[2]}
RIGHT=${BBOX[3]}
2018-02-27 18:48:47 +00:00
2018-02-24 21:43:28 +00:00
# Start position
2018-02-27 18:48:47 +00:00
CENTER=$(perl poly2center.pl "${poly_file}")
2018-02-24 21:43:28 +00:00
CENTER=(${CENTER//,/ })
LAT=${CENTER[0]}
LON=${CENTER[1]}
# Land
2018-02-27 18:48:47 +00:00
ogr2ogr -overwrite -progress -skipfailures -clipsrc $LEFT $BOTTOM $RIGHT $TOP "${region_dir}/${region_name}_land.shp" "$INPUTS/land-polygons-split-4326/land_polygons.shp"
python shape2osm.py -l "${region_dir}/${region_name}_land" "${region_dir}/${region_name}_land.shp"
2018-02-24 21:43:28 +00:00
# Sea
2018-02-27 18:48:47 +00:00
sea_file="${region_dir}/${region_name}_sea.osm"
cp sea.osm "${sea_file}"
sed -i "s/\$BOTTOM/$BOTTOM/g" "${sea_file}"
sed -i "s/\$LEFT/$LEFT/g" "${sea_file}"
sed -i "s/\$TOP/$TOP/g" "${sea_file}"
sed -i "s/\$RIGHT/$RIGHT/g" "${sea_file}"
2018-02-24 21:43:28 +00:00
2018-02-27 18:48:47 +00:00
cd ${olddir}
2018-02-25 00:15:29 +00:00
2018-02-27 18:48:47 +00:00
CMD="$OSMOSIS --rb file=${inpbf} \
--rx file=${sea_file} --s --m"
for f in ${region_dir}/${region_name}_land*.osm; do
2018-02-24 21:43:28 +00:00
CMD="$CMD --rx file=$f --s --m"
done
2018-02-27 18:48:47 +00:00
CMD="$CMD --wb file=${region_dir}/${region_name}_merge.pbf omitmetadata=true"
2018-02-24 21:43:28 +00:00
echo $CMD
$CMD