Skip to main content

I receive a text file with latitude and longitude coordinates.

The coordinates are typed in manually by the user using a reasonably similar syntax, although number of decimal places at the minute vary from none to four.

Examples of variation:

latitude: +70°38,91 +63°47 +69°56,426 +69°08,8447

longitude:-51°04 -50°40,5 -51°19,01 -50°52,600 -50°52,9597

How could I use regex to convert the values to decimal degrees?

I don't think you necessarily need to use regex. If you use a stringreplacer to replace the degree with a comma, then an attributesplitter to split the attribute into degrees, minutes and seconds, you can then feed this into the decimaldegreescalculator.

You will need to handle those cases where there are no seconds listed


Have you tried the AttributeReprojector? It might have a way to reproject the coordinates to the wanted syntax.


Hi @karl_zinglersen, how about this?

  1. Split each value at "°" using the AttributeSplitter. The resulting _list{0} contains the value of degrees; _list{1} contains the value of decimal minutes.

  2. Replace comma (,) in the decimal minutes (_list{1}) with the decimal point (.) using the StringReplacer.

  3. Calculate the value in decimal degrees from the list elements using the ExpressionEvaluator with this math expression
@Value(_list{0}) + (@Value(_list{0}) < 0 ? -@Value(_list{1}) : @Value(_list{1})) / 60.0

 Addition] If you are using FME 2014 or earlier, you should add the decimal point to the divisor (60) in the expression. Otherwise, int / int returns an integer (decimal places in the resulting value will be truncated).


While I agree that you can easily do this without resorting to using regex, here's a regex nonetheless ;-)

(-\+\-]?\d+)\D*(e\d,]+)

It will split up the string in two parts, one before and after a non-digit (e.g. the degrees sign or a space).

 Usage:

0684Q00000ArK2aQAF.png

Look for the results in the list _matches{}.part, here's an example for the input string "+69°56,426":

`_matches{0}.part' has value `+69'
`_matches{1}.part' has value `56,426'

It is then easy to send it off to the DecimalDegreesCalculator, if needed.

David


Reply