CSV to GPX to KML Converter (GPS routes, OpenCPN, Google Earth, etc.) [v2.0]

Discuss and share scripts and script files...
Post Reply
FluxTorpedoe
Posts: 855
Joined: 05 Oct 2011 13:15

CSV to GPX to KML Converter (GPS routes, OpenCPN, Google Earth, etc.) [v2.0]

Post by FluxTorpedoe »

#####################
###   CSV to GPX Converter   ###
#####################



❖ DOWNLOAD:
   — Latest version: CSV to GPX to KML Converter v2.0 — 2023-06-26 (publishing date)
   — See below for installation and other instructions.

———————————————————————————

❖ DESCRIPTION:


You’ve traveled and made a logbook, and now…
You want to see your trip on a map in Google Earth (or in OpenCPN and other chart plotters), with info for each waypoint?
Then this is for you.

This script converts Excel-like CSV file with dates and coordinates (and optionally other fields) to a GPS route in GPX format (compatible with OpenCPN and various online plotters), and to KML format (compatible with Google Earth).

This is a "niche" script indeed… But it might attract newcomers to XYplorer: there aren’t many alternatives, and the online converters are less than satisfying (when they work at all).

———————————————————————————

❖ USAGE:
   — Select your CSV file, then run the script
      A GPX file and a KML file with the same base name will be created

   — (opt.) You can also select an already generated GPX file, then run the script
      A KML file with the same base name will be created

———————————————————————————

❖ SCREENSHOT:
   ☛ From CSV source to: ⭢ GPX opened in OpenCPN, and ⭢ KML opened in Google Earth (both with first waypoint details)
2021 - DemoRoute - Workflow.png
2021 - DemoRoute - Workflow.png (735.16 KiB) Viewed 628 times
 
———————————————————————————

❖ CSV REQUIREMENTS:
   • First row:
      — must contain the header name of each column
      including at least (but in any order/position): Date, Latitude, Longitude
         eg   |Date|Latitude|Longitude|   ,   |Date|Time|Latitude|Longitude|Description|...|
   • Columns:
      — must NOT contain   "   or   ;   (except in (opt.) column named "description" or "info")
   • Coordinates:
      — must be fraction of degrees, or degrees and fraction of minutes, but can NOT include seconds
         eg   valid: 32.0323   valid: 32°01.94'   invalid: 32°01'56"

———————————————————————————

❖ NOTES:
   • Waypoints data:
      — Each row containing data for Date, Latitude, and Longitude will be converted into a waypoint
      — Data (if any) in all other columns will be assigned to waypoint description
      — Data (if any) in a column named "Description" or "Info" will be added last to waypoint description,
         and can include line breaks (Alt+Enter), quotes, and semicolons
   • Missing data:
      — Rows with missing date will use date of previous row (i.e. treated as new hour/description of same day)
      — Rows with missing or duplicate latitude/longitude will be considered as new description,
         and appended (after a separator) to the description of the previous waypoint
         (e.g. departure from the same waypoint but on a following day)
   • Coordinates:
      — can use suffix   S / W   or prefix   -   (dash sign) for South / West negative coordinates
      — can use   °   or   *   as the degree separator
      — can use   .   or   ,   as the minute decimal separator
      — may contain   '   or   ’   or nothing as the minute sign
         eg (all valid and equal)   22°16,65' S   or   -22*16.653   or   -22.27750555
      >> Latitudes and longitudes will be converted (if necessary) from regular
         13° 31.88' S   |   167° 20.6900' E
      to GPX/KML compatible format (fraction of degrees)
         -13.53134396   |   167.34484023
   • Date:
      — Dates can use   -   or   /   as the separator
      — Date data with only 6 digits will be considered yy-mm-dd (e.g. 21-03-16)
         If year is supposed to be at the end, use 4 digits dd-mm-yyyy (e.g. 16/03/2021)
      — Date will be used for waypoint name (format customizable at start of script)
      — Date will also be used as first entry of waypoint description (format customizable)
      — Header name of the (optional) time/hour column, if present, must be "Time"
      — Time data can use   h   or   :   as the separator (e.g. 12h00)
   • Other:
      — CSV file name will be used as route name
   • KML:
      — GPX to KML: Only GPX files generated by this script are supported

