Powershell script: TomTom XML omzetten naar Google Earth KML
# --------------------
# Script: xmlkml.ps1
# Auteur: M. Stam
# Datum: 8-7-2010
# --------------------
<#
.SYNOPSIS
Dit script zet TomTom Triplog XML bestanden om naar KML bestanden welke ingevoerd kunnen worden in Google Earth.
Bovendien zet het de datum en tijden, welke in de XML bestanden genoteerd zijn als Unix Epoch time, om naar UTC datetime.
Het script maakt gebruik van Microsoft Logparser 2.2 welke is te downloaden via:
http://www.microsoft.com/download/en/details.aspx?id=24659
.DESCRIPTION
Een voorbeeld van een TomTom Triplog XML bestand:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gpstrace xmlns="http://www.tomtom.com/traffic/gpstrace/1/0" version="1.0">
<metadata>
<organisation>none</organisation>
<use>internal</use>
<device manufacturingDateUtc="0" buildNo="0000" software="0000">XX</device>
<horizontalResolution>1</horizontalResolution>
<verticalResolution>1</verticalResolution>
<reportInterval>5</reportInterval>
</metadata>
<seq>
<pos>
<lat>52.71118</lat>
<lon>5.26687</lon>
<utc>1288428366000</utc>
<acc>2.0</acc>
<alt>46.0</alt>
</pos>
..........
.EXAMPLE
./xmlkml.ps1 -xmlpath c:\mijnmap\
.NOTES
Indien dit script niet werkt ga je met de command line (dosbox) gaan naar de folder waarin LogParser geïnstalleerd is,
b.v. C:\Program Files (x86)\Log Parser 2.2 en vervolgens het volgende commando invoeren:
regsvr32 LogParser.dll
.LINK
http://www.twitter.com/digistam
#>
while ($xmlpath -lt 1) { $xmlpath = read-host "voer de map met XML bestanden in"}
while (!(Test-Path $xmlpath)) { $xmlpath = read-host "De map met XML bestanden bestaat niet, voer het juiste pad in" }
$objlogparser = new-object -com msutil.logquery
$objinputformat = new-object -com msutil.logquery.xmlinputformat
$objinputformat.fmode = "tree"
$objoutputformat = new-object -com MSUtil.LogQuery.TemplateOutputFormat
$objoutputformat.tpl = "c:\temp\gpstemplate.tpl"
ForEach ($file in Get-ChildItem $xmlpath)
{
write-host 'het bestand' $file.name 'wordt nu omgezet';
$newfile = $file.basename + '.kml'
$query = "select lat,lon,to_timestamp(add(to_int(substr(to_string(utc2),0,10)),to_int(timestamp('1970','yyyy')))) as datum into $xmlpath\$newfile from $xmlpath\$file where lat IS NOT null"
$objlogparser.executebatch($query,$objinputformat,$objoutputformat)
write-host 'het bestand' $newfile 'is gereed en geplaatst in dezelfde folder als het XML bestand'
write-host ' ';
}
# Script: xmlkml.ps1
# Auteur: M. Stam
# Datum: 8-7-2010
# --------------------
<#
.SYNOPSIS
Dit script zet TomTom Triplog XML bestanden om naar KML bestanden welke ingevoerd kunnen worden in Google Earth.
Bovendien zet het de datum en tijden, welke in de XML bestanden genoteerd zijn als Unix Epoch time, om naar UTC datetime.
Het script maakt gebruik van Microsoft Logparser 2.2 welke is te downloaden via:
http://www.microsoft.com/download/en/details.aspx?id=24659
.DESCRIPTION
Een voorbeeld van een TomTom Triplog XML bestand:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gpstrace xmlns="http://www.tomtom.com/traffic/gpstrace/1/0" version="1.0">
<metadata>
<organisation>none</organisation>
<use>internal</use>
<device manufacturingDateUtc="0" buildNo="0000" software="0000">XX</device>
<horizontalResolution>1</horizontalResolution>
<verticalResolution>1</verticalResolution>
<reportInterval>5</reportInterval>
</metadata>
<seq>
<pos>
<lat>52.71118</lat>
<lon>5.26687</lon>
<utc>1288428366000</utc>
<acc>2.0</acc>
<alt>46.0</alt>
</pos>
..........
.EXAMPLE
./xmlkml.ps1 -xmlpath c:\mijnmap\
.NOTES
Indien dit script niet werkt ga je met de command line (dosbox) gaan naar de folder waarin LogParser geïnstalleerd is,
b.v. C:\Program Files (x86)\Log Parser 2.2 en vervolgens het volgende commando invoeren:
regsvr32 LogParser.dll
.LINK
http://www.twitter.com/digistam
#>
while ($xmlpath -lt 1) { $xmlpath = read-host "voer de map met XML bestanden in"}
while (!(Test-Path $xmlpath)) { $xmlpath = read-host "De map met XML bestanden bestaat niet, voer het juiste pad in" }
$objlogparser = new-object -com msutil.logquery
$objinputformat = new-object -com msutil.logquery.xmlinputformat
$objinputformat.fmode = "tree"
$objoutputformat = new-object -com MSUtil.LogQuery.TemplateOutputFormat
$objoutputformat.tpl = "c:\temp\gpstemplate.tpl"
ForEach ($file in Get-ChildItem $xmlpath)
{
write-host 'het bestand' $file.name 'wordt nu omgezet';
$newfile = $file.basename + '.kml'
$query = "select lat,lon,to_timestamp(add(to_int(substr(to_string(utc2),0,10)),to_int(timestamp('1970','yyyy')))) as datum into $xmlpath\$newfile from $xmlpath\$file where lat IS NOT null"
$objlogparser.executebatch($query,$objinputformat,$objoutputformat)
write-host 'het bestand' $newfile 'is gereed en geplaatst in dezelfde folder als het XML bestand'
write-host ' ';
}
Inhoud van het templatebestand (c:\temp\gpstemplate.tpl):
<LPHEADER><?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.google.com/earth/kml/2">
<Document>
<name>GPS posities</name>
</LPHEADER>
<LPBODY><Placemark>
<name>%datum%</name>
<description><![CDATA[ ]]></description>
<Point>
<coordinates>%lon%,%lat%,0</coordinates>
</Point>
</Placemark>
</LPBODY>
<LPFOOTER>
</Document>
</kml></LPFOOTER>
Recent Comments