Pitney Bowes
MapInfo Pro™ Monthly Journal

Something a bit more advanced - Finding objects close to other objects

adv How can you find slurry tanks close to a stream? For some that might be a very valid question, especially for those trying to minimize the number of streams polluted by slurry from these tanks.

The solution to this question can be illustrated by creating buffers around all streams and see which slurry tanks are within these buffers.

Slurry Tanks

But you can also find the answer to this question using SQL without creating and storing the buffers. In this case we want to select slurry tanks that are within a buffer of let's say 100 meters around any stream.

In the SQL statement we need to start by creating the buffers we want to compare the slurry tanks against. This can be done in a select like this:

Select CartesianBuffer(OBJ, 50, 100, "m") From STREAMS

The select statement will return a list of buffers around all streams. These buffers have a resolution of 50 and are 100 meters from the streams.

Note that in this case I'm using the function CartesianBuffer. You could also use the function Buffer. Which you choose depends on the coordinate system of your data.

Now it's time to compare this list with the slurry tanks. We do this by using the statement above as a sub select:

Select * From SLURRY_TANKS
Where OBJ Within Any
(Select CartesianBuffer(OBJ, 50, 100, "m") From STREAMS)


In the SQL Select dialog in MapInfo Professional the select statement will look like this:

SQL Select

Here we compare each slurry tank with each of the buffers and every time the slurry tank is within a buffer, the slurry tanks is selected. If a slurry tank is within 3 buffers, that slurry tank will be three times in the resulting query.

Also note that the spatial operators Within (and the opposite Contains) both work well when comparing points and regions, as they compare the centroid of the point with the region. However is you are comparing regions with regions or polylines, you should use Intersects. If you are using Within the result is close to unpredictable as the centroid of a region can be everywhere within the region.