#!/bin/bash
osm3s_query_path=/home/overpass/osm3s/bin/osm3s_query
basemap_source_dir=/mnt/home-hdd/basemap/gen_basemap_source/source
utilities_path=/mnt/home-hdd/jenkins-workspace/Maps_GenerateBasemap/tools/OsmAndMapCreator/utilities.sh
regions_path=regions.ocbf

curl -fSL https://github.com/osmandapp/OsmAnd-resources/raw/master/countries-info/regions.ocbf > regions.ocbf

##sed 's/<relation/<relation version="1" timestamp="2009-02-13T18:27:08Z"/g' $basemap_source_dir/motorways_flt.osm | sed 's/<way/<way version="1" timestamp="2009-02-13T18:27:08Z"/g' | sed 's/<node/<node version="1" timestamp="2009-02-13T18:27:08Z"/g' > $basemap_source_dir/motorways_flt2.osm && mv -f $basemap_source_dir/motorways_flt2.osm $basemap_source_dir/motorways_flt.osm
##osmosis --read-xml file=$basemap_source_dir/motorways_flt.osm --simplify-ways epsilonMeters=1000 --write-xml file=$basemap_source_dir/motorways_flt_simplified.osm
#~/utilites/osmosis/bin/osmosis --read-xml $basemap_source_dir/motorways_flt_simplified.osm --un --wx $basemap_source_dir/motorways_flt_simplified_no_nodes.osm
##mv -f $basemap_source_dir/motorways_flt_simplified_no_nodes.osm $basemap_source_dir/motorways_flt.osm

function process_highways {
	cat queries/$1.txt | $osm3s_query_path > $basemap_source_dir/$1.osm
	osmfilter $basemap_source_dir/$1.osm --keep-tags="all highway=$1 name*= ref*= int_ref= network= modifier=" -o=$basemap_source_dir/${1}_flt.osm
	mv -f $basemap_source_dir/${1}_flt.osm $basemap_source_dir/$1.osm
#	bash $utilities_path generate-region-tags $basemap_source_dir/$1.osm $basemap_source_dir/$1_regions.osm $regions_path
#	mv -f $basemap_source_dir/${1}_regions.osm $basemap_source_dir/$1.osm
}
function process_query {
	echo Querying $1
	cat queries/$1.txt | $osm3s_query_path > $basemap_source_dir/$1.osm
}

#process_highways motorway
#process_highways trunk
#process_highways primary
#process_highways secondary
#process_highways tertiary_1

#cat queries/query_other_ways.txt | $osm3s_query_path > $basemap_source_dir/other_ways.osm
#cat queries/query_route_road.txt | $osm3s_query_path > $basemap_source_dir/route_road.osm
#cat queries/query_water_1.txt | $osm3s_query_path > $basemap_source_dir/water_1.osm

process_query water_2
# cat queries/water_2.txt | $osm3s_path > $basemap_source_dir/water_2.osm
# cat queries/water_3.txt | $osm3s_path > $basemap_source_dir/water_3.osm
# cat queries/water_4.txt | $osm3s_path > $basemap_source_dir/water_4.osm
# cat queries/water_5.txt | $osm3s_path > $basemap_source_dir/water_5.osm
# cat queries/water_6.txt | $osm3s_path > $basemap_source_dir/water_6.osm
# cat queries/water_7.txt | $osm3s_path > $basemap_source_dir/water_7.osm
# cat queries/water_8.txt | $osm3s_path > $basemap_source_dir/water_8.osm
# cat queries/water_9.txt | $osm3s_path > $basemap_source_dir/water_9.osm
# cat queries/water_10.txt | $osm3s_path > $basemap_source_dir/water_10.osm
# cat queries/water_11.txt | $osm3s_path > $basemap_source_dir/water_11.osm
# cat queries/water_12.txt | $osm3s_path > $basemap_source_dir/water_12.osm
# cat queries/water_13.txt | $osm3s_path > $basemap_source_dir/water_13.osm
# cat queries/water_14.txt | $osm3s_path > $basemap_source_dir/water_14.osm
# cat queries/water_15.txt | $osm3s_path > $basemap_source_dir/water_15.osm
# cat queries/water_16.txt | $osm3s_path > $basemap_source_dir/water_16.osm
# cat queries/water_17.txt | $osm3s_path > $basemap_source_dir/water_17.osm
# cat queries/water_18.txt | $osm3s_path > $basemap_source_dir/water_18.osm
