Purpose:
Determines the value of a grid cell if the cell is non-null.
Syntax:
GetGridCellValue( table_id, x_pixel, y_pixel )
table_id is a string representing a table name, a positive integer table number, or 0 (zero). The table must be a grid table.
x_pixel is the integer number of the X coordinate of the grid cell. Pixel numbers start at 0. The maximum pixel value is the (pixel_width-1), determined by calling
RasterTableInfo(...RASTER_TAB_INFO_WIDTH).
y_pixel is the integer number of the Y coordinate of the grid cell. Pixel numbers start at 0. The maximum pixel value is the (pixel_height-1), determined by calling
RasterTableInfo(...RASTER_TAB_INFO_HEIGHT).
Return Value
A Float is returned, representing the value of a specified cell in the table if the cell is non-null. The IsGridCellNull() function should be used before calling this function to determine if the cell is null or if it contains a value.
Getting Values into a Grid Cell Using a Coordinate
To get values into a grid cell using a coordinate, use the GridTools.MBX that installs in to the MapInfo\Professional\Tools folder. This tool gets grid value information from the geographic position.
To use MapBasic to get values into a grid cell using a coordinate, see the following example. It converts (x,y) coordinates to the grid table's coordinate system. It then uses the coordinates to calculate the grid row and column.
- If the first line is true, then (line 2:
Then
statement) the Reprojection option (set in the Map Options dialog, under Image Processing) is set to None. In this case, the Map window's projection is dictated by the Grid, so we can re-use the same x and y we already determined. - If the first line is not true, then (line 5:
Else
statement) the Map window may have been reprojected, in which case we recalculate the (x,y) coordinates using the coordsys of the Grid table before doing grid math.The nested
Else
statement (line 10) converts the x/y values from the map window's coordsys to the coordsys of the grid table.
If (MapperInfo(MapWindowID, MAPPER_INFO_REPROJECTION) = "None") And iVisibleImages = 1
Then
x_grid = x
y_grid = y
Else
If MapperInfo(MapWindowID, MAPPER_INFO_COORDSYS_CLAUSE) = TableInfo(sTable, TAB_INFO_COORDSYS_CLAUSE) Then
x_grid = x
y_grid = y
Else
csysConverter = CreatePoint(x, y)
Set CoordSys Table sTable
x_grid = CentroidX(csysConverter)
y_grid = CentroidY(csysConverter)
End If
End If