I have a project which I am reviving after a gap of some years. It involves several hundred runs within MapInfo, scripted in MapBasic.
At one point within each run, I have six tables, each of a single cell.
These tables are called:
minBNGy maxBNGx minBNGy maxBNGy medBNGx medBNGy
They are min, max and median British National Grid coordinates. Each table is mappable, with a single point.
In each case, the table's single variable has the same name as the table.
Each is a long integer, but for some (probably deliberate) reason I no longer understand, I created these as floats.
I need to compile from these six tables a single table, with the six named cells and their values on a single row. It does not need to be mappable.
I was using this:
Add Column TARGET_TABLE (NEW_VARIABLE)From SOURCE_TABLE
Set To SOURCE_VARIABLE
Where COL1 = COL1
... but it no longer seems to work.
In my old code, the 'map' was dropped later.
I am using MapInfo / MapBasic v.6.5 on Windows 7 Ultimate 64-bit.
1 Answer 1
The solution was derived with assistance from Peter Horsbøll Møller:
' ================================================
' CALCULATE MIN AND MAX X COORDINATES OF CLUSTER
Open Table Spy60_O as Spy60 Interactive
Dim fMinX As Float
Select * from Spy60 order by caseNo into xSorted
Browse * From xSorted
Fetch First From xSorted
fMinX = xSorted.BNGx
Close Table xSorted
Dim fMaxX As Float
Select * from Spy60 order by caseNo Desc into xReverseSorted
Browse * From xReverseSorted
Fetch First From xReverseSorted
fMaxX = xReverseSorted.BNGx
Close Table xReverseSorted
' CALCULATE MIN AND MAX Y COORDINATES OF CLUSTER
Dim fMinY As Float
Select * from Spy60 order by caseNo into ySorted
Browse * From ySorted
Fetch First From ySorted
fMinY = ySorted.BNGy
Close Table ySorted
Dim fMaxY As Float
Select * from Spy60 order by caseNo Desc into yReverseSorted
Browse * From yReverseSorted
Fetch First From yReverseSorted
fMaxY = yReverseSorted.BNGy
Close Table yReverseSorted
' ================================================
'
' CALCULATE MEDIAN CENTRE X AND Y COORDINATES OF CLUSTER
'
'from: http://testdrive.mapinfo.com/TECHSUPP/MIPROD.NSF/59d125f456480edb852562b5004f2c33/daeed8326071ce0c85256b89005a72ad?OpenDocument
'
' ================================================
'
Browse * From Spy60
dim MedianTableX as string, ColNameX as string, nX as integer
MedianTableX="exTable"
ColNameX="exColumn"
Select BNGx from Spy60 Order By BNGx Into MedianTempX NoSelect
nX=TableInfo(MedianTempX, 8)
Select Avg(BNGx)from MedianTempX where RowID=int((nX+1)/2) or RowID=int((nX+2-(nX mod 2))/2) into MedianFinalX NoSelect
Browse * from MedianFinalX
Commit Table MedianFinalX As medBNGx_O
Open Table medBNGx_O as medBNGx Interactive
Dim fMedX As Float
fMedX = medBNGx._COL1
Browse * From Spy60
dim MedianTableY as string, ColNameY as string, nY as integer
MedianTableY="exTable"
ColNameY="exColumn"
Select BNGy from Spy60 Order By BNGy Into MedianTempY NoSelect
nY=TableInfo(MedianTempY, 8)
Select Avg(BNGy)from MedianTempY where RowID=int((nY+1)/2) or RowID=int((nY+2-(nY mod 2))/2) into MedianFinalY NoSelect
Browse * from MedianFinalY
Commit Table MedianFinalY As medBNGy_O
Open Table medBNGy_O as medBNGy Interactive
Dim fMedY As Float
fMedY = medBNGy._COL1