How to extract coordinates (deg,min,sec) from a string?

Hey there.

I have this data in which the “Long-Lat” column consists of a string of coordinates in degrees, minutes and seconds. I need to extract just the numbers/values of these coordinates for analysis. Is there any way of doing so?

Sample: [Long 29° 13’ 36.8 E Lat 25° 51’ 21 S ]

Thanks

I think given the number of figures you want to capture, using RegEx would be an option. I’m not a RegEx master, but here’s a pattern I got to work with your sample data:

.\w{4}\s(\d{2,3}).\s(\d{2,3}).\s(\d{2,3}.\d|\d{2,3})\s(\w)\s\w{3}\s(\d{2,3}).\s(\d{2,3}).\s(\d{2,3}.\d|\d{2,3})\s(\w).*

You can this as the “Pattern” in the Regex Split node and it will put your degrees, minutes, seconds, and direction all in separate cells and then you can recombine them depending on what you want to do next.

4 Likes

This is amazing.! Thanks a lot. I really have to ask, how did you manage to come up with the RegEx pattern for this problem?

Regards

Glad it’s working for you! I used RegEx101.com to work through it. It’s a nice site to input your target data and try different Regex patterns until you find one that works. It also has lots of documentation on what each of the tokens mean, so it’s helpful to learn!

1 Like

Hey,

So I tried the above pattern in the splitter but it couldn’t split some of the data. Attaching sample data and a picture below of the same.

Sample:
[Long 29° 15’ 50.4 E Lat 25° 53’ 5.4 S ]
[Long 29° 15’ 50.5 E Lat 25° 53’ 6.5 S ]
[Long 29° 15’ 50.2 E Lat 25° 53’ 7.6 S ]
[Long 29° 15’ 50.8 E Lat 25° 53’ 8.3 S ]

Regards

Try this one:
.\w{4}\s(\d{1,3}).\s(\d{1,3}).\s(\d{1,3}.\d|\d{1,3})\s(\w)\s\w{3}\s(\d{1,3}).\s(\d{1,3}).\s(\d{1,3}.\d|\d{1,3})\s(\w).*

The missing values have extra decimal point or had a single digit for before the decimal place and the pattern wasn’t matching. The tough part of Regex is if the entire string doesn’t match the pattern nothing will work. :man_shrugging:

3 Likes

Hey…!
This one worked just fine! All the rows got split perfectly.! Thank you so much for the help…!

Regards,
Aayush

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.