Extract Latitude and Longitude from given String

Hi All,

Can anyone please suggest me how to get the latitude and longitude from the string.

Latitudes and Longitudes may be separated by space or /.

Case-1: -89.74589501 145.52147876
Case-2: -89.74589501/145.52147876.

Example:- This is a text containing coordinates of 15.78 phase. Please check the co-ordinates -89.74589501 145.52147876.

hope this expression would help you resolve this
str_latitude = IF(str_input.Contains("/"),Split(str_input,"/")(1).ToString,Split(str_input," ")(1).ToString)
str_longitude = IF(str_input.Contains("/"),Split(str_input,"/")(0).ToString,Split(str_input," ")(0).ToString)

Cheers @Shivaraju

1 Like

Thanks @Palaniyappan for your quick reply

You are checking the co-ordinates with “/”, but in some cases latitudes and longitudes may differ with space.
Please check it and provide me a solution.

Hi,
you can use the following regex to get both separated.
\s([0-9.-])(\s|/)([0-9.-])

1 Like

yah this expression does the same
it will look for / in the string input, if its not there then it would split them with space
kindly try this and let know for any queries or clarification

Cheers @Shivaraju

2 Likes

@Palaniyappan,
Please use the below string to get the co-ordinates from it.
Example 1:- This is a text containing coordinates of 15.78 phase. Please check the co-ordinates -89.74589501 145.52147876.
Example 2:- This is a text containing coordinates of 15.78 phase. Please check the co-ordinates -89.74589501/145.52147876.

@vishal.kp

\s([0-9.-] )(\s|/)([0-9.-] )
This Regex expression is not giving any output and error. So could you please check this code at your end.

1 Like

Capture1
try this.

1 Like

Hi,

Can you try the following?

strLatAndLon=System.Text.RegularExpressions.Regex.Match(strOriginal,"-?\d{1,3}\.\d{8}[\s/]-?\d{1,3}\.\d{8}").ToString
strLatitude = strLatAndLon.Split({"/"c," "c})(0)
strLongitude=strLatAndLon.Split({"/"c," "c})(1)

Regards,

@vishal.kp
The above code works fine.
It is not giving the correct output for some cases which are listed below.
Case-1: When the Latitude and Longitude are separated by comma
Case-2: When the Latitude and Longitude are enclosed by parenthesis (-89.74589501, 145.52147876).
Case-3: When the Latitude and Longitude are enclosed by Double quotes
“-89.74589501, 145.52147876”.

Could you please check these cases and sorry for the trouble.

try this
5

2 Likes

first use a assign activity like this
str_input = str_input.Replace(","," “).Replace(”""","")
then another one with this expression
str_latitude = IF(str_input.Contains("/"),Split(str_input,"/")(1).ToString,Split(str_input," ")(1).ToString)
str_longitude = IF(str_input.Contains("/"),Split(str_input,"/")(0).ToString,Split(str_input," ")(0).ToString)

Cheers @Shivaraju

1 Like

@vishal.kp
I will check it and inform you.

1 Like

sure :slight_smile:

1 Like

@Palaniyappan
I will check the mentioned code and update you buddy

1 Like

yah sure @Shivaraju

Try this,
(-\d{1,}\.\d{1,})(\s|,|/)(\d{1,}\.\d{1,})

1 Like

@vishal.kp
The above code is failing when the co-ordinates is enclosed in double quotes
case1: “-89.74589501 145.52147876”
case2: -89.74589501 /145.52147876

I had searched in forum that we can extract decimal values from the string by this code “(-?[0-9]+(?:[,.][0-9]+)?)” but it is failed to get the data in case2.
Could you please check this scenario.

@Palaniyappan
Have you tried the above code at your end because am not getting the coordinates with your code.
image


image
image

Thanks @vishal.kp and @Palaniyappan

1 Like