summaryrefslogtreecommitdiff
path: root/kmlstitch.sh
diff options
context:
space:
mode:
Diffstat (limited to 'kmlstitch.sh')
-rwxr-xr-xkmlstitch.sh79
1 files changed, 74 insertions, 5 deletions
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