[GIS] How to Create Line Feature using two separate point features in MapInfo

mapbasicmapinfo

I have two MapInfo Tab files as Point feature. both the layer have the same unique ID. what I was trying to do is to connect both point using the same ID as a Line feature. so the end result will be "Line Feature" created by two separate point tab file. please help me to resolve this issue using MapBasic. currently I am using MapInfo 15.2.

enter image description here

Above image states two separate point feature that I was tying to connect which have same id field.

Best Answer

Let's assume your tables are called TABLE1 and TABLE2 and that your ID column is called ID in both tables.

'First you need to create a new empty table for the result
Create Table TABLE3 Using TABLE1 File "C:\Table3.tab"

'This tables should also be made mappable
Create Map For TABLE3 Using TABLE1

'Let's specify the coordinatesystem to use
Set CoordSys Table TABLE3

'And now we are using SQL to extract the necessary data from the tables
Select TABLE1.ID
   , CreateLine(CentroidX(TABLE1.OBJ), CentroidY(TABLE1.OBJ)
        , CentroidX(TABLE2.OBJ), CentroidY(TABLE2.OBJ)) "THELINE"
    From TABLE1, TABLE2
    Where TABLE1.ID = TABLE2.ID
    Into __TO__BE__INSERTED NoSelect

'And now let's insert the result into the new table
Insert Into TABLE3
    (ID, OBJ)
    Select ID, THELINE From __TO__BE__INSERTED 

Notice that I'm create a derived spatial object - the line - and giving the "column" an alias in the query: THELINE.

I can then refer to this derived spatial column when I insert the result into my new table.

Related Question