I'm using MapInfo and would like to achieve the following:

Find out all the points that fall within any of the polygons on screen, and which polygons they are contained within.

The data I am working with:

enter image description here

As you can see, there are about 30 different layers. So far I can only see myself going through each table with an SQL statement as I cannot seem to do it in bulk (or statement between multiple tables generates errors regarding join), but then this could produce 30 different files that then need sorting.

Is it possible to do an update table? For example a new column titled "Overlap" which will print the name of the polygon it is contained in or the layer name.

I am open to suggestions.


You will need to do individual queries for each polygon layer. Or you would need to merge all the polygon layers and then join this new layer/table with the point table.

You can update a field in the point table with the name of the polygon or the polygon table name. That might be the best solution.

The best approach would be to do this via a MapBasic tool but we can mimic it using the MapBasic window even though you will have to do the looping by hitting the Enter key 30 times.

First open the point table so that it's the first table opened.

Next open the 30'ish tables to compare with the point table.

Use these statements to select and update the points within a polygon in the polygon table with the name of the polygon table:

Dim sTab As String
Dim aCol As Alias
sTab = TableInfo(2, 1)
aCol = sTab + ".OBJ"
Print "Joining with " + sTab + ". Still " + (NumTables() - 2) + " tables to go"
Select points.OVERLAPTABLE
  From points, sTab
  Where points.obj Within aCol
  Into __TO__BE__UPDATED NoSelect
Print "   " + TableInfo("__TO__BE__UPDATED", 8) + " overlaps"
Close Table sTab
Undim sTab
Undim aCol

You can copy and paste these lines into the MapBasic window, highlight all the lines and hit Enter. This will run all the statements. Hit Enter again until the Message window say "... 0 tables to go"

Note that I have used "points" for the table containing points and "overlaptable" for the column that should be updated with the name of the tables. You can use other names if you prefer.

The names of the other tables, the 30 polygon tables, are read using a MapBasic function at runtime.

Now if you expect some points to be within polygons from multiple tables and you want to know which, you will have to do the update a bit differently. Use this statement for the update:

  • I have tried your code and input my own table names but received this error: imgur.com/a/5gUiP This error also occurs with your second update statement regarding multiple polygons (which I wish to use). My points table name is "edubase___Waltham_Forest_extra" I have created the column to be updated as "Policy_Overlap" Your instructions are clear but i've never used MapBasic before, so sorry if this is an easily solved problem – Jonathan West Aug 31 '16 at 11:21
  • Turns out reloading all the program made the script work. It prints the following: Joining with Major_Opportunity_Sites. Still 3 tables to go 0 overlaps Joining with Mayoral_Development_Corporatio. Still 2 tables to go 0 overlaps Joining with Metropolitan_Green_Belt. Still 1 tables to go 1 overlaps Joining with Metropolitan_Open_Land. Still 0 tables to go 0 overlaps Is this the final output? As it is not updating the column I have chosen with any information. – Jonathan West Aug 31 '16 at 11:42
  • The messages in the message window tells me that only 1 table overlaps: Metropolitan_Green_Belt. You should be able to find that name in the column Policy_overlap in the table edubase___Waltham_Forest_extra. Your points table should have some unsaved edits which should let us know that some updates have been made – Peter Horsbøll Møller Aug 31 '16 at 11:44
  • yeah, the error tries to tell you that you can't dim a variable again - you need to undim it first which is what I do in the last two lines. – Peter Horsbøll Møller Aug 31 '16 at 11:46
  • 1
    I've done that and it all worked! Thanks so much. Never knew about MapBasic but it's something i'll definitely look at in the future. Thanks for all your help! – Jonathan West Aug 31 '16 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.