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
Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 42
VB.NET how to use the Vertical ScrollBar 5 114
Include multiple hostnames in this command? 3 55
modThree challenge 4 97
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

860 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