Solved

Need Unix Shell Script to calculate the distance between two zip codes

Posted on 2004-03-30
4
568 Views
Last Modified: 2013-12-26
There will (4) four input paramters to the script, the longitude and latitude from two different zip codes.

The formula is:
sqrt( (34.1693-34.1448)^2 + ((117.9595-117.7375)*cos((34.1693+34.1448)/2))^2 )  * ( 2 * PI * 3959/360)

The output would be the distance between the two zip codes (miles).


Let me know if you need anymore info.

Thanks!
0
Comment
Question by:rlburris
4 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 10717571
Look at the man page for the 'bc' command.
0
 

Author Comment

by:rlburris
ID: 10717707
Chris

Thanks... Looks like what is needed, can you provide the script logic?
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10717868
VAL1=34.1693
VAL2=34.1448
VAL3=117.9595
VAL4=117.7375
PRECISION=2


echo "scale=${PRECISION};sqrt( (${VAL1}-${VAL2})^2 + ((${VAL3}-${VAL4})*c((${VAL1}+${VAL2})/2))^2 )  * ( 2 * 4*a(1) * 3959/360)" | bc -l

You have to have a "recent" enough bc (like the linux one) which accepts the "-l" switch to load the math library.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 10717971
#!/bin/sh
lon1=117.9595
lat1=34.1693
lon2=117.7375
lat2=34.1448
perl -e "print sqrt(($lat1-$lat2)**2+($lon1-$lon2)**2*cos(($lat1+$lat2)*atan2(1,1)/90))*69"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
cat dog challenge 18 124
Path of Workbook 3 59
Way to decrease size of apk file 9 40
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now