MapInfo Pro Developers User Group

Expand all | Collapse all

Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

  • 1.  Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-09-2018 02:31

    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.



  • 2.  RE: Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-13-2018 03:39

    Hi Jacques

    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(

    string inputTabFilePath,

    string[] inputRasterFilePaths,

    string outputTabFilePath,

    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#.



  • 3.  RE: Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-16-2018 15:02

    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.



  • 4.  RE: Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-17-2018 04:26

    Could it be the coordinates that are outside the extent of the grid file?

    Could you share your code?



  • 5.  RE: Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-21-2018 14:08

    Hello Peter,

    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

    should be

    If ((lCol >= 0 And lCol <= plWidth) And (lRow >= 0 And lRow <= plHeight)) Then

     

    Cheers,

    Jacques



  • 6.  RE: Need sample code for GetGridCellValue( table_id, x_pixel, y_pixel )

    Posted 08-21-2018 16:30

    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.