Question

Regex in StringSearcher to extrapolate/separate DMS (in ##° ##' ##.#####" format) for decimal degree conversion

  • 24 July 2018
  • 3 replies
  • 12 views

Badge

I found some help in an earlier post in regards to this (https://knowledge.safe.com/questions/46672/change-degree-minute-seconds-hemisphere-to-decimal.html), but the format of my DMS lat longs is different (I have spaces between the DMS values and my lat/long DMS values are separated). I tried to edit the regex from that post to no avail while trying to extrapolate my latitude DMS values...

(\\d+\\.?\\d*)|([NSEW])

(\\d+\\.? \\d*)|([NSEW])

(\\d+\\.? \\d*)|([NS])

However, my matched parts comes through with just the degrees value and are missing the minutes & seconds values. I will admit that I don't know enough regex!

Here's the details... I have latitude and longitude values stored in separate columns in DMS format (e.g., 27° 54' 32.32124" N or 38° 24' 16" N), and I need to convert them to decimal degrees. The seconds values may have a precision of anywhere from 2-7 with a scale of 0-5. I know I could probably handle this in a more cumbersome way with testers/testfilters and substring extractors, but I'd really like to figure out a regex expression to use in a stringsearcher and then push the matched parts values for degrees, minutes, and seconds to a DecimalDegreesCalculator. This would be a much more elegant conversion to decimal degrees.

Unfortunately I'm running a slightly older (2015) version of FME along with my organization's ArcGIS 10.3 subscription. If anyone has a regex to help make my conversion more elegant, that would be much appreciated!


3 replies

Badge

I'll answer my own question!

Was able to make this work using regex with three string searchers (each searching the lat or long DMS string for the D, M, or S values separately). I'm not certain why I couldn't get the parts list to work with just one string searcher, maybe it's a limitation with my version of FME, oh well.

The regex...

(\\d*)° to extrapolate degrees values

(\\d*)' to extrapolate mins values

(\\d+\\.\\d*)"|(\\d*)" for seconds (accounts for decimal & non-decimal seconds values)

Then the resulting three matched result attributes were pushed to a string replacer to remove the special characters using regex (°|'|"), then they were converted to decimal degrees in an attribute creator with FME math functions...

(@add(@Value(_matched_characters_LAT_D),@div(@Value(_matched_characters_LAT_M),60),@div(@Value(_matched_characters_LAT_S),3600)))

Whew :) I'm sure there's a more elegant way out there, but I feel better for forcing myself to learn regex! If anyone knows of a more elegant way I'm still happy to hear about it!

Userlevel 2
Badge +17

Hi @bwasserstein, have you specified the "Subexpression Matches List Name" parameter? I think every substring that matches the sub expression will be stored in the "_sub{}.part" list, if you set the parameter like this.

0684Q00000ArKcKQAV.png

Also, this regex seems to be better.

(\d+\.?\d*|[NSEW])
Userlevel 2
Badge +17

Hi @bwasserstein, have you specified the "Subexpression Matches List Name" parameter? I think every substring that matches the sub expression will be stored in the "_sub{}.part" list, if you set the parameter like this.

0684Q00000ArKcKQAV.png

Also, this regex seems to be better.

(\d+\.?\d*|[NSEW])
In this case, "All Matches List Name" parameter can also be available, as @david_r suggested in the previous thread.

 

0684Q00000ArMOJQA3.png

 

Reply