☛ Anomalies or bugs ?
   There are already several safety belts, but definitely not for everything.
   So if your GPX output isn’t working as expected, please comment with enough details on your source file and intended output.

———————————————————————————

And don't hesitate to post your questions, suggestions, comments...
Hoping some of you might find it useful !

Have a nice day, 8)

      Flux



##########################################################
##########################################################
###############
###    Installation   ###
###############


☛ Download the script (link above) and copy it into XYplorer scripts folder: <xyscripts>

☛ To run it, simply paste the following into the address bar then press ENTER:
::load "CSVtoGPXtoKML.xys";

 
—————————————————————————
v————————— OPTIONAL —————————v


☛ To make it more accessible, it’s advised to add it to your User Defined Commands (UDC), a catalog entry, a button...:

— User Defined Command
   Open the UDC Manage Commands interface (Menu "User > Manage Commands…" or Ctrl+Alt+F9) and select the "Load Script File" category
   Click the "New…" button and select "Add New Command" (or press INS), then fill in the two fields:
   Caption: CSV to GPX to KML Converter
   Script file: CSVtoGPXtoKML.xys
   The script can now be run by clicking on Menu "User > Load Script File > CSV to GPX to KML Converter"

— Catalog
   Right-click in your catalog and click on "Add New Item Here…", then fill in the two fields:
   Caption: CSV to GPX to KML Converter
   Location: ::load "CSVtoGPXtoKML.xys";
   The script can now be run by clicking on the catalog entry "CSV to GPX to KML Converter"

— Button, method 1. Either add    load "CSVtoGPXtoKML.xys";    to "On left click:" of a custom button, or

— Button, method 2. use the following snippet:
   a) Paste    ::snippet;    into the address bar and press ENTER. A text box will open.
   b) Paste the following and press OK. A new button will be created at the right end of your toolbar.

Code: Select all

Snip: CTB 1
  XYplorer 11.60.0207, 05.10.2012 17:30:00
Action
  NewUserButton
Name
  CSV to GPX to KML
Icon
  :hotlist
ScriptL
  load "CSVtoGPXtoKML.xys";
ScriptR
  
FireClick
  1
———————————————————————————

Version 1.6
CSVtoGPX.xys
(12.06 KiB) Downloaded 156 times
Last edited by FluxTorpedoe on 04 Jul 2023 15:25, edited 25 times in total.

FluxTorpedoe
Posts: 855
Joined: 05 Oct 2011 13:15

• CSV to GPX Converter – Changelog •

Post by FluxTorpedoe »

 
• CHANGELOG:

v2.0 — 2023-06-26Download here
+++ Conversion to KML (Google Earth format)
   — Select CSV file > Run script > both GPX file and KML file are generated
   — Select GPX file > Run script > KML file is generated
      (only GPX files generated by this script are supported)
+++ KML / Google Earth fix: Routes are correctly centered on screen, even if crossing longitude -180°
   An inordinate amount of time (and half the script) was dedicated to this! :biggrin:
+ KML: Style of waypoints and route can later be manually edited in KML header
   (id="WaypointStyle"... / id="RouteStyle"...), or by opening the file in Google Earth
+ Selected file path/name are stored before processing (in case user browses during script)
* GPX files are now written in UTF8 _with BOM_

v1.7 — 2023-06-23Download here
+ Coordinates can also be prefixed with - (minus) instead of suffixed with W and S
+ Coordinates can also be in fraction of degrees format (ie 32.0323 instead of 32°01.94')
+*! Generic description column (opt.):
  - Must be named "Description" or "Info" (caps unimportant)
  - Can be placed anywhere (before or after coordinates, etc.)
  + Anyway, will be written at the end of waypoint description,
     after the data all other secondary columns (eg weather, log...)
  + Can contain real multilines (line break: Alt+Enter in Excel), but
     can (still) contain ¶ instead, replaced with new lines in waypoint
  ! Can contain " (quotes)
  ! Can contain ; (semicolon)

v1.6 — 2021-03-16Download here
! If Time (hour) missing, added "12:00" to <time> tag for full GPX compatibility
! Coordinates not computed if half duplicate (same latitude OR longitude)
! 6 digits date not working, now year prefixed with "20"
! Character "&" in description would bug with some plotters, now replaced with "+"

v1.5 — 2021-03-05 (internal)
+ Date and name formatting customizable

v1.0 — 2021-03-02 (internal)
 Initial development
Last edited by FluxTorpedoe on 04 Jul 2023 15:10, edited 3 times in total.

FluxTorpedoe
Posts: 855
Joined: 05 Oct 2011 13:15

Re: CSV to GPX Converter (GPS routes, OpenCPN, etc.) [v1.7]

Post by FluxTorpedoe »

 
#######################
###   CSV to GPX Converter v1.7   ###
#######################



Hi everyone,

Here’s an update with a broader tolerance for the input data, mainly:
+ Coordinates: allow fraction of degrees, minus prefix, and * instead of °
   ⇒ All following coordinates are valid and equal
      22°16,65' S   ,   -22*16.653   ,   -22.27750555
+ Enhanced dedicated description column (named "description" or "info")
  can include line breaks (Alt+Enter in Excel), and symbols   "   and   ;

Full list available in • CSV to GPX Converter – Changelog •.
More details available in first post.


Have a nice day! 8)
   Flux

———————————————————————————

• DOWNLOAD:   (previous versions available in Changelog)
CSVtoGPX.xys
(15.08 KiB) Downloaded 26 times
 
• INSTALLATION:
 — Please refer to first post

• UPDATE:
 — Overwrite your existing "CSVtoGPX.xys" file with latest version

———————————————————————————

• CHANGELOG:
Don’t hesitate to browse the exhaustive changelog (with download links to previous versions) here: • CSV to GPX Converter – Changelog •

FluxTorpedoe
Posts: 855
Joined: 05 Oct 2011 13:15

Re: CSV to GPX to KML Converter (GPS routes, OpenCPN, Google Earth, etc.) [v2.0]

Post by FluxTorpedoe »

 
#######################
###   CSV to GPX Converter v2.0   ###
#######################



Hi everyone,

Here’s a major update which now also converts to Google Earth KML format:
   — Select CSV file > Run script > both GPX file and KML file are generated
   — Select (an already generated) GPX file > Run script > KML file is generated

:!!: NOTE: The script is now called CSVtoGPXtoKML

Full changelog available in • CSV to GPX Converter – Changelog •.
More details available in first post.


❖ Trifling tidbit :maf: :
   — There’s a bug (!) in Google Earth: In some cases, opening a route that crosses longitude -180° will center the view on its opposite (around 0°)
      So this script includes a function that computes the average (mean, not median) of all longitudes, to find the correct center.
      Not so complex in the end, but a bit trickier than one might think, so I thought it worth mentioning. ;)


Have a nice day! 8)
   Flux

———————————————————————————

• DOWNLOAD:   (previous versions available in Changelog)
CSVtoGPXtoKML.xys
(23.15 KiB) Downloaded 30 times
 
• INSTALLATION:
 — Please refer to first post

• UPDATE:
 — Remove your existing "CSVtoGPX.xys" file
 — Rename your entries (in UDC, Catalog, Button…) from CSVtoGPX to CSVtoGPXtoKML

———————————————————————————

• CHANGELOG:
Don’t hesitate to browse the exhaustive changelog (with download links to previous versions) here: • CSV to GPX Converter – Changelog •

Post Reply