Mkgmap Linux Script Issue

I recently switched to Ubuntu and am converting my Windows map generation scripts. At the point of the script where I generate the command to run mkgmap something goes awry. The command I construct causes mkgmap to throw a variety of errors. However if I echo that command to the terminal, copy / paste it back and press enter it runs fine.

Script code:

java -Xmx2000M -jar $mkgmapJar --family-name=\"$familyName\" --mapname=$mapName --reduce-point-density=5.4 --index --adjust-turn-headings --ignore-maxspeeds --ignore-turn-restrictions --remove-short-arcs=4 --description=\"$Description \"--location-autofill=1 --family-id=$mapNo  --route --link-pois-to-ways --add-pois-to-areas --add-pois-to-lines --generate-sea=\"land-tag=natural=land\" --output-dir=$tempDIR --gmapsupp $gmapsupp $customDataFile  $styleDIR/$mapNo.typ

Which expands into:

java -Xmx2000M -jar /home/david/OpenStreetMap/mkgmap/mkgmap.jar --family-name="OpenStreetMap Saskatchewan" --mapname=55710000 --style-file=/home/david/OpenStreetMap/mkgmapSTYLES/custom_style --check-styles --reduce-point-density=5.4 --index --adjust-turn-headings --ignore-maxspeeds --ignore-turn-restrictions --remove-short-arcs=4 --description="OpenStreetMap Saskatchewan 24-JAN-25" --location-autofill=1 --family-id=5571  --route --link-pois-to-ways --add-pois-to-areas --add-pois-to-lines --generate-sea="land-tag=natural=land" --output-dir=/home/david/OpenStreetMap/MapTemp --gmapsupp /home/david/OpenStreetMap/MapTemp/*.osm.pbf /home/david/OpenStreetMap/CustomMapLayer.osm  /home/david/OpenStreetMap/mkgmapSTYLES/custom_style/5571.typ

If I have spaces in FamilyName or Description within double quotes mkgmap hits the space and thinks it is past the options section and the text after the space is the first input file.

SEVERE (Main): Saskatchewan": input file 'Saskatchewan"' doesn't exist
WARNING (global): Setting max-jobs to 6
SEVERE (Main): Saskatchewan: input file 'Saskatchewan' doesn't exist
SEVERE (Main): 24-JAN-25": input file '24-JAN-25"' doesn't exist
Unknown sea generation option '"land-tag=natural=land"'

When I remove the spaces, it still has problems with the sea polygon declaration. The error and usage instructions are displayed multiple times, but it does continue and generate a gmapsupp.img file

Unknown sea generation option '"land-tag=natural=land"'

I have no idea if it is an mkgmap issue or a problem with the script.

(guessing without testing but)

It might help to change some of the double quotes to single quotes to avoid the shell trying to process what is inside (at least one parameter has wildcards).

Re the “no spaces and still get a problem with sea” thing, maybe try removing double quotes from around that, since the error reported includes the double quotes?

1 Like

Swapped the double quotes for singles, and same behavior on both issues.

you don’t say which shell you use, and without the whole code it is hard to see the reason for the error, but it seems to be some escaping problem or with quotes

I found a workaround that will be adequate for me. I echo the command to a file, make it executable and run it. No errors.

Here’s the original script.

#!/bin/bash

# Store current directory and check if the pbf input file is available before continuing
rootDIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
inputPBF="$rootDIR/saskatchewan-latest.osm.pbf"

if ! test -f $inputPBF; then
   echo $inputPBF is not present, cannot proceed.
   read -rsp $'Press Enter to continue...\n' -n 1
   exit
fi


# Set variables
# MapNo determines name of temporary files generated (used by splitter & mkgmap)
#  different MapNo are required if you want to use multiple maps on the same device
#  specify 4 digits, will be padded with 4 trailing zeros to make required 8 digits
fileDate=$(date -r, --reference=$inputPBF "+%d-%b-%y" | tr 'a-z' 'A-Z')		# store date of pbf file formated DD-MMM-YY

mkgmapJar="$rootDIR/mkgmap/mkgmap.jar"
splitterJar="$rootDIR/splitter/splitter.jar"

tempDIR="$rootDIR/MapTemp"
styleDIR="$rootDIR/mkgmapSTYLES/custom_style"

customDataFile="$rootDIR/CustomMapLayer.osm"  # .osm file generated in JOSM with extra things I want on the map
if ! test -f $customDataFile; then customDataFile=""; fi  # set variable blank if file doesn't exist
   

mapNo="5571"
mapName=$mapNo"0000"
familyName="OpenStreetMap_Saskatchewan"
Description="OpenStreetMap_Saskatchewan_$fileDate"

gmapsupp="$tempDIR/$MapNo*.osm.pbf"	# intermediate files generated by splitter ()


# VARIABLE OUTPUT TEST
:<<COMMENT
echo "rootDIR = $rootDIR"
echo "inputPBF = $inputPBF"
echo "fileDate = $fileDate"
echo "mkgmapJar = $mkgmapJar"
echo "splitterJar = $splitterJar"
echo "tempDIR = $tempDIR"
echo "styleDIR = $styleDIR"
echo "customDataFile = $customDataFile"
echo "mapNo = $mapNo"
echo "mapName = $mapName"
echo "familyName = $familyName"
echo "Description = $Description"
echo "gmapsupp = $gmapsupp"

exit
COMMENT

echo "** SPLITTING REGION INTO TILES **"
java -Xmx1000M -jar $splitterJar --output-dir=$tempDIR --mapid="$mapName" $inputPBF


echo "** GENERATING MAP FILE ( gmapsupp.img ) **"
#problems here, fails if spaces in descriptions, errors for sea poly, but works fine if manually pasted to terminal
java -Xmx2000M -jar $mkgmapJar --family-name=\"$familyName\" --mapname=$mapName --reduce-point-density=5.4 --index --adjust-turn-headings --ignore-maxspeeds --ignore-turn-restrictions --remove-short-arcs=4 --description=\"$Description\" --location-autofill=1 --family-id=$mapNo  --route --link-pois-to-ways --add-pois-to-areas --add-pois-to-lines --generate-sea=\"land-tag=natural=land\" --output-dir=$tempDIR --gmapsupp $gmapsupp $customDataFile  $styleDIR/$mapNo.typ


echo "** DELETING TEMPORARY FILES **"
cd $tempDIR
mv -f gmapsupp.img ../"SASK-$fileDate.img"	# rename / move generated map
rm *						# clear temp folder


read -rsp $'Press Enter to continue...\n' -n 1
1 Like

I had 8 virtually identical map creation batch files in Windows. Since Linux scripting is so much easier, this evening I combined them all into a single script where it prompts me for which of them to build.