Cruisers Forum
 

Go Back   Cruisers & Sailing Forums > Seamanship, Navigation & Boat Handling > OpenCPN
Cruiser Wiki Click Here to Login
Register Vendors FAQ Community Calendar Today's Posts Log in

Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 08-03-2020, 18:57   #1
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
How to Edit (rename and re-sequence) GPX Route Points

I'm doing some route planning with OpenCPN. I've created a number of routes, with dozens to hundreds of route points each. OpenCPN creates these points with sequential names at first, but that leads to two problems:

1) As points are added and deleted, the sequence is broken.

2) Each route has points with many of the same names. Loading these into some chartplotters causes problems.

I export them all to GPX anyway. I could go through and manually edit the GPX files. I could write a script to do that in some programming language. I could use GPS Bable or some other utility to convert to a file format that's easier to edit by hand. But it seems there should be an easier way.

Has anyone else run into this and found a more elegant solution?
CaptTom is offline   Reply With Quote
Old 09-03-2020, 09:20   #2
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 6,008
Re: How to Edit (rename and re-sequence) GPX Route Points

What do you want to happen to waypoint names automatically?
transmitterdan is offline   Reply With Quote
Old 09-03-2020, 11:08   #3
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
Re: How to Edit (rename and re-sequence) GPX Route Points

Quote:
Originally Posted by transmitterdan View Post
What do you want to happen to waypoint names automatically?
OK, sorry I wasn't more specific. My OpenCPN route point names look something like this:

225
001
002
004
006
NM001
007
...
154
NM005
155
001

In this example, I started with the end point from the last route (225), added a bunch in between (001 through 155), deleted some (003, 005), inserted new ones in between (NM001...) and ended with the first point of the next route (001.)

Ideally, I'd want to rename them all, sequentially, with an abbreviation for the route name, followed by sequential numbers (MyRt001, MyRt002, etc.)

The logic in a program to do this is simple. The hard part would be picking a language, downloading an IDE for that language, gathering the routines and sample code to read and write GPX files, studying the examples and building the input/output dialogs. Iterating through the route point names and replacing them with a sequence of new names is trivial, in any language.

So, I figured there must be someone out there who has already done it. But I'm drawing a blank.
CaptTom is offline   Reply With Quote
Old 10-03-2020, 19:22   #4
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
Re: How to Edit (rename and re-sequence) GPX Route Points

I gave up trying to automate this. Here's what I ended up doing:

Set up a macro in my text editor to remove all the OpenCPN GPX extensions, leaving just the needed data under <rtept...>.

Set up a macro to remove the carriage returns and leading blanks on each of these lines, making one line for each route point.

Copied the column of route point names to an Excel worksheet.

Changed the first point to "001". Did a "fill sequential" on the rest of the column.

Added a column to the left with the route abbreviation. Did a "fill down" on the rest of the column.

Copied to two columns to a new file in my text editor.

Removed the tabs between the columns.

Still in the text editor, copied the merged column back over the route names in the original, flattened GPX file.

Opened the flattened and edited GPX file in OpenCPN.

Exported the GPX file back out again, restoring the carriage returns and spaces.

It's a stupid amount of work for such a simple thing, but still easier than writing a new program to read, edit and re-save the GPX file. And really, with macros and the search-and-replace capabilities of a decent text editor, each file took only a minute or less.

I already had the macro to remove all the extensions. It saves a ton of space. I don't know why OpenCPN doesn't have some options for what to include or omit in exported GPX files.

Funny how applications come and applications go, and the technology changes and improves every year, but I still come back to an old-fashioned text editor, to do the same type of thing, decade after decade.
CaptTom is offline   Reply With Quote
Old 11-03-2020, 10:10   #5
Registered User
 
Mirage35's Avatar

Join Date: May 2015
Location: Sailing Lake Ontario
Boat: Mirage 35
Posts: 1,126
Re: How to Edit (rename and re-sequence) GPX Route Points

I can relate. I wanted to convert between GPX and my old chartplotter's non-standard format - actually a bigger job than could be easily handled with a text editor because I wanted to convert tracks as well as routes.

