According to the the MapBasic v17 documentation a code snippets for GetGridCellValue() provides a conversion from Earth Coordinates to x_grid and y_grid. GetGridCellValue(tableid, x_grid, y_grid) always fail with error: argumet 2 out of range.
I cannot find the reference to GRIDTOOL.MBX (MapInfo\Professional\Tools) in MapInfo v16 or 17. I think it was a old tool for the 32bit platform. It's no longer available.
With the 64 bit versions of MapInfo Pro we changed how MapInfo Pro works with grids. Grids are now "just" a raster and not a special type of raster. Unfortunately that also meant that the dedicated grid functions of the MapBasic language no longer will work.
Unless you of course have some existing grid files and open these into MapInfo Pro. That could be grids created with Vertical Mapper. In that case case, I think Pro will still see these as grid files.
I have attached a small source code example that shows the basics of reading a value from a grid for a specific coordinate. Please note that my example expects the coordinate to use the same coordinate system as the grid.
If you are working with grids as raster files, I'd recommend that you take a closer look at the Raster SDK that comes with MapInfo Pro Advanced. For example the GetPointCellValues method can be used to enrich a table of points with data from your grid(s).
public static void GetPointCellValues(
FieldBandFilter fieldBandFilters = null,
IRasterProgressTracker progressTracker = null)
The Raster SDK is .NET based so it would be easier to write this logic using a .NET based language like C#.
Over the last few days I came up with similar code from my old library, but it always fail with the following error: GetGridCellValue: argument 2||3 out of range. Note that I need to get values from a *.mig, *.grd, *.grc and *.dem files.
Could it be the coordinates that are outside the extent of the grid file?
Could you share your code?
I finally had the time to revisit this. And thanks to you I found the error. I had the boundary of the grid flipped so at time I was trying to read outside the bounds of the grid. thus raising the range error for GetGridCellValue() arg 2 or 3.
I found a little bug in you bound check line 153 of you example:
If lCol < 0 Or lRow < 0 Or lCol >= plWidth Or lRow >= plHeight Then
If ((lCol >= 0 And lCol <= plWidth) And (lRow >= 0 And lRow <= plHeight)) Then
Good to hear you made it work, Jacques.
The original code also has code for handling maps where image reprojection has been turn on. I decided to keep it simple for this example.
We could probably share the code for the tool but it might be a bit obsolete for 64 bit.