Convert gps data from dddmm.mmmmm to dd.mmmm

468 views
Skip to first unread message

Roger

unread,
Oct 1, 2017, 6:31:27 AM10/1/17
to Node-RED
Hi Guys,

Has anyone experience with converting data from ddmm.mmmm to dd.mmmm?
I found a formula that you convert it by dividing by 60
But how to work with a value that starts with a 0?

I hope some one has done this before and can help me out

Thanks!

Colin Law

unread,
Oct 1, 2017, 6:56:25 AM10/1/17
to node...@googlegroups.com
I don't understand what you mean. Are those text strings or numbers?
What are the d and m values, days, months, minutes? Can you give some
examples?

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/fd7cda64-cb2f-4030-b20c-a370f999fab1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Roger

unread,
Oct 1, 2017, 7:00:26 AM10/1/17
to Node-RED
The input is like below:
$GPGGA,222940.00,5204.28330,N,00434.33265,E,1,05,1.20,9.7,M,45.9,M,,*59

the 5204.28330 should be something like 52.071413

I also checked if i can change the output format of the ublox but i cannot change it to what i neede
 
Op zondag 1 oktober 2017 12:31:27 UTC+2 schreef Roger:

Colin Law

unread,
Oct 1, 2017, 7:12:03 AM10/1/17
to node...@googlegroups.com
Oh, degrees and minutes and fractions of minutes, which you want to
convert to degrees and fractions (in which case you meant dd.dddd). Is
that right?

Are you starting with the 5204.28330 as a string "5204.28330" or is it
already converted to a number? It would be easier if you started with
the string, then you can take the first two characters as the degrees,
convert the rest to a number and divide it by 60 and add to the
degrees (having converted that to a number first).

If it is already converted to a number it is a little more complex,
you will have to divide it by 100, take the integer part as the
degrees then take the fractional part and multiply by 100 again to
turn it back to minutes then divide by 60 to make it fractional
degrees and add that to the integer degrees.

Colin

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/78198891-57fd-40d6-9ac1-52b1516944d3%40googlegroups.com.

Roger

unread,
Oct 1, 2017, 8:01:55 AM10/1/17
to Node-RED
The msg.payload : string[73] looks a string to me


"convert the rest to a number and divide it by 60 and add to the 
degrees (having converted that to a number first). "

But what happens the if it starts with a 0? or 2 00?
I guess it is wrong then?

Colin Law

unread,
Oct 1, 2017, 8:30:28 AM10/1/17
to node...@googlegroups.com
Do you mean the string is not always the same length? So it might be
112.3456, meaning 1 degree 2.3mins?

If it is not fixed length then first split it into two strings at the
decimal point (the javascript split() function will do that for you).
Then the last two digits before the point are the integer minutes and
anything before that is degrees. The bit after the point is the
fractional minutes.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/845060b1-0dfa-467b-a531-f8e47c23061d%40googlegroups.com.

Roger

unread,
Oct 1, 2017, 8:41:08 AM10/1/17
to Node-RED
What i mean is is when i have 5204.28330 and i take 52 of then it starts with a 0
When i divide it then by 60 i am missing the 0
Is that correct with the way you described?

Garry Hayne

unread,
Oct 1, 2017, 8:53:48 AM10/1/17
to Node-RED
Hi Roger, the zero is insignificant, you are left with 4.28330 minutes.

Colin Law

unread,
Oct 1, 2017, 9:09:47 AM10/1/17
to node...@googlegroups.com
That is not a problem, you will have the number 4.2833 and when you
divide that by 60 you will get 0.071388 and then when you add that to
the 52 you get 52.071388

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/5e49ccc2-8086-4b78-9014-bbc066b296f4%40googlegroups.com.

Julian Knight

unread,
Oct 1, 2017, 9:21:23 AM10/1/17
to Node-RED
That is an NMEA data string, the specifications for it can be found here: http://aprs.gids.nl/nmea/#gga

The first number is the time: 22:39:40.00 UTC
2nd is the Latitude: 5204.28330,N = 52d 04.28330' N
3rd is the Longitude: 00434.33265,E = 04d 34.33265' E

You were pretty close to sea level there!

You should be able to translate that to JS.

Julian Knight

unread,
Oct 1, 2017, 9:22:45 AM10/1/17
to Node-RED
Or here is an example in JavaScript: https://gist.github.com/fphillips/1861056

Roger

unread,
Oct 1, 2017, 9:24:18 AM10/1/17
to Node-RED
nice, thanks!

