There is another way to make a distance matrix outside of Maptitude and then import into Maptitude. This could be done in Excel, using a VB script or by simple copy and past, setting up a formula, and dragging the formula over the rows an columns, or in any stat package language, or VB, etc. Language will need trig functions. Suppose you have a list of locations Long(i)Lat(i), i = 1 to n. You want to make the distance matrix with elements D(i,j) where i = 1 to n, j = 1 to n. D(i,j) = Great Circle distance between Long(i),Lat(j); Long(j)Lat(j) ]
First convert the Long(i),Lat(i) to radians. degrees to radians: Long(i) = Long(i) * pi/180 = Long(i) * 57.2958 Lat(i) = Lat(i) * pi/180 = Lat(i) * 57.2958 Better to use pi/180 because the precision may be important. pi being a stored constant in Excel (i think) r * arccos[sin(Lat(i)) * sin(Lat(j)) + cos(Lat(i)) * cos(Lat(j)) * cos(Lon(j) - Lon(i))] Where r is the radius of the earth r=3437.7 (nautical miles) r=6378.7 (kilometers) r=3963.0 (statute miles) Once you have the table, then import into Maptitude and link to whatever layer needs the distance matrix. You get a dataview, rows are point locations, columns are the distances to all the other points. There is code at http://jaimerios.com/?p=39 <http://jaimerios.com/?p=39> if you need to adjust for the ellipsoid, see http://www.movable-type.co.uk/scripts/latlong-vincenty.html <http://www.movable-type.co.uk/scripts/latlong-vincenty.html> There is Javascript code at the bottom. If you are curious if the spherical trig and a linear form are close, you can use Pythagoras distance = sqrt(x * x + y * y) where x = 69.1 * (Lon(j) - Lat(i)) and y = 69.1 * (Lon(j) - Lon(i)) * cos(Lat(i)/57.3) Dick Hoskins ________________________ Forward or reply from: Dick Hoskins EMS/Trauma WA DOH, Olympia (360) 236-2873 [EMAIL PROTECTED] _________________________ ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Moshe Haspel Sent: Friday, August 15, 2008 1:57 PM To: [email protected] Subject: Re: [Maptitude] Distance matrix calculation If I understand correctly, you need to resort the results? I haven't tested this, but it (or at least something close to it) should work: 1. Use OpenTable() to open the .dbf file that you just created with the distances macro. 2. Use CreateEditor() to create an dataview for that table. 3. Use SelectAll() to create a selection set of all data in the dataview. 4. Use SortSet() to sort your data as needed. 5. Use ExportView() to export the sorted dataview to a new file. Reinaldo Paul Pérez Machado wrote: > > /*Hi Moshe, > > Thanks a lot. It worked like a charm! As only me will probably use it > there is no need of a DBox. I did make a few modifications to fit my > requirements. The most important was the following line(s): > > // for inner_loop = 1 to point_count do // Start looping over > points a second time (for "to" point) > for inner_loop = 1 to outer_loop do // Start looping over points a > second time (for "to" point) > > To get rid of the redundancy, the only problem is that I need now to > have the ID sorted increasing but repeating the FROMID: > 1,1 > 1,3 > 1,4 > etc. > But I have > 1,1 > 3,1 > 3,3 > 4,1 > 4,3 > 4,4 > That is the same but not what required. I am thinking how to solve > this chalenge now. > > Best regards. And thanks again. > > Reinaldo*/ > > ---------------------------------------------------------- > > [EMAIL PROTECTED] <mailto:mhaspel%40emory.edu> wrote: >> >> I wrote a macro for this very function about a year ago... free >> download at http://www.directionsmag.com/files/index.php/view/738 >> <http://www.directionsmag.com/files/index.php/view/738> >> <http://www.directionsmag.com/files/index.php/view/738 >> <http://www.directionsmag.com/files/index.php/view/738> > >> >> No dialog box, though-- you'll have to modify the administrative >> settings at the top of the file. Either that, or commission someone to >> write a dbox. >> >> Quoting Reinaldo Paul Pérez Machado <[EMAIL PROTECTED] >> <mailto:Reinaldo%40igasageo.com.br> >> <mailto:Reinaldo%40igasageo.com.br>>: >> >> > >> > >> > Hi, >> > >> > Please, some help is required. I am not a DK programmer, but I need >> > to generate a matrix containing all distances among 585 Lon/Lat >> > coordinate pairs. That is, the resulting table should contain 170820 >> > values, if I am not calculating wrongly. I guess I should use the >> > GetDistance() function, but the problem is I lack all the basic >> > programming knowledge for sorting the results, write to a file etc. >> > No fancy interface is required, but at least something like point to >> > the .bin table or geographic file and asking for the name of the >> > output would be necessary. >> > >> > Thanks in advance for the aid. Best regards, >> > >> > Reinaldo >> > > -- ======================================================== | Moshe Haspel, Ph.D. | | Director of Research and Evaluation, | | Office of University-Community Partnerships | | Adjunct Assistant Professor, | | Department of Political Science | | | | Emory University | | 1256 Briarcliff Road NE | | Room 427-W | | Mailstop 1256-001-1AL | | Atlanta, GA 30322 | | Phone: 404-712-9370 | | | | | | Address for direct deliveries (FedEx, UPS, etc.) | | 1256 Briarcliff Road NE, Suite 418-W, | | Atlanta, GA 30306-2636 | | | ========================================================
