As one who bends over backward (a little too far probably) to avoid
programming (and for those who don't own MapBasic), I have a SQL-based,
non-programming alternative:

In the "Select Columns" box:
* (or whatever columns you want),
Round(Distance(CentroidX(obj), CentroidY(obj), CentroidX(tableB.obj),
CentroidY(tableB.obj), "mi"),.1) "Miles"

(the last items in that statement set the units to miles, round to .1 &
name the distance column "Miles")

In the "from Tables" box:
TableA, TableB
(I think they need to be in this order - the Centroid functions above assume
the first Centroids to be from
the first table listed here).

Then you just need your link established in the "where Condition" box and
any "Order by" clause.

This should work - the distance function is very poorly documented in the
MapInfo help files/books.

Curt Newsome

"Crompton, Mark" wrote:

>
> Hi Christian,
>
> Using MapBasic, setup a Nested For Loop.
> *****************************************************************
> Dim nLoop, nInnerLoop As Integer
> Dim fDistance As Float
> Dim fX1, fY1. fX2, fY2 As Float
>
> For nLoop = 1 to TableInfo(TableA, TAB_INFO_NROWS)
>         Fetch Rec nLoop from TableA
>         fX1 = CentroidX(TableA.obj)
>         fY1 = CentroidY(TableA.obj)
>         For nInnerLoop = 1 to TableInfo(TableB, TAB_INFO_NROWS)
>                 Fetch Rec nInnerLoop from TableB
>                 fX2 = CentroidX(TableB.obj)
>                 fY2 = CentroidY(TableB.obj)
>                 fDistance = Distance(fX1, fY1, fX2, fY2, "mi")
>                 Print "The Distance from TableA Store "+nLoop+" to TableB
> Store "+nInnerLoop+" is "+fDistance
>         Next
> Next
> *****************************************************************
> Yes this can be put into smaller code, but this should appear readable and
> logical.  I've not checked it so there could be some simple errors.
>
> Hope it helps
> Mark Crompton
>
> -----Original Message-----
> From: christian ormond [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 10, 2000 2:17 PM
> To: Mapinfol
> Subject: MI. Measuring distancce
>
> I have a table with a of 200 stores (Table A) and their lat longs and
> another group of 1600 stores (Table B) with their lat longs.  How in a
> sql statement would I find distance from all the stores in Table A to
> Table B.  I can figure out how to do it from a specific store lat/long
> i.e. -71.2555, 42.15222 to the centroidX(obj) Centroidy(obj) "mi" but
> can not figure out how to get more than one store in a one step batch.
> Any suggestions.
>
> Should look like:
> Table A Store #1.....Table B Store #1...1.1 mi
> Table A Store #1.....Table B Store #2...1.3 mi
> Table A Store #1.....Table B Store #3...1.5 mi
> Table A Store #1.....Table B Store #4...2.4 mi
> Table A Store #2.....Table B Store #1...5.8 mi
> Table A Store #2.....Table B Store #2...7.1 mi
> Table A Store #2.....Table B Store #3...10.8 mi
> Table A Store #2.....Table B Store #4...15.7 mi
>
> ----------------------------------------------------------------------
> To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
> "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]

----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]

Reply via email to