leos Posted February 27, 2009 Posted February 27, 2009 If you are a GPS fun and have a Garmin device, probably you want to take some GPS info out of Google Earth GE and loat it into the GPS. You can make some paths and placemarks in GE, save them as a kml file, and convert that info to GPX format usable with Garmin MapSource with this script. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Fileversion=v.1.0 #AutoIt3Wrapper_Res_LegalCopyright=©2009 Leontin Suteu #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: Suteu Leontin leos at rdslink.ro © decembrie2008.. last update: 19.12.2008 Function EN: converting kml (Google Earth) to gpx (GPS Exchange, Garmin MapSource)files Functia RO: converteste informatiile GPS din formatul KML in format GPX #ce ---------------------------------------------------------------------------- Global $fisier, $hFisier, $linia, $sPlacemark, $sCoordTrack = "", $sCoordWpoint = "" Global $minLat = 90, $minLon = 180, $maxlat = 0, $maxLon = 0 Global $nrWpoint = 0, $nrTrack = 0, $rezultat, $eroare citFisKml() salvFisGpx() Exit ;-------------------------------------------------------------- Func citFisKml() $fisier = FileOpenDialog("Choose kml file", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "GoogleEarth files (*.kml)") $hFisier = FileOpen($fisier, 0) If $hFisier = -1 Then afiseroare(1, True) While 1 ; main loop for reading kml file $linia = FileReadLine($hFisier) If @error = -1 Then ExitLoop If StringInStr($linia, "<Placemark>", 0) > 0 Then procesPlace() WEnd FileClose($hFisier) MsgBox(64, "Ready", "Found " & $nrTrack & " tracks and " & $nrWpoint & " wpoints", 5) EndFunc ;==>citFisKml ;-------------------------------------------------------------- Func salvFisGpx(); writes gpx file Local $sFisierGpx, $eroare, $rezultat $sFisierGpx = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>' & @CRLF $sFisierGpx &= '<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="GE2Gpx" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">' & @CRLF $sFisierGpx &= '<metadata>' & @CRLF $sFisierGpx &= '<bounds minlat="' & $minLat & '" minlon="' & $minLon & '" maxlat="' & $maxlat & '" maxlon="' & $maxLon & '"/>' & @CRLF $sFisierGpx &= '</metadata>' & @CRLF & @CRLF $sFisierGpx &= $sCoordWpoint ; adding waypoints $sFisierGpx &= $sCoordTrack ; adding tracks $sFisierGpx &= '</gpx>' ; end mark for gpx file $eroare = True While $eroare $fisier = FileSaveDialog("Choose the file to save to", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "GPS Exchange files(*.gpx)") If StringInStr($fisier, ".gpx", 0) = 0 Then $fisier &= ".gpx" $hFisier = FileOpen($fisier, 2) If $hFisier = -1 Or $fisier = "" Then afiseroare(3, False) $eroare = True Else $rezultat = FileWrite($hFisier, $sFisierGpx) $eroare = False EndIf If $rezultat = 0 And $eroare Then afiseroare(4, False) Else MsgBox(0, "Googleearth to GPX ©2008 Leontin Suteu", "GPX data is ready " & $fisier) EndIf WEnd FileClose($hFisier) EndFunc ;==>salvFisGpx ;-------------------------------------------------------------- Func procesPlace() $sPlacemark = "" $sPlacemark &= $linia ;reading the file till we get a line with "</Placemark>" While 1 If StringInStr($linia, "</Placemark>", 0) Then ExitLoop $linia = FileReadLine($hFisier) $sPlacemark &= $linia WEnd ; now $sPlacemark variable will contain data about the waypoint/track StringStripCR($sPlacemark) ;stripping any "carriage return" codes Select Case StringInStr($sPlacemark, "<Point>", 0) > 0 ;it is a wpoint procesWpoint() Case StringInStr($sPlacemark, "<LineString>", 0) > 0 ;it is a track procesTrack() EndSelect EndFunc ;==>procesPlace ;-------------------------------------------------------------- ; processing wpoints Func procesWpoint() Local $sCoordonate = "", $nume, $lim1, $lim2, $coordonate[4], $lon, $lat, $alt $lim1 = StringInStr($sPlacemark, "<name>", 0); wpoint name $lim2 = StringInStr($sPlacemark, "</name>", 0) If $lim1 = 0 Or $lim2 = 0 Then afiseroare(2, True) $nume = StringMid($sPlacemark, $lim1 + 6, $lim2 - $lim1 - 6) $lim1 = StringInStr($sPlacemark, "<coordinates>", 0) ; coordinates string $lim2 = StringInStr($sPlacemark, "</coordinates>", 0) If $lim1 = 0 Or $lim2 = 0 Then afiseroare(2, True) $sCoordonate = StringMid($sPlacemark, $lim1 + 13, $lim2 - $lim1 - 13) StringStripWS($sCoordonate, 1) ; stripping spaces StringStripWS($sCoordonate, 2) $coordonate = StringSplit($sCoordonate, ",") $lon = $coordonate[1] $lat = $coordonate[2] $alt = $coordonate[3] If $lon > $maxLon Then $maxLon = $lon If $lon < $minLon Then $minLon = $lon If $lat > $maxlat Then $maxlat = $lat If $lat < $minLat Then $minLat = $lat $sCoordWpoint &= '<wpt lat="' & $lat & '" lon="' & $lon & '">' & @CRLF $sCoordWpoint &= '<time>' & @YEAR & "-" & @MON & "-" & @MDAY & "T" & @HOUR & ":" & @MIN & ":" & @SEC & '</time>' & @CRLF $sCoordWpoint &= '<name>' & $nume & '</name>' & @CRLF $sCoordWpoint &= '<cmt></cmt><desc></desc>' & @CRLF $sCoordWpoint &= '<sym>Circle with X</sym>' & @CRLF $sCoordWpoint &= '<extensions><gpxx:WaypointExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"><gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode></gpxx:WaypointExtension></extensions>' & @CRLF $sCoordWpoint &= '</wpt>' & @CRLF & @CRLF $nrWpoint += 1 EndFunc ;==>procesWpoint ;-------------------------------------------------------------- ; processing track section Func procesTrack() Local $sCoordonate = "", $nume, $lim1, $lim2, $i, $coordonate[4], $lon, $lat, $alt $lim1 = StringInStr($sPlacemark, "<name>", 0); track name $lim2 = StringInStr($sPlacemark, "</name>", 0) If $lim1 = 0 Or $lim2 = 0 Then afiseroare(2, True) $nume = StringMid($sPlacemark, $lim1 + 6, $lim2 - $lim1 - 6) $lim1 = StringInStr($sPlacemark, "<coordinates>", 0) ; coordinates string $lim2 = StringInStr($sPlacemark, "</coordinates>", 0) If $lim1 = 0 Or $lim2 = 0 Then afiseroare(2, True) $sCoordonate = StringMid($sPlacemark, $lim1 + 13, $lim2 - $lim1 - 13) StringStripWS($sCoordonate, 1) StringStripWS($sCoordonate, 2) $puncte = StringSplit($sCoordonate, " ") $sCoordTrack &= '<trk>' & @CRLF $sCoordTrack &= '<name>' & $nume & '</name>' & @CRLF $sCoordTrack &= '<trkseg>' & @CRLF For $i = 1 To $puncte[0] - 1 $coordonate = StringSplit($puncte[$i], ",") $lon = Number($coordonate[1]) $lat = Number($coordonate[2]) $alt = $coordonate[3] If $lon > $maxLon Then $maxLon = $lon If $lon < $minLon Then $minLon = $lon If $lat > $maxlat Then $maxlat = $lat If $lat < $minLat Then $minLat = $lat $sCoordTrack &= '<trkpt lat="' & $lat & '" lon="' & $lon & '"><ele>' & $alt & '</ele></trkpt>' & @CRLF Next $sCoordTrack &= '</trkseg>' & @CRLF $sCoordTrack &= '</trk>' & @CRLF & @CRLF $nrTrack += 1 EndFunc ;==>procesTrack ;-------------------------------------------------------------- ; functia de tratare a erorilor ; error processing Func afiseroare($cod, $iesire) Switch $cod Case 1 MsgBox(48, "Error", "Can not open kml file") Case 2 MsgBox(48, "Error", "Bad kml file") Case 3 MsgBox(48, "Error", "Can not open gpx file") Case 4 MsgBox(48, "Error", "Can not write file " & $fisier) EndSwitch If $iesire Then Exit EndFunc ;==>afiseroare ;--------------------------------------------------------------
Andreik Posted February 27, 2009 Posted February 27, 2009 I have a Garmin GPS, I will try it tomorrow. PS: ma bacur sa vad un roman inteligent pe aici
DaRam Posted February 27, 2009 Posted February 27, 2009 I have an older C550. Do I need to install the Garmin supplied software to transfer the gpx file or can I just copy it to SD card and use?I have a Garmin GPS, I will try it tomorrow. PS: ma bacur sa vad un roman inteligent pe aici
HeffeD Posted February 27, 2009 Posted February 27, 2009 Haven't had a chance to give this a try yet, but very cool idea for a script!
Andreik Posted February 28, 2009 Posted February 28, 2009 I have an older C550. Do I need to install the Garmin supplied software to transfer the gpx file or can I just copy it to SD card and use?I don't use any kind of software. Just copy the file.
ReFran Posted February 28, 2009 Posted February 28, 2009 (edited) Perhaps someone looking here is also interested in a free online converter:http://www.gpsies.com/convert.do;jsessioni...37C50C1C141D51EFormats wich can be converted from to:Google Earth (KML und KMZ), PCX5 Tracks und Waypoints, GPX Tracks, Routen und Waypoints, GPX für Garmin Streetpilot, Garmin Course (CRS und TCX), GeoRSS, Logbook, NMEA, OVL (ASCII), Fugawi, KOMPASS Verlag (Alpenverein), Navigon Route, OziExplorer, qpeGps Track, MagicMaps IKT, TomTom ITN, Suunto SDF, Magellan Track, PathAway.It's in German, but easy to understand. If someone want to write a GUI for that I can help.Hope it doesn't dirsturb here.Best regards, ReinhardJust saw, english also available beside many other languages. Here the english address: http://www.gpsies.com/convert.do Edited February 28, 2009 by ReFran
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now