Re: MI Grid file
Here is an update to the MapBasic sample code I posted earlier that contains fixes to a couple of items pointed out by careful readers. ' * ' Copyright (c) 2000, MAPINFO CORPORATION ' All rights reserved. ' ' $Workfile: GridInfo.mb $ ' $Revision: 1.1 $ ' $Author: DRESSEL $ ' $Date: May 22 2000 16:14:56 $ ' ' Module Description: ' ' MapBasic program to retrieve grid info. ' ' Revision History: ' 'Rev 1.0 May 22 2000 16:14:56 DRESSEL 'Rev 1.1 June 6 2000 13:30:00 DRESSEL ' Check for minimum version of MapInfo Professional (5.5) ' Add support for Northwood's NWGRD30.GHL grid handler ' Fix bug with button help message ' Fix typo refering to 'rotatesymbols' ' * Include "MapBasic.def" Include "Menu.def" Include "Icons.def" Declare Sub Main Declare Sub GridInfoToolHandler Declare Sub About Declare Sub GoodBye Define AppVersion 1.1 'Note: All MapBasic funtion variables are passed by reference unless ' explicitly defined to be passed directly with the 'ByVal' key word. Declare Function GE_OpenGrid Lib "Migrid.dll" ( lpszFilename As String, ByVal lCacheSize As Integer, hGrid As Integer) As Logical Declare Function GE_GetCoordSysInfo Lib "Migrid.dll" ( ByVal hGrid As Integer, ptchCoordSys As String, pdMinXVal As Float, pdMinYVal As Float, pdMaxXVal As Float, pdMaxYVal As Float) As Logical Declare Function GE_GetContinuousMinMax Lib "Migrid.dll" ( ByVal hGrid As Integer, pdMinZVal As Float, pdMaxZVal As Float) As Logical Declare Function GE_GetDimensions Lib "Migrid.dll" ( ByVal hGrid As Integer, plWidth As Integer, plHeight As Integer) As Logical Declare Function GE_StartRead Lib "Migrid.dll" ( ByVal hGrid As Integer) As Logical Declare Function GE_GetContinuousValue Lib "Migrid.dll" ( ByVal hGrid As Integer, ByVal lCol As Integer, ByVal lRow As Integer, pdValue As Float, puchIsNull As SmallInt) As Logical Declare Function GE_EndRead Lib "Migrid.dll" ( ByVal hGrid As Integer) As Logical Declare Function GE_CloseGrid Lib "Migrid.dll" ( hGrid As Integer) As Logical Global gsPath As String Sub Main OnError Goto HandleError If SystemInfo(SYS_INFO_MIVERSION) < 550 Then Note "This utility depends on the Grid Engine API of " + "MapInfo Professional version 5.5 or higher to run." Exit Sub End If Create Menu "&Grid Info" As "&About Grid Info..." Calling About, "E&xit Grid Info" Calling Goodbye Alter Menu "Tools" Add "&Grid Info" As "&Grid Info" Alter ButtonPad "Tools" Add Separator ToolButton Calling GridInfoToolHandler Icon MI_ICON_INFO Cursor MI_CURSOR_CROSSHAIR DrawMode DM_CUSTOM_POINT HelpMsg "Retrieve value from grid cell.\nRetrieve grid value" Show Exit Sub HandleError: Note "Main: " + Error$() Resume Next End Sub Sub GridInfoToolHandler OnError Goto HandleError Dim sCmd As String Dim i As SmallInt Dim lVerbose As Logical Dim x, y As Float Dim MapWindowID As Integer Dim lReturn As Logical Dim hGrid As Integer Dim sPath As String Dim ptchCoordSys As String Dim pdMinXVal, pdMinYVal, pdMaxXVal, pdMaxYVal As Float Dim pdMinZVal, pdMaxZVal As Float Dim plWidth, plHeight As Integer Dim lCol, lRow As Integer Dim pdValue As Float Dim puchIsNull As SmallInt MapWindowID = FrontWindow() If WindowInfo( MapWindowID, WIN_INFO_TYPE) <> WIN_MAPPER Then Note "Click in a map window." Exit Sub End If For i = 1 To MapperInfo(MapWindowID, MAPPER_INFO_LAYERS) If LayerInfo(MapWindowID, i, LAYER_INFO_TYPE) = LAYER_INFO_TYPE_GRID Then sPath = LayerInfo(MapWindowID, i, LAYER_INFO_PATH) Exit For End If Next sPath = Left$(sPath, Len(sPath)-3) + "MIG" If Not FileExists(sPath) Then If FileExists(ProgramDirectory$() + "Nwgrd30.ghl") Then sPath = Left$(sPath, Len(sPath)-3) + "GRD" End If End If If Not FileExists(sPath) Then Note "Cannot find grid file " + sPath Exit Sub End If If sPath <> gsPath Then gsPath = sPath lVerbose = TRUE Else lVerbose = FALSE End If sCmd = "Set " + MapperInfo(MapWindowID, MAPPER_INFO_COORDSYS_CLAUSE_WITH_BOUNDS) Run Command sCmd x = CommandInfo(CMD_INFO_X) y = CommandInfo(CMD_INFO_Y) Print "X = " + x + ", Y = " + y lReturn = GE_OpenGrid(sPath, 1024, hGrid) If Not lReturn Then Note "Open " + sPath + " failed" Exit Sub End If If hGrid = 0 Then Note "Open " + sPath + " failed: grid handle = 0" Exit Sub End If If lVerbose Then Print " Opened " + sPath + " with handle " + hGrid End If ptchCoordSys = Space$(255) 'Initialize to allocate actually memory. lReturn = GE_GetCoordSysInfo(hGrid, ptchCoordSys, pdMinXVal
Re: MI Grid file
>I have had a bit of a go at using the API from Delphi, but just can't get >things working. The problem seems to be what the hGrid relates to in >Delphi. Can anybody provide a simple Delphi example that, for example, >opens a grid and reads a value at x,y ? > >There have been a few questions regarding this on the list so I suspect I >am not alone. and >I got the documentation for the grid engine from MapInfo (a file named >grideng30.exe containing 2 word files). It did contain documentation for the >Grid API functions, but missed a description of the various C-structures (or >records in Pascal) used by the API. > >It it possible for you to publish the missing documentation for these >C-structures, or - best of all - a simple C or Delphi (working) example with >source code.?? I don't have access to Delphi nor Pascal, but here is an example that demonstrates using the GridEngine from MapBasic. This sample program opens a grid file and retrieves a value from it. Give it a try. ' * ' Copyright (c) 2000, MAPINFO CORPORATION ' All rights reserved. ' ' $Workfile: GridInfo.mb $ ' $Revision: 1.0 $ ' $Author: DRESSEL $ ' $Date: May 22 2000 16:14:56 $ ' ' Module Description: ' ' MapBasic program to retrieve grid info. ' ' Revision History: ' 'Rev 1.0 May 22 2000 16:14:56 DRESSEL ' * Include "MapBasic.def" Include "Menu.def" Include "Icons.def" Declare Sub Main Declare Sub GridInfoToolHandler Declare Sub About Declare Sub GoodBye Define AppVersion 1.0 'Note: All MapBasic funtion variables are passed by reference unless ' explicitly defined to be passed directly with the 'ByVal' key word. Declare Function GE_OpenGrid Lib "Migrid.dll" ( lpszFilename As String, ByVal lCacheSize As Integer, hGrid As Integer) As Logical Declare Function GE_GetCoordSysInfo Lib "Migrid.dll" ( ByVal hGrid As Integer, ptchCoordSys As String, pdMinXVal As Float, pdMinYVal As Float, pdMaxXVal As Float, pdMaxYVal As Float) As Logical Declare Function GE_GetContinuousMinMax Lib "Migrid.dll" ( ByVal hGrid As Integer, pdMinZVal As Float, pdMaxZVal As Float) As Logical Declare Function GE_GetDimensions Lib "Migrid.dll" ( ByVal hGrid As Integer, plWidth As Integer, plHeight As Integer) As Logical Declare Function GE_StartRead Lib "Migrid.dll" ( ByVal hGrid As Integer) As Logical Declare Function GE_GetContinuousValue Lib "Migrid.dll" ( ByVal hGrid As Integer, ByVal lCol As Integer, ByVal lRow As Integer, pdValue As Float, puchIsNull As SmallInt) As Logical Declare Function GE_EndRead Lib "Migrid.dll" ( ByVal hGrid As Integer) As Logical Declare Function GE_CloseGrid Lib "Migrid.dll" ( hGrid As Integer) As Logical Global gsPath As String Sub Main OnError Goto HandleError Create Menu "&Grid Info" As "&About Grid Info..." Calling About, "E&xit Grid Info" Calling Goodbye Alter Menu "Tools" Add "&Grid Info" As "&Grid Info" Alter ButtonPad "Tools" Add Separator ToolButton Icon MI_ICON_INFO HelpMsg "Retrieve grid value" Cursor MI_CURSOR_CROSSHAIR DrawMode DM_CUSTOM_POINT Calling GridInfoToolHandler Show Exit Sub HandleError: Note "Main: " + Error$() Resume Next End Sub Sub GridInfoToolHandler OnError Goto HandleError Dim sCmd As String Dim i As SmallInt Dim lVerbose As Logical Dim x, y As Float Dim MapWindowID As Integer Dim lReturn As Logical Dim hGrid As Integer Dim sPath As String Dim ptchCoordSys As String Dim pdMinXVal, pdMinYVal, pdMaxXVal, pdMaxYVal As Float Dim pdMinZVal, pdMaxZVal As Float Dim plWidth, plHeight As Integer Dim lCol, lRow As Integer Dim pdValue As Float Dim puchIsNull As SmallInt MapWindowID = FrontWindow() If WindowInfo( MapWindowID, WIN_INFO_TYPE) <> WIN_MAPPER Then Note "Click in a map window." Exit Sub End If For i = 1 To MapperInfo(MapWindowID, MAPPER_INFO_LAYERS) If LayerInfo(MapWindowID, i, LAYER_INFO_TYPE) = LAYER_INFO_TYPE_GRID Then sPath = LayerInfo(MapWindowID, i, LAYER_INFO_PATH) Exit For End If Next sPath = Left$(sPath, Len(sPath)-3) + "MIG" If sPath <> gsPath Then gsPath = sPath lVerbose = TRUE Else lVerbose = FALSE End If sCmd = "Set " + MapperInfo(MapWindowID, MAPPER_INFO_COORDSYS_CLAUSE_WITH_BOUNDS) Run Command sCmd x = CommandInfo(CMD_INFO_X) y = CommandInfo(CMD_INFO_Y) Print "X = " + x + ", Y = " + y lReturn = GE_OpenGrid(sPath, 1024, hGrid) If lReturn Then If lVerbose Then Print " Opened " + sPath + " with handle " + hGrid End If If hGrid <> 0 Then ptchCoordSys = Space$(255) 'Initialize to allocate actually memory. lReturn = GE_GetCoordSysInfo(hGrid, ptchCoordSys, pdMinXVal, pd
Re: MI Grid file
Andrew, I have had a bit of a go at using the API from Delphi, but just can't get things working. The problem seems to be what the hGrid relates to in Delphi. Can anybody provide a simple Delphi example that, for example, opens a grid and reads a value at x,y ? There have been a few questions regarding this on the list so I suspect I am not alone. Regards Neil Moseley [EMAIL PROTECTED] >1. Based on the definition of these functions from the API, the size limit >appears to be about 2,147,483,648 x 2,147,483,648, but I'm sure practical >limitations become apparent long before that. > > BOOL GRIDENGFUNCTION GE_GetContinuousValue(GE_HGRID hGrid, >long lCol, long lRow, double *pdValue, unsigned char *puchIsNull); > > BOOL GRIDENGFUNCTION GE_GetDimensions(GE_HGRID hGrid, long *plWidth, >long *plHeight); > > BOOL GRIDENGFUNCTION GE_WriteContinuousValue(GE_HGRID hGrid, >long lCol, long lRow, double dValue); > >2. No, the IDW algorithm is just one way to create a grid file. > >3. I know that ESTI-Map in Moscow has written a TIN-based interpolator, > and Mercator Geosystems has others. > >4. MapInfo Professional 5.5 (and now 6.0) includes a DEM2GRID utility. > >The complete API for the Grid Engine is available upon request. > >-- >To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put >"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED] > -- To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]
Re: MI Grid file
>Does anyone have experience of using either large grid files or tiled grid >files to represent, for example, elevation data? We have some. >We're trying to determine the best way to distribute DEM data for use by >MapInfo Professional (without add-in's). Options we've considered are: (1) >points (2) square cells as regions and (3) .mig files. Given around 10 >million readings, option 1 would be bulky and option 2 even more so! >Specific questions on .mig files- (1) what is the size limit? (2) is the >limit related to the IDW algorithm? (3) are there alternative algorithms? >(4) has anyone written a .mig loader, say from a point file? 1. Based on the definition of these functions from the API, the size limit appears to be about 2,147,483,648 x 2,147,483,648, but I'm sure practical limitations become apparent long before that. BOOL GRIDENGFUNCTION GE_GetContinuousValue(GE_HGRID hGrid, long lCol, long lRow, double *pdValue, unsigned char *puchIsNull); BOOL GRIDENGFUNCTION GE_GetDimensions(GE_HGRID hGrid, long *plWidth, long *plHeight); BOOL GRIDENGFUNCTION GE_WriteContinuousValue(GE_HGRID hGrid, long lCol, long lRow, double dValue); 2. No, the IDW algorithm is just one way to create a grid file. 3. I know that ESTI-Map in Moscow has written a TIN-based interpolator, and Mercator Geosystems has others. 4. MapInfo Professional 5.5 (and now 6.0) includes a DEM2GRID utility. The complete API for the Grid Engine is available upon request. -- To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]