IB - Developer Center    Forums  Hop To Forum Categories  FOCUS/WebFOCUS    Distance Calculation by Latitude/Longitude
Go
New
Search
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Member
Posted
I was trying to calculate distance by using latitude and longtitude. Does anyone has the formula or ways to do so? I'd really appreciated.
 
Posts: 6 | Location: Memphis | Registered: April 30, 2007Reply With QuoteEdit or Delete MessageReport This Post
Virtuoso
Posted Hide Post
quote:
calculate distance by using latitude and longtitude



how about google

distance

gives you

Haversine formula:
 R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c 

(Note that angles need to be in radians to pass to trig functions).
 
JavaScript: var R = 6371; 
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c; 
  


and

meridian

I'm not sure if you will be able to do this in WF, but you might be able to do this.




Frank

prod: WF 7.6.5 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.5 on the same platform and databases,IE7

 
Posts: 1644 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Virtuoso
Posted Hide Post
http://www.mathforum.com/library/drmath/view/51711.html

The above gives a discussion of the issue, Of course how to calculate sines and cosines to do the formula should be interesting.


Leah
 
Posts: 1307 | Location: Council Bluffs, IA | Registered: May 24, 2004Reply With QuoteEdit or Delete MessageReport This Post
Expert
Posted Hide Post
Adong,

See the discussion on this subject from February this year.

T


Old FOCUS coders never die, they just become functionally stable. (Tony A Wink)

Current Client: WebFOCUS 7.6.2 Win XP SP2/IIS 6/Tomcat 5.5 - MRE / BID MS SQL / Oracle - DevStudio 7.6.6 7.1.6
Local: WebFOCUS 7.6.6 7.1.6 on Win XP SP2/Apache/Tomcat 5.5 - Self Service
 
Posts: 2865 | Location: England U.K. (Freelance) | Registered: April 08, 2004Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Here's what I came up with after much discussion in February and a little help from some college math professors.

-SET &PI = 3.1415926535897932384626433832795;
-* Earth's mean radius in km 6371
-* Earth's mean radius in mi 3956
-SET &Earth_R = 3956;

DEFINE FUNCTION F_SIN(angle/I3)
Rads/D33.12 = angle / 180 * &PI ;
F_SIN/D20.12 = Rads - ((Rads ** 3)/(1*2*3))
+ ((Rads ** 5)/(1*2*3*4*5)) - ((Rads ** 7)/(1*2*3*4*5*6*7))
+ ((Rads ** 9)/(1*2*3*4*5*6*7*8*9)) + ((Rads ** 11)/(1*2*3*4*5*6*7*8*9*10*11))
+ ((Rads ** 13)/(1*2*3*4*5*6*7*8*9*10*11*12*13));
END
-*
-RUN
-*
DEFINE FUNCTION F_COS(angle/I3)
Rads/D33.12 = angle / 180 * &PI ;
F_COS/D20.12 = 1 - ((Rads ** 2)/(1*2))
+ ((Rads ** 4)/(1*2*3*4)) - ((Rads ** 6)/(1*2*3*4*5*6))
+ ((Rads ** 8)/(1*2*3*4*5*6*7*8)) - ((Rads ** 10)/(1*2*3*4*5*6*7*8*9*10))
+ ((Rads ** 12)/(1*2*3*4*5*6*7*8*9*10*11*12));
END
-*
-RUN
-*
DEFINE FUNCTION F_DIST(Lat1/D16.6, Long1/D16.6, Lat2/D16.6, Long2/D16.6)
Earth_R/D8 = 3956;
dLat/D20.6 = Lat2 - Lat1;
dLong/D20.6 = Long2 - Long1;
F_DIST/D20.4 = SQRT(dLat * dLat + dLong * dLong) * 1/(F_COS(dLat / 2)) / 360 * (2 * &PI * Earth_R);
END
-*
-RUN
-*
TABLE FILE CAR
SUM
-**************SIN COS COT********************************
-**************DISTANCE CALCULATOR************************
COMPUTE LON1/D20.8 = 94.9202;
COMPUTE LON2/D20.8 = 94.9741;
COMPUTE LAT1/D20.8 = 29.3969;
COMPUTE LAT2/D20.8 = 29.3676;
COMPUTE DLON/D20.8 = LON2-LON1;
COMPUTE DLAT/D20.8 = LAT2-LAT1;
COMPUTE DIST/D20.8 = F_DIST(LAT1, LON1, LAT2, LON2);
BY COUNTRY NOPRINT
WHERE RECORDLIMIT EQ 1
END

Hope this helps

Glenda


Glenda

Production 5.3.6 - UNIX
 
