Calculating Distance between Latitude/Longitude points

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
mahmudul
Participant
Posts: 15
Joined: Fri May 07, 2010 8:57 pm

Calculating Distance between Latitude/Longitude points

Post by mahmudul »

Hello All,
I am trying to figure out how to calculate distance between Latitude/Longitude points. I am not sure if there is any built in functions in transformer stage I can use. Please advise. Thanks!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Calculating Distance between Latitude/Longitude points

Post by chulett »

mahmudul wrote:I am not sure if there is any built in functions in transformer stage I can use.
There isn't. Some options off the top of my head:

1. Roll your own
2. Buy a package
3. Call a web service
-craig

"You can never have too many knives" -- Logan Nine Fingers
PaulVL
Premium Member
Premium Member
Posts: 1315
Joined: Fri Dec 17, 2010 4:36 pm

Post by PaulVL »

You also need to qualify if you want straight line distance or driving distance.
mahmudul
Participant
Posts: 15
Joined: Fri May 07, 2010 8:57 pm

Post by mahmudul »

I need to calculate the distance in miles between two points. It doesn't have to be driving distance.....it can be simply the shortest distance between those two points. Thanks again for your input and feedback!!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You also need to specify whether this is a straight line distance or a great circle (that is, over the surface of the earth, which is curved). There are web services out there that can perform this calculation.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hence suggestion #3! :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Use the Pythagorean theorem to calculate a simple distance yourself.

distance = square root of ( (x1 - x2)^2 + (y1 - y2)^2 )

where x and y values are your longitude and latitude decimal numbers.

It may help to use AsFloat() around each x and y value, such as if they are strings vs. decimals.

Then search for a formula to convert the lat/long distance result into miles.
Choose a job you love, and you will never have to work a day in your life. - Confucius
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

When we first created the SDK for DataStage years ago, I got to write some of the functions (which have since been re-written and tuned by engineering) and I had written a distance computation function as well as a Swatch-Time function which were deemed by marketing to be unnecessary and have been dropped. I can't find my sources anymore; and there are several methods of computing distance between two points on a sphere which can produce somewhat different results for points that are far apart. Luckily, all of the basic trigonometric functions you require are part of the BASIC language, so you can just plug-and-play the function you prefer into a user-written program.
Klaus Schaefer
Participant
Posts: 94
Joined: Wed May 08, 2002 8:44 am
Location: Germany
Contact:

Post by Klaus Schaefer »

Are you working with a GeoDB or extensions? These usually have functions to calculate all sorts of geometrics.

Klaus
Post Reply