From 88eec1cd640d61c9054985ce374bc5849a833466 Mon Sep 17 00:00:00 2001 From: st33v Date: Sun, 30 Aug 2015 12:22:59 +1000 Subject: might work now --- kmlstitch.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 5 deletions(-) (limited to 'kmlstitch.sh') diff --git a/kmlstitch.sh b/kmlstitch.sh index 21df0bd..5a254a3 100755 --- a/kmlstitch.sh +++ b/kmlstitch.sh @@ -5,21 +5,90 @@ datadir='../data/' echo $datadir +outfile='alltrip.kml' +endheader='' + # Functions ########################## -readKml() +unzipKmz() +{ + echo file is $file + if [ ${file: -4} == ".kmz" ] + then + unzip $file + fi +} + + +extractTrack() { - echo $file + if [ -f doc.kml ] + then # + placelines=$( lineNums placemark doc.kml) + startline=$(echo $placelines | cut -d ' ' -f 1 ) + endline=$(echo $placelines | rev | cut -d ' ' -f 1 | rev) + echo $FUNCNAME + sed -n "${startline},${endline}p" doc.kml >> ${outfile} + echo $FUNCNAME: placelines: $placelines + echo startline: $startline + echo endline $endline + rm doc.kml + fi +} +# + +writeHeader() +{ + if [ -f $outfile ] + then + mv $outfile $outfile.old + fi + + #stopline=$(grep -n $endheader doc.kml | cut -d : -f 1 | head -1) + stopline=$(lineNums $endheader doc.kml | head -1) +echo $FUNCNAME + sed -e ${stopline}q doc.kml > $outfile + echo stopline = $stopline +} + +# return a list of line numbers that match arg1 +lineNums() +{ + match=$1 + file=$2 + grep -ni ${match} ${file} | cut -d : -f 1 +} + +# Add ending tags to kml file + +endKml() +{ + echo "" >> ${outfile} + echo "" >> ${outfile} } ###################################### +# loop through the kml directory -for file in '$datadir'* +count=0 # loop counter + +for file in "$datadir"*.km? do - echo 'file is $file\n' + count=$((count+1)) + echo $count ":" + unzipKmz + if [ $count == 1 ] + then + writeHeader + fi + extractTrack done +endKml +zip ${outfile}.kmz ${outfile} +rm ${outfile} + echo "finished" -ls -f $datadir | while read -r file; do wc "$file"; done +#ls -f $datadir | while read -r file; do wc "$file"; done -- cgit v1.3