RE: MI. Measuring distancce

2000-05-11 Thread Crompton, Mark

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]



RE: MI. Measuring distancce

2000-05-11 Thread Jacques Paris

-Original Message-
[mailto:[EMAIL PROTECTED]]On Behalf Of Curt Newsome
Sent: May 11, 2000 12:15 PM
Subject: Re: MI. Measuring distancce

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



Here is some information printed in the MI Professional 5.5 supplement (and
present in the 5.5 help files) that makes it almost clear how distance is
calculated.

DISTANCE()
If the current coordinate system is an earth coordinate system, Distance( )
returns the great-circle distance between the two points. A great-circle
distance is the shortest distance between two points on a sphere. (A great
circle is a circle that goes around the earth, with the circle's center at
the center of the earth; a great-circle distance between two points is the
distance along the great circle which connects the two points.)

For the most part, MapInfo performs a Cartesian or Spherical operation.
Generally a Spherical operation is performed unless the coordinate system is
NonEarth, in which case a Cartesian operation is performed.

SPHERICALDISTANCE()
The SphericalDistance( ) function always returns a value as calculated in a
Latitude/Longitude non-projected coordinate system using great circle based
algorithms..  A value of -1 will be returned for data that is in a NonEarth
coordinate system since this data can't be converted into a
Latitude/longitude coordinate system.

CARTESIANDISTANCE()
If the current coordinate system is an earth coordinate system,
CartesianDistance( ) returns the great-circle distance between the two
points. A great-circle distance is the shortest distance between two points
on a sphere. (A great circle is a circle that goes around the earth, with
the circle's center at the center of the earth; a great-circle distance
between two points is the distance along the great circle which connects the
two points.)

If the current coordinate system is a non-earth coordinate system,
CartesianDistance( ) returns the Cartesian distance.


Now, you may want to know the algorithm used to calculate it along a
great-circle... but that is above my head and not within my interests.

Jacques Paris

e-mailalternate
 [EMAIL PROTECTED]   [EMAIL PROTECTED]

paris PC Consult (mainly MapInfo app.)
 www.total.net/~rparis/gisproducts.htm

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



Re: MI. Measuring distancce

2000-05-11 Thread Curt Newsome

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]