I ended up writing a routine to do it, but that was because I had time on my hands and wanted an excuse to learn Python.
__________________
Beam me up, Scotty. There's no intelligent life down here.
Mirage35 is online now   Reply With Quote
Old 11-03-2020, 13:59   #6
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
Re: How to Edit (rename and re-sequence) GPX Route Points

Quote:
Originally Posted by AnglaisInHull View Post
I can relate. I wanted to convert between GPX and my old chartplotter's non-standard format - actually a bigger job than could be easily handled with a text editor because I wanted to convert tracks as well as routes.

I ended up writing a routine to do it, but that was because I had time on my hands and wanted an excuse to learn Python.
Same here. Long ago I wrote a translation program in (get this!) Visual Basic 3.0. It seems there were always a bunch of different formats for the various equipment I used, and I was always converting between them. Mine was sort of like GPSBabel, but smarter about routes vs. tracks vs. waypoints, since all the different hardware handled those differently (or not at all.)

You'd think now that so many devices use GPX there would be a quick and dirty GPX editing tool out there. Were I still actively coding I'd probably whip one up, but I'm not set up for that any more.
CaptTom is offline   Reply With Quote
Old 16-03-2020, 12:50   #7
Registered User
 
ironman's Avatar

Join Date: Sep 2019
Posts: 66
Re: How to Edit (rename and re-sequence) GPX Route Points

Quote:
Originally Posted by CaptTom View Post
I'm doing some route planning with OpenCPN. Has anyone else run into this and found a more elegant solution?
If you right-click the route and reverse it, it offers to rename the waypoints. This might be just what you want. If you don't mind doing it twice
ironman is offline   Reply With Quote
Old 16-03-2020, 13:54   #8
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
Re: How to Edit (rename and re-sequence) GPX Route Points

Quote:
Originally Posted by ironman View Post
If you right-click the route and reverse it, it offers to rename the waypoints. This might be just what you want. If you don't mind doing it twice
I tried that. But it didn't re-number them in any useful way. It left the oddball names in between (NM001, etc) from inserted points, and it didn't seem to do the rest in any reliable sequence.

It's a good trick though, when you want to connect the start of one route to the finish of another. You can "append" to an existing waypoint, but only onto the end of a route. Reverse it and you can append to the beginning, then reverse it back.
CaptTom is offline   Reply With Quote
Old 17-03-2020, 13:03   #9
Registered User
 
ironman's Avatar

Join Date: Sep 2019
Posts: 66
Re: How to Edit (rename and re-sequence) GPX Route Points

Well I tried this on a Linux and Windows port of OpenCPN 5.0 and it does rename the NM001 waypoint name that is seen in the Route Properties; see attached.

Must say, I have not checked whether this is exactly the same waypoint name that is sent in the NMEA message, but for now I presume so.

Nice trick to prepend a waypoint!
Attached Thumbnails
Click image for larger version

Name:	before.JPG
Views:	73
Size:	65.6 KB
ID:	210777   Click image for larger version

Name:	after.JPG
Views:	93
Size:	63.5 KB
ID:	210778  

ironman is offline   Reply With Quote
Old 17-03-2020, 16:56   #10
Registered User
 
ironman's Avatar

Join Date: Sep 2019
Posts: 66
Re: How to Edit (rename and re-sequence) GPX Route Points

I found out, after doing it a few times in a row, that the non-renaming of the intermediate waypoint sometimes occurs, both on Windows and Linux ports. I can force this non-renaming by checking the box next to the Waypoint Name (which seems to show the waypoint name in the map), but I cannot make it go away by unchecking the box. So I think this is a bug, and now we know it, it ought to be reported. Can you do that?
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	56
Size:	21.2 KB
ID:	210785  
ironman is offline   Reply With Quote
Old 17-03-2020, 18:45   #11
Registered User
 
CaptTom's Avatar

Join Date: Apr 2004
Location: Southern Maine
Boat: Prairie 36 Coastal Cruiser
Posts: 3,116
Re: How to Edit (rename and re-sequence) GPX Route Points

Quote:
Originally Posted by ironman View Post
Well I tried this on a Linux and Windows port of OpenCPN 5.0 and it does rename the NM001 waypoint name that is seen in the Route Properties; see attached.
Wow. I just tried a simple example and it worked for me, too!

