11 while getopts "rDo:d:" FLAG
; do
14 d
) DATABASE_FILE
=$OPTARG ;;
15 o
) OSM_FILE
=$OPTARG ;;
21 if [[ $NEW = 1 ]] ; then
22 rm -f ${DATABASE_FILE}
23 sqlite3
${DATABASE_FILE} < ${ROOT}/create_database.sql
26 # TODO check if file is bzipped and unzip it
28 # TODO check if pv is not installed and use cat instead
30 pv
-N "extracting from osm" ${OSM_FILE} | python
${ROOT}/osm2tsvs.py
32 if [[ $DUPE = 1 ]] ; then
33 sqlite3
${DATABASE_FILE} < ${ROOT}/create_tmp_database.sql
36 function import_file
() {
40 ( pv
-N "importing $TABLE" ${TABLE}.tsv.gz | zcat
> fifo
) &
41 if [[ $DUPE = 0 ]] ; then
42 if [[ $NEW = 1 ]] ; then
43 echo -e ".separator \"\\\t\"\n.import fifo $TABLE" | sqlite3
${DATABASE_FILE}
44 elif [[ $NEW = 0 ]] ; then
45 echo -e "create table tmp_${TABLE} as select * from ${TABLE} limit 0;\n.separator \"\\\t\"\n.import fifo tmp_$TABLE\ninsert or replace into ${TABLE} select * from tmp_${TABLE};" | sqlite3 ${DATABASE_FILE}
47 elif [[ $DUPE = 1 ]] ; then
48 echo -e ".separator
\"\\\t\"\n.import fifo tmp_
$TABLE" | sqlite3 ${DATABASE_FILE}
50 echo "removing duplicates from
$TABLE...
"
51 sqlite3 ${DATABASE_FILE} "insert or ignore into ${TABLE} select * from tmp_${TABLE};"
65 import_file relation_tags
66 import_file relation_members
68 rm -f nodes.tsv.gz node_tags.tsv.gz ways.tsv.gz way_tags.tsv.gz way_nodes.tsv.gz relations.tsv.gz relation_tags.tsv.gz relation_members.tsv.gz fifo
70 if [[ $DUPE = 1 ]] ; then
71 sqlite3
${DATABASE_FILE} "drop table tmp_nodes;"
72 sqlite3
${DATABASE_FILE} "drop table tmp_node_tags;"
73 sqlite3
${DATABASE_FILE} "drop table tmp_ways;"
74 sqlite3
${DATABASE_FILE} "drop table tmp_way_tags;"
75 sqlite3
${DATABASE_FILE} "drop table tmp_way_nodes;"
76 sqlite3
${DATABASE_FILE} "drop table tmp_relations;"
77 sqlite3
${DATABASE_FILE} "drop table tmp_relation_tags;"
78 sqlite3
${DATABASE_FILE} "drop table tmp_relation_members;"
81 sqlite3
${DATABASE_FILE} "VACUUM;"