LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2012)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 21 Feb 2012 18:40:05 -0500
Reply-To:   "Roberts, Michael" <Michael.Roberts@ahca.myflorida.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Roberts, Michael" <Michael.Roberts@ahca.myflorida.com>
Subject:   Re: Calculate distances in a file with latitude and longitude
Comments:   To: Boreak Silk <Boreak.Silk@melbourne.vic.gov.au>
In-Reply-To:   <0C559686C1C6CA45955720D1306D1ED601E9E35B@HAEMAIL01.melbourne.vic.gov.au>
Content-Type:   multipart/alternative;

Boreak Silk,

Thank you for the suggestion. Unfortunately I don't have immediate access to the GIS apps. We do have access to licenses, but there is a time delay that is not feasible. The solution provided by Jon has worked very well though. I have version 17.0.3 and after downloading and installing the extendedtransforms.py file, everything fell into place - thanks to Jon!

Mike

From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Boreak Silk Sent: Tuesday, February 21, 2012 6:08 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Calculate distances in a file with latitude and longitude

Alternatively, you can map those XY coordinates by using one of GIS applications (ArcMap or MapInfo) and then calculate straight lines between hospitals. If you have roam map layer you can calculate road distances between those hospitals.

Good luck,

Boreak Silk

________________________________ From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Jon K Peck Sent: Tuesday, 21 February 2012 9:27 AM To: SPSSX-L@LISTSERV.UGA.EDU<mailto:SPSSX-L@LISTSERV.UGA.EDU> Subject: Re: Calculate distances in a file with latitude and longitude Since you have an input table consisting, I presume of data like this, hosp1, lat, long hosp2, lat, long ...

the easiest thing to do is to read the text file directly and write a new file in the format hosp1 dist11 dist12 dist13 ... hosp2 dist21 dist22 dist23 ...

and then read that as needed. Of course, the distance from a hospital to itself should be zero.

Here is a tiny Python program to do that. Note 1: extendedTransforms has both a spherical distance function, sphDist, and an ellipsoidal distance function, ellipseDist. I used the latter here, which is a little more accurate, but it probably makes little difference unless these hospitals are scattered around the world. Note 2: the distance function can take input in radians or degrees. I have assumed radians here. Note 3: Since the email often mangles indentation, I've written dashes at the start of each indented line to make the indentation structure clear. ========== code starts ============ # read lat/long table and write all distances import csv from extendedTransforms import ellipseDist

table = csv.reader(open("c:/users/mcroberts/latlong.csv", "rb")) output = csv.writer(open("c:/users/mcroberts/latlongout.csv", "wb"))

data = []

for row in table: ----data.append(row)

for item in data: ----hosp, lat, long = item[0].split() ----dist = [hosp] ----for item2 in data: --------hosp2, lat2, long2 = item2[0].split() --------dist.append(str(ellipseDist(float(lat), float(long), float(lat2), float(long2), inradians=True))) ----output.writerow(dist) ============ code ends =============

Jon Peck (no "h") aka Kim Senior Software Engineer, IBM peck@us.ibm.com<mailto:peck@us.ibm.com> new phone: 720-342-5621

From: "Roberts, Michael" <Michael.Roberts@ahca.myflorida.com<mailto:Michael.Roberts@ahca.myflorida.com>> To: SPSSX-L@listserv.uga.edu<mailto:SPSSX-L@listserv.uga.edu> Date: 02/20/2012 01:53 PM Subject: [SPSSX-L] Calculate distances in a file with latitude and longitude Sent by: "SPSSX(r) Discussion" <SPSSX-L@listserv.uga.edu<mailto:SPSSX-L@listserv.uga.edu>> ________________________________

Hi List,

I would like some help with calculating distances between hospitals based on their lat & long, which I have. I have a list of about 250 locations and need to be able to get the distances from each hospital to every other hospital. The data are in a text file and I have SPSS ver. 17.0.3, so I can use the Python extendedtransforms package. The end result would have to be a matrix of 250 by 250 having distances from every hospital to every other hospital, or something of the sort, I think!

Eg:

Hosp1 hosp2 hosp3... Hosp x y z Hosp2 a b c Hosp3 l m n ...

I used to know how to do loops and vectors but have been exclusively working in SQL and the rust is flaking off terribly :) Hope this makes sense to everyone.

Would appreciate any help with this.

TIA

Mike This email is intended solely for the named addressee. If you are not the addressee indicated please delete it immediately.


[text/html]


Back to: Top of message | Previous page | Main SPSSX-L page