Posts: 248 | Location: Galveston, Texas | Registered: July 07, 2004Reply With QuoteEdit or Delete MessageReport This Post
Expert
Posted Hide Post
Adong, i think we would all agree that it depends on how much accuracy you need.
Do you need to correct for the curvature of the earth, or not?
If not, then plain old Pythagoras should be good enough, after xlating your latlongs into radians. If your distances are all within your country (you don't say what country you're in), you can decide just how much agony you need to go thru. If your distances are crossing continents, then Tony and Glenda have done your heavy lifting for you. (looks like a great first entry for the new wf wikipedia!)




DevStu 767; wintell 767; Unix 765,Oracle: /// iplanet; Dev 765 tomcat 6;///MRE/BID/PMF
 
Posts: 2631 | Location: Manhattan | Registered: October 28, 2003Reply With QuoteEdit or Delete MessageReport This Post
Master
Posted Hide Post
Did you mean to say
quote:
- ((Rads ** 11)/
?
 
Posts: 535 | Location: NYC | Registered: January 11, 2005Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Glenda,

Thank you very much for your post. It works perfect. I really appreciate your help.

Maggie
 
Posts: 6 | Location: Memphis | Registered: April 30, 2007Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Maggie,

Glad I was able to help.

Glenda.


Glenda

Production 5.3.6 - UNIX
 
Posts: 248 | Location: Galveston, Texas | Registered: July 07, 2004Reply With QuoteEdit or Delete MessageReport This Post
Expert
Posted Hide Post
Hi Glenda,

I think that this topic is one worthy for writing an article about for the FOCUS on Developers area. I'm sure Kathleen would agree as it is bound to come up time and again. What do you reckon?

T (currently in Vegas!!Smiler)


Old FOCUS coders never die, they just become functionally stable. (Tony A Wink)

Current Client: WebFOCUS 7.6.2 Win XP SP2/IIS 6/Tomcat 5.5 - MRE / BID MS SQL / Oracle - DevStudio 7.6.6 7.1.6
Local: WebFOCUS 7.6.6 7.1.6 on Win XP SP2/Apache/Tomcat 5.5 - Self Service
 
Posts: 2865 | Location: England U.K. (Freelance) | Registered: April 08, 2004Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Tony,

I'm just a puzzle solver. The more challenging the better. When a COBOL programmer said WeBFOCUS code was too limited to perform distance calculations, it was like waving a red flag in front of a bull (or a stubborn Irish gal).

I don't know the first thing about writing an article. If you want to help me or write it yourself, I won't mind. It sure would save others from what I had to go through to find the information.

And don't rub it in! I couldn't make Las Vegas this year and I so wanted to meet you and the others.
Glenda


Glenda

Production 5.3.6 - UNIX
 
Posts: 248 | Location: Galveston, Texas | Registered: July 07, 2004Reply With QuoteEdit or Delete MessageReport This Post
Virtuoso
Posted Hide Post
I discussed this issue (more in general) with some people from IBI in Vegas.
It is indeed not easy to use recursive programming within webfocus and create formulas for several mathematic or financial functions like IRR and FV etc.
But I'm sure that they will see it as a challange to forfill our wishes on this point if we ask them




Frank

prod: WF 7.6.5 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.5 on the same platform and databases,IE7

 
Posts: 1644 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Expert
Posted Hide Post
Hi Glenda,

I agree totally, just tell me that "it can't be done" and I will try to find a way. Just as when Susannah said that trig functions are not possible in Feb in answer to the original question.

T


Old FOCUS coders never die, they just become functionally stable. (Tony A Wink)

Current Client: WebFOCUS 7.6.2 Win XP SP2/IIS 6/Tomcat 5.5 - MRE / BID MS SQL / Oracle - DevStudio 7.6.6 7.1.6
Local: WebFOCUS 7.6.6 7.1.6 on Win XP SP2/Apache/Tomcat 5.5 - Self Service
 
Posts: 2865 | Location: England U.K. (Freelance) | Registered: April 08, 2004Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Tony,

You've got me pegged!

Glenda


Glenda

Production 5.3.6 - UNIX
 
Posts: 248 | Location: Galveston, Texas | Registered: July 07, 2004Reply With QuoteEdit or Delete MessageReport This Post
Expert
Posted Hide Post
T and Glenda... i see a really great Summit presentation on this subject for the 2 of you to do together for 2008...
and there's a chance, i hear, that Summit might be in Dallas... close enough for "Red" to get there.




DevStu 767; wintell 767; Unix 765,Oracle: /// iplanet; Dev 765 tomcat 6;///MRE/BID/PMF
 
Posts: 2631 | Location: Manhattan | Registered: October 28, 2003Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Susannah,

YOu are so perceptive. I never said a thing about being a redhead. But yes, that's where the stubborn streak comes from. I like your idea. I'm game if Tony is.


Glenda

Production 5.3.6 - UNIX
 
Posts: 248 | Location: Galveston, Texas | Registered: July 07, 2004Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

IB - Developer Center    Forums  Hop To Forum Categories  FOCUS/WebFOCUS    Distance Calculation by Latitude/Longitude

Copyright © 1996-2008 Information Builders, leaders in enterprise business intelligence.