Solved

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

Posted on 2004-03-30
4
571 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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 103
sumNumber challenge 16 122
maven archtype selection in eclipse 1 57
Is there a simple front-end menu system. 9 88
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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