Steve,

I use the same technique as Graham currently, painfully slow, but I have
come up with another idea that I have not yet tried. 

1. Start with a radius search "binary chop" method. Do a few searches until
we have at least one selected obj.

2. Split the objects in our search radius.

3. Test every intersection point on our resulting polygons using standard
Distance function (or calculate the distance yourself - I have a function
that does this if you want it and it is faster in many cases)

4. Test the distance from your point to each line in the polygons. I have
run across functions that do this, but haven't tried them yet.

5. Take the smallest distance from steps 3 and 4 and you have your closest
object.

There are some optimizations you can do. Decide how many radius searches to
do in step 1 so that you get the smallest number of points and lines to
check in steps 3 and 4. Take only the closest points from step 3 to check in
step 4. You may want to have user-defineable optimization parameters to
handle differnent types of data. For instance, on a layer with very detailed
and complex polygons, it might be better to do another 1 or 2 radius
searches.

If this works for you I would be interested in seeing the source code.

- Brad

> -----Original Message-----
> From: Stephen R. Riese [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, December 31, 1999 1:01 PM
> To:   MapInfo
> Subject:      MI Looking for Nearest Object Distance Functions
> 
> Greetings,
> 
> I'm new to MapInfo/MapBasic and this list server.  I'm looking for a
> function that will return the distance from a given point to the nearest
> object of a certain type.  For example, from point (x, y) to the nearest
> house (point object), road or river (linear object) or nearest forrest
> (area object).  All of the functions I've come across give the distance
> between two known points.  I need to find the closest object  first (e.g.,
> which house or river is closest -- hard to do) and then determine the
> distance (easy to do).
> 
> Is there some way to avoid an exhaustive search?  I need to make tens of
> thousands of these calculations, each one selecting the nearest of up to
> hundreds of similar objects.  In addition, each linear and area object are
> defined by two or more points.  I assume I'll need to determine which
> point
> within each of these objects is closest to the known (x, y) point.
> 
> Thanks for any help you can provide and Happy New Year!
> 
> [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]
----------------------------------------------------------------------
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