LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert UTM coordinates to Latitude, Longitude and Viceversa

I want to use a csv file with coordinates, and be able to convert the coordinates in both ways. I tried to make a vi myself, but I couldn't make it work.

I followed the formulas here:

https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system#Simplified_formulas

but wasn't able to make a working app.

Can someone please help me?

Thanks.

0 Kudos
Message 1 of 10
(6,028 Views)

You have a lot going on in that VI.  It appears its just math and something tells me you might be getting lost in all that mess.  I would try to clean up the code and use Sub VIs or i would use a formula node.

 

[Edit]: on a second take you also may have race conditions. I see you writing to variable A in a for loop outside of you while loop where you read the variable with no data dependency.  I dont see a need for all of  the local variables.  Another suggestion would be to remove them and use wires and shift registers.



-Matt
0 Kudos
Message 2 of 10
(6,008 Views)

I found these formulas:

x=R*cos(lat)*cos(lon)

y=R*cos(lat)*sin(lon)

z=R*sin(lat)

I made another vi, but I receive an error on a formula. I receive nan, because the value I get when I perform the last trigonometric function is too big.

I will leave my vi, and maybe you can help me out.

Thanks.

0 Kudos
Message 3 of 10
(5,964 Views)

The issue is not the number being too large.  DBL can handle very large numbers, bigger than what youre working with. NAN means that it recieved a value that is not a number.  Something tells me you may have taken a value from the wrong column that you werent expecting or it was empty. I would double check the values being pulled from the spreadsheet and make sure they are being indexed properly.

 

A few tips,

 

1. replace the conversion de coordenades with a property not to reinitialize to default and wire the error to the while loop

2. replace all the decimal string to number or vice versa with fract/exp string to number. 

3. Wire the error of the implicite property node for longitude and latitude to the while loop

4. Pull the controls for longitude and latitude outside of the event structure, but in the while loop and then remove the local variables and rewire from the indicators.



-Matt
0 Kudos
Message 4 of 10
(5,956 Views)

What I think is happening is that the formulas are wrong, because the numbef that goes into the inverse trig function os bigger than one and that is what's causing the error.

Can someone give me the right formulas I can use?

Thanks.

0 Kudos
Message 5 of 10
(5,907 Views)

The equations you've cited are the relationships that allow you to convert between Cartesian coordinates (X, Y, Z) and Spherical Polar Coordinates (Radius, Latitude, and Longitude, usually expressed with the Greek characters rho, theta, and phi). 

 

Note your equations, given R, Latitude and Longitude, any values of these quantities will give finite values for X, Y, and Z.  Furthermore, as long as all of X, Y, and Z are not all zero, these equations can easily be inverted:

R = sqrt (sqr(X) + sqr(Y) + sqr(Z))

Longitude = arctan (Y/X)  (note that the arctan is defined even if X = 0)

Latitude = arctan (Z / sqrt(sqr(X) + sqr(Y))

 

Note that LabVIEW's arctan function needs to be supplemented with a "guard" for a zero denominator.  If the numerator is positive, then the arctan value is pi/2, while if it is negative, the arctan value is -pi/2.

 

Unfortunately, while many other Languages have arctan functions that have "numerator" and "denominator" inputs to handle the case of zero denominators.

 

Bob Schor

0 Kudos
Message 6 of 10
(5,897 Views)

atan2 = Inverse Tangent (2 Input)

 

atan2.png

 

Lynn

0 Kudos
Message 7 of 10
(5,882 Views)

Aha!  I over-looked that, sorry NI (and thanks, Lynn).

 

BS

0 Kudos
Message 8 of 10
(5,871 Views)

I tried your formulas in an excel worksheet, but they still don't work.

I used some utm points from Honduras in central america, but the points appear some place else.

Can you please check my excel worksheet?

Thanks.

0 Kudos
Message 9 of 10
(5,826 Views)

According to the Web, Tegucigalpa is 14° N (latitude), 87° W (longitude).  The Earth's radius is approximately 6.4 million meters (I have no idea where you get the values for R in your spreadsheet).

 

If you use the atan2(x, y) formulas instead of atan (y/x), you will avoid the "blowup" in the situation x=0.

 

Where did you get the values for X, Y, and Z in your WorkSheet?  I strongly suspect they are wrong, particularly Z.  Honduras is not that close to the equator.  Also check the units for these measurements (feet?  meters?  miles?  inches?  not sure how you get R as about 1.6 million).

 

Finally, note that UTM coordinates seem to be measured from the 180° meridian (somewhere in the Pacific), whereas Longitude is measured from the 0° meridian (through Greenwich, England, half a world away).

 

Bob Schor

 

0 Kudos
Message 10 of 10
(5,817 Views)