|
I was wondering if anyone has some SPSS Syntax to calculate the distance
between two places with latitude and longitude coordinates. I have looked up the formulas, but have been unable to get the calculations to work. I currently have latitude and longitude stored in "Decimal degrees" but not the formula of HH:mm:ss that needs to be put into the formula. Does anyone have any suggestions about data transformations or have a formula that works to find distance using "decimal degrees." I am not sure, but this could also have to do with the difference between radians and degrees as well. Any help would be appreciated. Example Data: Zipcode Latitude Longitude 78540 26.30178 -98.15952 78541 26.29592 -98.164071 78543 26.297908 -97.992486 Don ===================== 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 the extendedTransforms.py programmability module on SPSS Developer Central (www.spss.com/devcentral) there are two functions for this: sphDist and ellipseDist.
They take latitude and longitude values in degrees or in radians and calculate the distance. sphDist uses a spherical approximation to the earth and ellipseDist uses an ellipsoidal approximation, which is a bit more accurate. Result is returned in miles. HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Don Asay Sent: Monday, August 11, 2008 11:47 AM To: [hidden email] Subject: [SPSSX-L] SPSS Syntax Calculating Distance using Latitude and Longitude I was wondering if anyone has some SPSS Syntax to calculate the distance between two places with latitude and longitude coordinates. I have looked up the formulas, but have been unable to get the calculations to work. I currently have latitude and longitude stored in "Decimal degrees" but not the formula of HH:mm:ss that needs to be put into the formula. Does anyone have any suggestions about data transformations or have a formula that works to find distance using "decimal degrees." I am not sure, but this could also have to do with the difference between radians and degrees as well. Any help would be appreciated. Example Data: Zipcode Latitude Longitude 78540 26.30178 -98.15952 78541 26.29592 -98.164071 78543 26.297908 -97.992486 Don ===================== 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 ===================== 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 Björn Türoque
At 01:46 PM 8/11/2008, Don Asay wrote:
>I was wondering if anyone has some SPSS Syntax to calculate the distance >between two places with latitude and longitude coordinates. Jon Peck has pointed out that there's Python code available on Developer Central. It can also be done in native SPSS code; see below. It's slightly less than what's on Developer Central, accurate, because it ignores the Earth's deviation from sphericity.(1) It's from an earlier posting(2), edited some, not tested. * Initialize constants ............ . DO IF $CASENUM EQ 1. * #EarthRad is the Earth's radius in whatever units you please; . * the calculated distance will be in those units. Radius (3): . * 6,372.7976 km, * 3,959.873 statute miles, * 3,441.035 nautical miles. . COMPUTE #EarthRad = 6,372.7976 /* km */. * #AngleCvt is the number of your angle units (degrees) in . * one of SPSS's angle units (radians). It uses that ARCTAN(1) . * is PI/4 radians. . #AngleCvt = 360 /* Number of input units in a full circle */. /(8*ARCTAN(1)). END IF. * Compute distance between points with coordinates . * (lat1,lon1) and (lat2,lon2) . compute distance = #EarthRad* arcos(sin(lat1/#AngleCvt)*sin(lat2/#AngleCvt) + cos(lat1/#AngleCvt)*cos(lat2/#AngleCvt *cos(lon2/#AngleCvt-lon1/#AngleCvt)). ............................................... (1) >fromloc = (41.90, 87.65) >toloc = (41.73, 71.43) >[...] >Using these coordinates (Chicago, IL to >Providence, RI), the ellipsoidal and spherical >results are 836.2705 and 834.0903 miles. (Jon Peck, "Re: Function for arc cosine", Thu, 7 Jun 2007 09:53:06 -0500) (2) Richard Ristow, "Re: Function for arc cosine", Thu, 31 May 2007 11:35:53 -0400, taken in turn from posting by Seumas Rogan, Thu, 3 Jul 2003 16:23:18 -0700 (3) From http://en.wikipedia.org/wiki/Earth_radius: Quadratic mean radius: Qr The ellipsoidal quadratic mean radius provides the best approximation of Earth's average transverse meridional radius and radius of curvature ... This is the equivalent spherical "great-circle" radius of the ellipsoid). For Earth, Qr equals 6,372.7976 km (3,959.873 mi; 3,441.035 nmi). See also http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html) ===================== 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 |
