Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
utagawal committed Jun 3, 2023
1 parent c225727 commit fbdd59b
Show file tree
Hide file tree
Showing 140 changed files with 44,171 additions and 0 deletions.
Binary file added __pycache__/get_contours.cpython-39.pyc
Binary file not shown.
62 changes: 62 additions & 0 deletions add_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/python
import sys
import os
import subprocess
from scripts_hgt.get_hgt import get_hgt
from scripts_hgt.hgt_to_osm import hgt_to_osm
from get_contours import get_contours
import os, shutil, fnmatch
import subprocess
import time

country_name=sys.argv[1]
style=sys.argv[2]
url=sys.argv[3]

start_time = time.perf_counter()
country_name_lower_case = country_name.lower().replace(" ", "_")
country_name_upper_case = country_name_lower_case.capitalize()


os.makedirs("dem/"+country_name_lower_case, exist_ok=True)

os.makedirs("carte_"+country_name_lower_case, exist_ok=True)


#Get Id
country_list=[]

#File country
file_in = open("country.txt", "rt")


lines = file_in.readlines()
for line in lines:
result = line.split(";")
country_list.append([result[0],result[1],result[2]])
file_in.close()

id=f'{len(country_list)+1:02d}'


#File country
file_in = open("country.txt", "rt")

file_source = file_in.read()
file_modif = file_source+'\n#'+country_name+';'+id+';'+style+';'+url
file_in.close()

file_out = open("country.txt", "wt")
file_out.write(file_modif)
file_out.close()

print("Start Add country"+country_name+ " "+id+ " "+" "+style,url)

#Get contours
get_contours(country_name, url)

#Launch script
subprocess.run(["bash", "update_map.sh",country_name,id,style,url])
stop_time = time.perf_counter()

print("End Add country in "+time.strftime('%H:%M:%S', time.gmtime(stop_time - start_time)))
24 changes: 24 additions & 0 deletions check_dem_missing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python
import sys
import os
import subprocess
from scripts_hgt.get_hgt import get_hgt
from scripts_hgt.hgt_to_osm import hgt_to_osm
from get_contours import get_contours
import os, shutil, fnmatch
import subprocess
import time
import glob
import pathlib

dirList = os.listdir()

for dir in dirList:
if(dir.startswith("carte_")):
hasFiles=False
for file in pathlib.Path(dir).glob("*.img"):
if(str(file).split("/")[1].startswith("88")):
hasFiles=True
if(hasFiles==False):
print(dir)

7 changes: 7 additions & 0 deletions country.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
France;02;utagawa;https://download.geofabrik.de/europe/france-latest.osm.pbf
#Rhone-Alpes;01;utagawa;https://download.geofabrik.de/europe/france/rhone-alpes-latest.osm.pbf
Suisse;03;utagawa;https://download.geofabrik.de/europe/switzerland-latest.osm.pbf
Italie;04;utagawa;https://download.geofabrik.de/europe/italy-latest.osm.pbf
Belgique;05;utagawa;https://download.geofabrik.de/europe/belgium-latest.osm.pbf
Espagne;06;utagawa;https://download.geofabrik.de/europe/spain-latest.osm.pbf
#Reunion;07;utagawa;https://download.geofabrik.de/europe/france/reunion-latest.osm.pbf
90 changes: 90 additions & 0 deletions create_dem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

start_time="$(date +%s)"
d=`date "+%d.%m.%Y"`

time_task () {
T="$(($(date +%s)-start_time))"
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
time_display=""
if [ $D -gt 0 ];then
time_display="${time_display}${D} days "
fi
if [ $H -gt 0 ];then
time_display="${time_display}${H} hours "
fi
if [ $M -gt 0 ];then
time_display="${time_display}${M} minutes "
fi
time_display="${time_display}${S} seconds "

echo "Finished in ${time_display}"
}

echo "Creation of the map $1 ...."

land=$1
id=$2
type=$3

land_lower=$(echo $land | tr '[:upper:]' '[:lower:]')
land_lower=$(echo $land_lower | tr ' ' _ )
land_without_space=$(echo $land | tr ' ' _ )
file="$land_lower".osm.pbf
poly="$land_lower".poly
type_upper="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"

cd "carte_$land_lower"

name="Map${type_upper} France ${d%%}"
mapname="99$id"
mapname_courbes="88$id"
name_file=Map${type_upper}_${land_without_space}_


count=`ls -1 *.osm.gz 2>/dev/null | wc -l`
if [ $count != 0 ];then
rm *.img
echo "Split contour ...."

java -Xmx32768m -jar ../splitter/splitter.jar --mapid=${mapname_courbes}0000 --max-nodes=1000000 --polygon-file=${poly} --keep-complete=false *.osm.gz

mv template.args courbes.args

echo "Creation of the map courbes ...."
java -Xmx32768m -jar ../mkgmap/mkgmap.jar -c ../options_courbes.args -c courbes.args

rm ${mapname_courbes}*.osm.pbf
rm areas.list
rm areas.poly
rm courbes.args
rm none-areas.poly
rm none-template.args
rm densities-out.txt
rm osmmap.img
rm osmmap.tdb
#rm *.osm.gz
fi


java -Xmx32768m -jar ../mkgmap/mkgmap.jar --mapname=${mapname}0000 --family-id=${mapname} --description="${name}" -c ../options_dem.args --gmapsupp ../style/rando.typ ${mapname_courbes}*.img


rm areas.list
rm areas.poly
rm map.args
rm densities-out.txt
rm osmmap.img
rm osmmap.tdb


dm=`date "+%Y_%m_%d"`

mv -f gmapsupp.img ${name_file}${dm}.img

time_task

cd ..
109 changes: 109 additions & 0 deletions create_map.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash

start_time="$(date +%s)"
d=`date "+%d.%m.%Y"`

time_task () {
T="$(($(date +%s)-start_time))"
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
time_display=""
if [ $D -gt 0 ];then
time_display="${time_display}${D} days "
fi
if [ $H -gt 0 ];then
time_display="${time_display}${H} hours "
fi
if [ $M -gt 0 ];then
time_display="${time_display}${M} minutes "
fi
time_display="${time_display}${S} seconds "

echo "Finished in ${time_display}"
}

echo "Map creation : $1 ...."

land=$1
id=$2
type=$3

land_lower=$(echo $land | tr '[:upper:]' '[:lower:]')
land_lower=$(echo $land_lower | tr ' ' _ )
land_without_space=$(echo $land | tr ' ' _ )
file="$land_lower".osm.pbf
poly="$land_lower".poly
type_upper="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"

cd "carte_$land_lower"

name="Map${type_upper} ${land} ${d%%}"
mapname="77$id"
mapname_courbes="88$id"
name_file=Map${type_upper}_${land_without_space}_


count=`ls -1 *.osm.gz 2>/dev/null | wc -l`
if [ $count != 0 ];then
rm *.img
echo "Split contour ...."

java -Xmx16384m -jar ../splitter/splitter.jar --mapid=${mapname_courbes}0000 --max-nodes=1600000 --polygon-file=${poly} --keep-complete=false *.osm.gz

mv template.args courbes.args

echo "Creation of the map courbes ...."
java -Xmx16384m -jar ../mkgmap/mkgmap.jar -c ../options_courbes.args -c courbes.args

rm ${mapname_courbes}*.osm.pbf
rm areas.list
rm areas.poly
rm courbes.args
rm none-areas.poly
rm none-template.args
rm densities-out.txt
rm osmmap.img
rm osmmap.tdb
rm *.osm.gz
fi


if [ ! -f "${mapname}.osm.pbf" ]; then
echo "***** Split OSM file ...."

java -Xmx16384m -jar ../splitter/splitter.jar --mapid=${mapname}0000 --max-nodes=1600000 --keep-complete=true --route-rel-values=foot,hiking,bicycle --overlap=0 ${file}

mv template.args map.args
fi

