-1

I'm trying to create a MapBasic tool which will automatically merge polygons when a line is drawn over the polygons I wish to merge. But I get an error 'Unrecognized command: Where' Here is my code. Can anyone see where I am going wrong please?

' Set the input and output table names
Dim inputTable As String
Dim outputTable As String
inputTable = "Input_Table"
outputTable = "Output_Table"

' Set the name of the line table
Dim lineTable As String
lineTable = "Line_Table"

' Create a new temporary table to hold the selected polygons
Dim tempTable As String
tempTable = "Temp_Table"
Create Table tempTable (Obj Integer, ID Integer)

' Select polygons that intersect the line
Insert Into tempTable (Obj, ID) Select * From inputTable Where Obj Intersects Any lineTable

' Merge the selected polygons into a single feature
Dim newObject As Object
Select * From tempTable Into newObject
Commit Table newObject As outputTable

' Clean up the temporary table
Drop Table tempTable
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
user8136435
  • 67
  • 1
  • 10

1 Answers1

0

Have a look at MabBasic documentation, it says

Insert Into table

[ ( columnlist ) ]

{ Values ( exprlist ) | Select columnlist From table }

There nothing mentioned about Where ...

You need a Select

Select expression_list
From table_name [ , ... ] [ Where expression_group ]
[ Into results_table [ Noselect ] ]
[ Group By column_list ]
[ Order By column_list ]

Would be like this:

Select inputTable.Obj, inputTable.ID 
From inputTable, lineTable 
Where inputTable.Obj Intersects lineTable.Obj
Into tempTable 

Just a tip, open a MabBasic Window in your MapInfo and run your operations manually. The MabBasic Window will print according code.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110