@echo off
rem --------------------------------------------------
rem --- CreateIMG.bat - By Marco Certelli - Beta07 ---
rem --------------------------------------------------
rem **** Define your default country ****
set country=dach-latest
rem *************************************
rem Available styles: drivemap, kleineisel, masterstyle, default, marine, noname, test
set style=mapst2
rem Available TYPfiles: DRIVEMAP.TYP, KLEINEISEL.TYP, MASTER.TYP, TEDDY.TYP, DOM.TYP
set typfile=velowaus.typ
rem Put AddTypToIMG=yes to add TYPfile to gmapsupp.img (so it is active in garmin too)
set AddTypToIMG=yes
rem MapSource Family-ID: must be a unique (in mapsource) 3 digit number (000 to 999)
set FID=900
rem MSDir shall contain the "existing" directory where mapsource installs maps
rem Next usually results in MSDir=C:\\Garmin
set MSDir=%systemdrive%\\Garmin
rem Next usually results in MSDir=C:\\Program Files\\Garmin
rem set MSDir=%ProgramFiles%
rem set MSDir=%MSDir:\=\\%
rem set MSDir=%MSDir%\\Garmin
rem Available continents: europe, africa, asia, north-america, south-america
set continent=
rem Just leave debug=no for production & to delete intermediate temporary files.
set debug=no
echo.
echo ******************************************************
echo * This script downloads (if needed) and compiles the *
echo * OSM map data to generate a Garmin IMG routable map *
echo ******************************************************
echo.
rem Override default country if a name is given to the batch as parameter
if "%1" NEQ "" set country=%1
rem Ask user for a country name if no default and no parameter is set
if "%country%" NEQ "" goto :Search4Map
set /P country="Enter the country to build: "
echo.
:Search4Map
if NOT EXIST OSM-Data mkdir OSM-Data
cd OSM-Data
rem 1) search for xxx.osm file
rem set osmfile=%country%.osm
rem if EXIST %osmfile% echo File OSM-Data\%osmfile% found (no download required)
rem if EXIST %osmfile% GOTO :SplitMap
rem 2) search for xxx.osm.bz2 file
rem set osmfile=%country%.osm.bz2
rem if EXIST %osmfile% echo File OSM-Data\%osmfile% found: delete it for a new download
rem if EXIST %osmfile% GOTO :SplitMap
rem 3) search for xxx.osm.pbf file
set osmfile=%country%.osm.pbf
if EXIST %osmfile% echo File OSM-Data\%osmfile% found: delete it for a new download
if EXIST %osmfile% GOTO :SplitMap
echo.
echo Downloading OSM data for %country%
echo.
if EXIST %osmfile% goto :SplitMap
echo.
echo *************************************************************
echo *** SORRY: download of /%continent%/%osmfile% has FAILED!!!
echo *** and manually download %osmfile%
echo *************************************************************
echo.
goto :END
:SplitMap
echo.
echo Start converting %country% OSM data into IMG Map...
if NOT EXIST ..\IMG-OSM-%country% mkdir ..\IMG-OSM-%country%
cd ..\IMG-OSM-%country%
if EXIST template.args goto :Compile
echo.
echo Splitting OSM-Data\%osmfile%. Please wait
echo.
rem start /low /b /wait java -enableassertions -Xmx1000m -jar ..\bin\splitter.jar --mapid=66%FID%001 --max-nodes=1000000 ..\OSM-Data\%osmfile%
rem start /low /b /wait java -enableassertions -Xmx1250m -jar ..\bin\splitter.jar --mapid=66%FID%001 --output=xml ..\OSM-Data\%osmfile%
start /low /b /wait java -enableassertions -Xmx1200m -jar ..\bin\splitter.jar> splitter.log --mapid=66%FID%001 --search-limit=200000 ..\OSM-Data\%osmfile% --output=xml --resolution=13 --max-nodes=200000 --max-areas=50 --wanted-admin-level=5 --problem-report --keep-complete=false --status-freq=120
:Compile
echo.
echo Compiling OSM-Data\%osmfile% into IMG, FID=%FID%. Please wait
echo.
set TypFileToAdd=
if "%AddTypToIMG%" NEQ "yes" goto :NoTypToAdd
copy "..\bin\typ\%typfile%" style.typ 2>nul 1>nul
..\bin\TYPtool %FID% 1 style.typ >nul
set TypFileToAdd=style.typ
:NoTypToAdd
rem start /low /b /wait java -enableassertions -Xmx1000m -jar ..\bin\mkgmap.jar --country-name="%country%" --family-id=%FID% --mapname=66%FID%001 --overview-mapname=66%FID%000 --series-name="OSM-%country%" --family-name="OpenStreetMap: %country%" --style-file=..\bin\styles\ --style=%style% --description="%country%" -c ..\bin\template_basic.args -c template.args %TypFileToAdd%
rem start /low /b /wait java -enableassertions -Xmx600m -jar ..\bin\mkgmap.jar --transparent --check-roundabouts --link-pois-to-ways --make-poi-index --reduce-point-density=2.6 --reduce-point-density-polygon=8 --index --levels=0:23,1:22,2:21,3:20 --make-poi-index --route --verbose --country-name="%country%" --family-id=%FID% --mapname=66%FID%001 --overview-mapname=66%FID%000 --series-name="OSM-%country%" --family-name="OpenStreetMap: %country%" --style-file=..\bin\styles\ --style=%style% --description="%country%" -c ..\bin\template_basic.args -c template.args %TypFileToAdd%
rem start /low /b /wait java -enableassertions -Xmx700m -jar ..\bin\mkgmap.jar --process-destination --add-pois-to-areas --pois-to-areas-placement=tagelist --add-pois-to-lines --tdbfile --transparent --make-poi-index --reduce-point-density=2.6 --reduce-point-density-polygon=4 --index --levels=0:24,1:23,2:22,3:21,4:20,5:19,6:18,7:16 --make-poi-index --verbose --route --country-name="%country%" --family-id=%FID% --mapname=66%FID%001 --overview-mapname=66%FID%000 --series-name="OSM-%country%" --family-name="OpenStreetMap: %country%" --style-file=..\bin\styles\ --style=%style% --description="%country%" -c ..\bin\template_basic.args -c template.args %TypFileToAdd%
start /low /b /wait java -enableassertions -Xmx2400m -jar ..\bin\mkgmap.jar>mkgmap.log --link-pois-to-ways --polygon-size-limits="23:15, 22:14, 21:13,20:12,19:11 18:10, 17:9, 16:8, 15:7, 14:6, 13:5, 12:4 ,11:3 10:2, 9:1, 8:0 " --process-exits --keep-going --process-destination --merge-lines --style=default --pois-to-areas-placement=tagelist --tdbfile --transparent --make-poi-index --reduce-point-density=2.6 --reduce-point-density-polygon=4 --index --levels=0:24,1:23,2:22,3:21,4:20,5:19,6:18,7:16 --verbose --route --country-name="%country%" --family-id=%FID% --mapname=66%FID%001 --overview-mapname=66%FID%000 --series-name="OSM-%country%" --family-name="OpenStreetMap: %country%" --style-file=..\bin\styles\ --style=%style% --description="%country%" -c ..\bin\template_basic.args -c template.args %TypFileToAdd%
if EXIST 66%FID%001.img goto :Cleanup
echo.
echo ***********************************************
echo *** SORRY: IMG compiling task has FAILED!!! ***
echo ***********************************************
echo.
goto :END
:Cleanup
if "%debug%" NEQ "no" goto :MSPrepare
del *.gz 2>nul
del *.pbf 2>nul
del areas.list 2>nul
del template.args 2>nul
if EXIST %MSDir% goto :MSPrepare
echo.
echo MapSource Install files not prepared ("%MSDir%" not existing)
goto :END
:MSPrepare
echo.
echo Preparing MapSource Install (.reg)
echo.
copy ..\bin\typ\%typfile% style.typ 2>nul 1>nul
rem preparing MapSource installer registry
echo Windows Registry Editor Version 5.00 > IMG-OSM-%country%_MSInstall.reg
echo. >> IMG-OSM-%country%_MSInstall.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Garmin\Mapsource\Families\IMG-OSM-%country%] >> IMG-OSM-%country%_MSInstall.reg
rem TYPtool <family_id> <product_id> <stylefile>
..\bin\TYPtool %FID% 1 style.typ >> IMG-OSM-%country%_MSInstall.reg
if EXIST style.typ echo "TYP"="%MSDir%\\IMG-OSM-%country%\\style.typ" >> IMG-OSM-%country%_MSInstall.reg
echo. >> IMG-OSM-%country%_MSInstall.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Garmin\Mapsource\Families\IMG-OSM-%country%\1] >> IMG-OSM-%country%_MSInstall.reg
echo "BMAP"="%MSDir%\\IMG-OSM-%country%\\66%FID%000.img" >> IMG-OSM-%country%_MSInstall.reg
echo "LOC"="%MSDir%\\IMG-OSM-%country%" >> IMG-OSM-%country%_MSInstall.reg
echo "TDB"="%MSDir%\\IMG-OSM-%country%\\66%FID%000.tdb" >> IMG-OSM-%country%_MSInstall.reg
rem preparing un-installer registry
echo Windows Registry Editor Version 5.00 > IMG-OSM-%country%_MSUnInstall.reg
echo. >> IMG-OSM-%country%_MSUnInstall.reg
echo [-HKEY_LOCAL_MACHINE\SOFTWARE\Garmin\Mapsource\Families\IMG-OSM-%country%] >> IMG-OSM-%country%_MSUnInstall.reg
:END
cd..
echo.
echo ********************************************
echo *** CreateIMG Script End - Press any key ***
echo ********************************************
if "%1" EQU "" pause >nul