echo "***** Compile Garmin img ...."
java -Xmx16384m -jar ../mkgmap/mkgmap.jar -c ../options_${type}.args -c map.args

if [ -f "${mapname_courbes}0000.img" ]; then
java -Xmx16384m -jar ../mkgmap/mkgmap.jar --mapname=${mapname}0000 --family-id=${mapname} --description="UtagawaVTTmap (${name})" -c ../options_${type}.args --gmapsupp ../style/${type}.typ ${mapname}*.img ${mapname_courbes}*.img
else
java -Xmx16384m -jar ../mkgmap/mkgmap.jar --mapname=${mapname}0000 --family-id=${mapname} --description="UtagawaVTTmap (${name})" -c ../options_${type}.args --gmapsupp ../style/${type}.typ ${mapname}*.img
fi

rm ${mapname}*.img
rm ${mapname}*.osm.pbf
rm areas.list
rm areas.poly
rm map.args
rm densities-out.txt
rm osmmap.img
rm osmmap.tdb

rm -f /var/data/garminmaps/UtagawaVTTmap/${land_without_space}/${name_file}*

dm=`date "+%Y_%m_%d"`

mkdir /var/data/garminmaps/UtagawaVTTmap/${land_without_space}

mv -f gmapsupp.img /var/data/garminmaps/UtagawaVTTmap/${land_without_space}/${name_file}${dm}.img

time_task

cd ..
33 changes: 33 additions & 0 deletions download_all_osm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python
import sys
import os
import subprocess
from scripts_hgt.get_hgt import get_hgt
from scripts_hgt.hgt_to_osm import hgt_to_osm
from get_contours import get_contours
import os, shutil, fnmatch
import subprocess
import time

country_list=[]

#File country
file_in = open("country.txt", "rt")

lines = file_in.readlines()
for line in lines:
result = line.split(";")
country_list.append([result[0],result[1],result[2],result[3]])

file_in.close()

for idx, country in enumerate(country_list):
country_name=country[0]
id=country[1]
style=country[2]
url=country[3]
if(not country_name.startswith('#')):
print("Update "+country_name+ " "+id+" "+style+" "+url)
#Launch script
subprocess.run(["bash", "download_osm.sh",country_name,id,style,url])

21 changes: 21 additions & 0 deletions download_osm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
echo "Download of the map $1 ...."

land=$1
id=$2
type=$3
url=$4

land_lower=$(echo $land | tr '[:upper:]' '[:lower:]')
land_lower=$(echo $land_lower | tr ' ' _ )
file="$land_lower".osm.pbf
url_poly=${url//-latest.osm.pbf/.poly}
file_poly="$land_lower".poly

cd "carte_$land_lower"

curl -L -o $file $url

curl -L -o $file_poly $url_poly

cd ..
32 changes: 32 additions & 0 deletions download_require.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# adjust to latest version (see www.mkgmap.org.uk)
MKGMAP="mkgmap-r4836"
SPLITTER="splitter-r645"

if [[ $OSTYPE == 'linux'* ]]; then
sudo apt update
sudo apt upgrade
sudo apt install curl
sudo apt install python3-pip
sudo apt install openjdk-13-jre-headless
sudo apt install unzip
fi

if [ ! -d "mkgmap" ]; then
curl -L -o "mkgmap.zip" "https://www.mkgmap.org.uk/download/${MKGMAP}.zip"
unzip "mkgmap.zip"
rm "mkgmap.zip"
mv ${MKGMAP} mkgmap
fi

if [ ! -d "splitter" ]; then
curl -L -o "splitter.zip" "https://www.mkgmap.org.uk/download/${SPLITTER}.zip"
unzip "splitter.zip"
rm "splitter.zip"
mv ${SPLITTER} splitter
fi

if [ ! -f "sea.zip" ]; then
curl -L -o "sea.zip" "http://osm.thkukuk.de/data/sea-latest.zip"
fi

pip install -r requirements.txt
Loading

0 comments on commit fbdd59b

Please sign in to comment.