*Jon Peck posted a reply to this but in the archives the message is scrambled.
Did anyone happen to save that post? If so would you email it to me? Date:* Mon, 20 Feb 2012 15:27:07 -0700 *Reply-To:* Jon K Peck<[hidden email]> *Sender:* "SPSSX(r) Discussion"<[hidden email]> *From:* Jon K Peck<[hidden email]> <http://listserv.uga.edu/cgi-bin/wa?A2=ind1202&L=spssx-l&D=0&P=36443> *Subject:* Re: Calculate distances in a file with latitude and longitude <http://listserv.uga.edu/cgi-bin/wa?A2=ind1202&L=spssx-l&D=0&P=38463> -- Art Kendall Social Research Consultants ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
Administrator
|
Hi Art. It looks okay in the Nabble archive--see the second post here:
http://spssx-discussion.1045642.n5.nabble.com/Calculate-distances-in-a-file-with-latitude-and-longitude-td5500259.html#a5503755
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Art Kendall
If you just want to calculate distances
and have installed the SPSSINC TRANS extension command and the extendedTransforms.py
module, you can run something like this.
spssinc trans result=distance /formula "extendedTransforms.ellipseDist(latitude1, longitude1, latitude2, longitude2, inradians=False)". for positions in degrees. If in radians, change inradians to True. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email] Date: 06/02/2012 07:16 AM Subject: [SPSSX-L] earlier post "Calculate distances in a file with latitude and longitude" Sent by: "SPSSX(r) Discussion" <[hidden email]> *Jon Peck posted a reply to this but in the archives the message is scrambled. Did anyone happen to save that post? If so would you email it to me? Date:* Mon, 20 Feb 2012 15:27:07 -0700 *Reply-To:* Jon K Peck<[hidden email]> *Sender:* "SPSSX(r) Discussion"<[hidden email]> *From:* Jon K Peck<[hidden email]> <http://listserv.uga.edu/cgi-bin/wa?A2=ind1202&L=spssx-l&D=0&P=36443> *Subject:* Re: Calculate distances in a file with latitude and longitude <http://listserv.uga.edu/cgi-bin/wa?A2=ind1202&L=spssx-l&D=0&P=38463> -- Art Kendall Social Research Consultants ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Art Kendall
At 09:12 AM 6/2/2012, Art Kendall wrote:
>*Jon Peck posted a reply to this but in the archives the message is scrambled. >Did anyone happen to save that post? If so would you email it to me? Perhaps the following will help. It's from a (probably over-elaborate) post I wrote on the subject, back in 2009(*): FAQ: Computing distance from latitude and longitude (DRAFT) Sections below are ===== (1) Solution in native SPSS transformation code ===== (2) Using Python code from Developer Central ===== (3) Test data and test run of native SPSS code ===== (1) Native SPSS code ===================================== Earth-radius values are from http://en.wikipedia.org/wiki/Earth_radius; see also http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html. * ............... Initialize constants ................. . * The following code >REQUIRES< that angles in the base system . * (SPSS) be in radians, so that the trigonometric distance is . * in radians, and can be multiplied directly by the Earth's . * radius. . DO IF $CASENUM EQ 1. * These initializations >MUST< be performed: . * #EarthRad is the Earth's radius in whatever units you please; . * the calculated distance will be in those units: . * 6,372.7976 km, . * 3,959.873 statute miles, . * 3,441.035 nautical miles. . . COMPUTE #EarthRad = 3959.873 /* statute miles */. * #AngleCvt is the number of your angle units (degrees, here) . * in one of SPSS's angle units (radians). It uses that . * ARCTAN(1)is PI/4 radians or (in any angle measure) 1/8 circle . . . COMPUTE #AngleCvt = 360 /* Number of input units in a full circle */ /(8*ARTAN(1)). END IF. * ............... Compute distance ................ . * Compute distance between points with coordinates . * (lat1,lon1) and (lat2,lon2) . compute distance = #EarthRad* (2*artan(1)-arsin( sin(lat1/#AngleCvt) /* (sin(lat1) */ *sin(lat2/#AngleCvt) /* .sin(lat2) */ + cos(lat1/#AngleCvt) /* +cos(lat1) */ *cos(lat2/#AngleCvt) /* .cos(lat2) */ *cos(lon2/#AngleCvt /* .cos(long2 */ -lon1/#AngleCvt) /* -long1))*/ )). FORMAT Distance (F7.2). ===== (2) Using Python code ==================================== From Peck, Jon, "Re: Function for arc cosine", to SPSSX-L Thu, 7 Jun 2007 09:53:06 -0500"" "In the extendedTransforms module on SPSS Developer Central ( www.spss.com/devcentral), there are two functions that implement distance calculations on Earth latitude and longitude coordinates. sphDist: calculate distance between two points on earth using spherical approximation ellipseDist: calculate distance between two points on earth using ellipsoidal approximation "Here is a simple usage example for just a single distance pair. ............. begin program. import spss import extendedTransforms fromloc = (41.90, 87.65) toloc = (41.73, 71.43) dist1 = extendedTransforms.ellipseDist(fromloc[0], fromloc[1], toloc[0], toloc[1], inradians=False) dist2 = extendedTransforms.sphDist(fromloc[0], fromloc[1], toloc[0], toloc[1], inradians=False) print dist1, dist2 end program. (3) ===== Test data, and test run ================================= The 'given' values which are compared with the calculation are, . Providence to Chicago distance, from Jon Peck's posting "Re: Function for arc cosine", Thu, 7 Jun 2007 09:53:06 -0500 . Others, arbitrary test points with distance calculated at site http://www.movable-type.co.uk/scripts/latlong.html. It's not clear why tiny discrepancies remain. DATA LIST LIST / City1 lat1 lon1 City2 lat2 lon2 GivenDist (A4, F6.2, F6.2,A4, F6.2, F6.2, F7.2). BEGIN DATA Pvd 41.90 87.65 Chi 41.73 71.43 836.27 A1 42.00 80.00 A2 39.00 70.00 564.33 B1 44.00 70.00 B2 49.00 85.00 791.00 END DATA. . /*-- LIST /*-*/. * ............... Initialize constants ................. . * The following code >REQUIRES< that angles in the base system . * (SPSS) be in radians, so that the trigonometric distance is . * in radians, and can be multiplied directly by the Earth's . * radius. . DO IF $CASENUM EQ 1. * These initializations >MUST< be performed: . * #EarthRad is the Earth's radius in whatever units you please; . * the calculated distance will be in those units: . * 6,372.7976 km, . * 3,959.873 statute miles, . * 3,441.035 nautical miles. . . COMPUTE #EarthRad = 3959.873 /* statute miles */. * #AngleCvt is the number of your angle units (degrees, here) . * in one of SPSS's angle units (radians). It uses that . * ARCTAN(1)is PI/4 radians or (in any angle measure) 1/8 circle . . . COMPUTE #AngleCvt = 360 /* Number of input units in a full circle */ /(8*ARTAN(1)). END IF. * ............... Compute distance ................ . * Compute distance between points with coordinates . * (lat1,lon1) and (lat2,lon2) . compute distance = #EarthRad* (2*artan(1)-arsin( sin(lat1/#AngleCvt) /* (sin(lat1) */ *sin(lat2/#AngleCvt) /* .sin(lat2) */ + cos(lat1/#AngleCvt) /* +cos(lat1) */ *cos(lat2/#AngleCvt) /* .cos(lat2) */ *cos(lon2/#AngleCvt /* .cos(long2 */ -lon1/#AngleCvt) /* -long1))*/ )). FORMAT GivenDist(F7.2). COMPUTE DeltaPct = 100*(Distance/GivenDist-1). FORMATS DeltaPct (PCT7.2). LIST. List |-----------------------------|---------------------------| |Output Created |29-MAR-2009 00:55:20 | |-----------------------------|---------------------------| City1 lat1 lon1 City2 lat2 lon2 GivenDist distance DeltaPct Pvd 41.90 87.65 Chi 41.73 71.43 836.27 834.33 -.23% A1 42.00 80.00 A2 39.00 70.00 564.33 564.52 .03% B1 44.00 70.00 B2 49.00 85.00 791.00 791.03 .00% Number of cases read: 3 Number of cases listed: 3 ========================================================= (*) From posting, Date: Sun, 29 Mar 2009 00:57:59 -0400 From: Richard Ristow <[hidden email]> Subject: Re: Calculating distance between latitude and longitude To: [hidden email] ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |