Shortest distance between a point and edge of the polygon

1,812 views
Skip to first unread message

aguy01

unread,
Sep 18, 2011, 8:44:13 PM9/18/11
to MapInfo-L
I have a table that has set of points with lat/long - Table 1. Also
there is a polygon - Polygon1. None of the points in Table1 are within
the polygon. How can I write a sql statements to find the shortest
distance between the edge of the polygon and each data point in the
Table1. Each point is located at a certain distance from the edge of
the polygon.

e.j.h.polle

unread,
Sep 19, 2011, 7:36:28 AM9/19/11
to MapInfo-L
Hi,

The trick here is to use the Nearest statement to draw lines between
the point objects and the closest point on the edge of the polygon.

For this to work the point objects and the polygon should be in
different tables and you need to create a new table to store the
results of the Nearest statement. You can not do this via Query > SQL
Select... You will need to use your MapBasic window here (and maybe
have a look in the MapBasic help or MapBasic Reference Guide for more
details on the Nearest statement)

Step 1: Create a new table (e.g. DistanceResults) with 3 columns: one
to hold the identifier of the Polygon, one to hold the identifier of
the Points and one for the Distance.

Step 2: The statement: Nearest All from table <PolygonTable> to
<PointsTable> into DistanceResults Data <Polygon ID>=<Polygon ID>,
<Point ID>=<Point ID>

(This statement will create 2-point polyline objects between the
points and the polygon - these line objects can be made visible by
adding the DistanceResults table to the Map Window)

Step 3: Update the Distance column in the DistanceResults table, using
either (depending on your projection/coordinate system) the function
ObjectLen or the the function CartesianObjectLen.


It might require some trial-and-error, but the moment you have got
this running you will be amazed :-)

HTH,

Egge-Jan

Kelly Counts

unread,
Nov 11, 2016, 1:51:46 PM11/11/16
to MapInfo-L
Thank you!!   This was super helpful.  Got it to run.  Thanks!
Reply all
Reply to author
Forward
0 new messages