diff options
| author | st33v <github@f3rr3t.com> | 2015-08-30 12:22:59 +1000 |
|---|---|---|
| committer | st33v <github@f3rr3t.com> | 2015-08-30 12:22:59 +1000 |
| commit | 88eec1cd640d61c9054985ce374bc5849a833466 (patch) | |
| tree | d4de0ed7845813c6d004f045983c61b99db5213e | |
| parent | 49afaea7a8bd4cd4bc661e56c0af8af47ccbc35d (diff) | |
might work now
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | kmlStich.sh | 6 | ||||
| -rwxr-xr-x | kmlstitch.sh | 79 |
3 files changed, 75 insertions, 12 deletions
@@ -1,2 +1,2 @@ # kmlstich -Shell script that concatenates a set of mkl (or kmz) route files into a single file. +Shell script that concatenates a set of kml (or kmz) route files into a single file. diff --git a/kmlStich.sh b/kmlStich.sh deleted file mode 100644 index 5cc18e0..0000000 --- a/kmlStich.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Shell script to stitch kml files together. -# SJP August 2015 - -# name the data directory -datadir='../data/' -echo $datadir 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='<name>' + # 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 "</Document>" >> ${outfile} + echo "</kml>" >> ${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 |