That would have saved me a lot of time. But when I tried that before, it didn't work. I reversed twice and still didn't end up with sequentially named waypoints. Maybe there are some conditions under which it doesn't work. I had a lot of pretty complex routes in play at the time.

Plus, I wanted to give the waypoints "real" names, with an abbreviation for the route followed by the sequential number. Many chartplotters and apps won't take multiple routes with identically-named waypoints in different places.

Edit: I confirmed it doesn't work on some of the old un-renamed routes I still had kicking around. Maybe the waypoints have to be in sequential order to start with. Since my routes started at an "old" waypoint from another route, and sometimes combined two or more previous routes, they weren't sequential. The old sequencing and "NM..." waypoints were retained even if I checked the box to re-number them.
CaptTom is offline   Reply With Quote
Old 01-05-2022, 23:35   #12
Registered User

Join Date: Nov 2011
Location: Brisbane Australia
Boat: Fountaine Pajot Belize 43 ft
Posts: 23
Re: How to Edit (rename and re-sequence) GPX Route Points

I am not sure whether this thread gets looked at now 2 year later but I have experienced the same problems identified above. I like to have all me waypoints named in a logical sequence and to have a prefix which is meaningful. So I do that manually through the waypoint properties box. OPENCPN does have the option to resequence waypoints but it only does that for waypoint names that are numbers ie. have no other text as the waypoint.

My suggestion is to have an option to add a prefix to all the waypoints in the route.
Example:
001 002 003 NM005 004 ac006 007
Now add prefix : Input prefix = NME
New list would then be:
NME001 NME002 NME003 NMENM005 NME004 NMEac006 NME007

This does not then require resequencing of the waypoints but simply adds a prefix to make the waypoint name unique.
Would this be possible and how would I request this?

Thank you
GSwannell is offline   Reply With Quote
Old 03-05-2022, 01:16   #13
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 286
Smile Re: How to Edit (rename and re-sequence) GPX Route Points

@GSwannell ... the JavaScript plugin is what you need. You can write a script to rename your routepoints however you wish.

The following script is a starter for you and resequenced all routepoint names prefixed with the first 4 letters of the route name.
I have included some comments (//) to explain what is happening
(It does not take any special action over shared waypoints, should you have them.)

Code:
routeGUIDs = OCPNgetRouteGUIDs();
for (r = 0; r < 2 /*routeGUIDs.length */; r++){	// for each route
	route = OCPNgetRoute(routeGUIDs[r]);
	prefix = route.name.slice(0,5);	// use truncated route name
	for (p = 0; p < route.waypoints.length; p++){ // for each point in route
		route.waypoints[p].markName = prefix + ("000"+ p).slice(-3);
		}
	OCPNupdateRoute(route);
	}
Antipole is offline   Reply With Quote
Old 03-05-2022, 14:14   #14
Registered User

Join Date: Nov 2011
Location: Brisbane Australia
Boat: Fountaine Pajot Belize 43 ft
Posts: 23
Re: How to Edit (rename and re-sequence) GPX Route Points

Hi Antipole,
Fantastic thankyou. I have coding experience so will look into setting up a plugin for this purpose and develop the script. That will save me much time in planning my sailing trips. I currently manually edit every waypoint name to make it unique and meaningful.
Cheers
GSwannell is offline   Reply With Quote
Old 03-05-2022, 14:57   #15
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 286
Re: How to Edit (rename and re-sequence) GPX Route Points

Whoops - when testing that script I made it stop after the second route and forgot to remove that limit.
Second line should be:
Code:
for (r = 0; r < routeGUIDs.length ; r++){	// for each route
Antipole is offline   Reply With Quote
Reply

Tags
enc, route


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thin and thick nuts on propshaft: sequence?? theoleduc Propellers & Drive Systems 58 12-02-2020 09:47
To Rename Or Not Rename A Boat? boatingnewbie Our Community 51 26-08-2018 06:02
Bad Luck to Rename a Boat ? Lovelyr3ta Liveaboard's Forum 40 26-09-2016 03:55
Rename this thread GordMay Families, Kids and Pets Afloat 13 24-01-2006 22:03

Advertise Here


All times are GMT -7. The time now is 08:51.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.