Solved

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

Posted on 2004-03-30
4
567 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
Comment Utility
Look at the man page for the 'bc' command.
0
 

Author Comment

by:rlburris
Comment Utility
Chris

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

Expert Comment

by:Alf666
Comment Utility
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
Comment Utility
#!/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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

12 Experts available now in Live!

Get 1:1 Help Now