Op zondag 1 oktober 2017 15:22:45 UTC+2 schreef Julian Knight:

damo....@gmail.com

unread,
Oct 2, 2017, 1:17:03 AM10/2/17
to Node-RED
Hi Roger,

Something else to consider, depending on your setup, but you could use the GPSd software and a node-red-contrib-gpsd node (written by some hack ;) ), which will do all the data translation conversion for you. 

Damo.

Dave C-J

unread,
Oct 2, 2017, 4:00:26 AM10/2/17
to node...@googlegroups.com
Nice - shame we can't touch gpl3 :-(

damo....@gmail.com

unread,
Oct 2, 2017, 5:36:27 AM10/2/17
to Node-RED
Hey Dave,

Is there a problem with how I have licenced the gpsd node?

D.

Dave C-J

unread,
Oct 2, 2017, 6:04:40 AM10/2/17
to node...@googlegroups.com
No problem other than many corporates (including ours) won't let us use gpl licensed code without jumping through many hoops - which in general makes it easier just to not touch it. So it's "our" problem not "yours", the point people just need to be aware before jumping in.

damo....@gmail.com

unread,
Oct 2, 2017, 7:15:59 AM10/2/17
to Node-RED
Is this a problem for contributed node-red nodes?  Or an issue generally?

I wouldn't think corporations would be interested in something like contrib-gpsd, although I suppose a company may wish to distribute the node as part of a node-red package or product (device).  Is this what you were referring to?

Is it the following restriction of GPLv3 that is the major issue?

Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license.

If so, what about the LGPLv3?  Would this generally be acceptable to corporations?

However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work.

I suppose the only restriction I look for in licensing my code is for those who modify/improve my work to contribute it back. 

Dave, what would suggest as an acceptable copyleft license to corporations, for contributed node-red nodes?

D.

Dave C-J

unread,
Oct 2, 2017, 9:20:34 AM10/2/17
to node...@googlegroups.com
It's not Node-RED specific (other than the current discussion), and indeed probably not a problem for "most" users - just folk need to be aware. We do have users using Node-RED for commercial offerings and they need to satisfy themselves this isn't a problem for them. (and it's not just your node of course .

It's just I have used (raw) gpsd on past projects and it's great and probably the best way to do this sort of thing... (on small linux systems) - as it can do lots of other neat stuff under the covers - so a Node-RED node would be/is a great idea.

Certainly our lawyers are a conservative bunch so the default position for any copy-left is no... as I said we can get exceptional approval if warranted, justified, etc - but it's a arduous process. AKA probably easier to re-write it from scratch if really needed - which isn't really the point. But hey.


steve rickus

unread,
Oct 2, 2017, 10:43:04 AM10/2/17
to Node-RED

Although this string format looks pretty well-defined, I would probably use a regular expression to find the dd and mm.mmmm numbers before the ,N (for latitude) and before the ,E (for longitude). That way, if the order was reversed, the code would not break. Something like this in a function node should work:

var nvals = msg.payload.match(/,(\d+)(\d\d\.\d+),N/);
var evals = msg.payload.match(/,(\d+)(\d\d\.\d+),E/);
msg
.payload = {
    latitude
: (+nvals[1] + nvals[2]/60).toFixed(4),
    longitude
: (+evals[1] + evals[2]/60).toFixed(4)
}
return msg;

Then the downstream nodes can refer to either of these values as msg.payload.latitude or msg.payload.longitude
--
Steve

Mark Setrem

unread,
Oct 2, 2017, 10:58:35 AM10/2/17
to Node-RED
Steve  wouldn't your code break for 3/4's of the planet?  


Amended for the South and West hemispheres 


var nvals = msg.payload.match(/,(\d+)(\d\d\.\d+),(N|S)/);
var evals = msg.payload.match(/,(\d+)(\d\d\.\d+),(E|W)/);

steve rickus

unread,
Oct 2, 2017, 11:07:04 AM10/2/17
to Node-RED
Good catch -- I was not familiar with this type of location format (just based the answer on the sample data), but that looks like it would work..
Any idea if the regex needs to work with negative values? Or is that taken care of by using W vs. E, for instance?

Julian Knight

unread,
Oct 2, 2017, 11:16:03 AM10/2/17
to Node-RED
No point Steve since the NMEA string formats are very well defined and very strict as they have to be given the nature of the devices they work on.
Reply all
Reply to author
Forward
0 new messages