Solved

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

Posted on 2004-03-30
4
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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