MapWinGIS:Grid GetRow
From MapWindow GIS
GetRow
Syntax
bool GetRow(int row, ref float vals)
Summary
This is a faster way to read the array values that are of a specific size. The row is the integer row to read from the grid object. The vals variable is actually the first element of the array of floats that you want to be populated with the values from the grid. Since arrays are stored sequentially in memory, passing the first element allows the prediction of where the other values must go. It is very important that you always dimension the array as being of type float, and always make sure that you dimension it from 0 to numCols - 1.
Parameters
| row | The Integer value of the row to retrieve values for. |
| vals | Reference to the first element of the array of floats that will hold the row of values. |
Returns
Boolean false if there was an error, true otherwise.
Visual Basic Net 2005 Example Implementation Code
'Requires reference to MapWinGIS 'mwSourceGrid is already instantiated and opened from an existing grid file 'SourceGrid is dimensioned as Dim SourceGrid(MaxCol, MaxRow) as Float Public Function CopySource(ByVal mwSourceGrid As MapWinGIS.Grid) As Single(,) Dim row, col As Integer Dim vals() As Single m_mrow = mwSourceGrid.Header.NumberRows - 1 m_mcol = mwSourceGrid.Header.NumberCols - 1 Dim SourceGrid(m_mcol, m_mrow) As Single For row = 0 To m_mrow ReDim vals(m_mcol) mwSourceGrid.GetRow(row, vals(0)) For col = 0 To m_mcol SourceGrid(col, row) = vals(col) Next Next Return SourceGrid End Function
Visual C# 2005 Example Implementation Code
// Reference to MapWinGIS required
// MapWinGIS.Grid object has already been instantiated and opened
// SourceGrid has already been dimensioned [MaxCol, MaxRow]
public bool CopySource(MapWinGIS.Grid mwSourceGrid, ref float[,] SourceGrid)
{
for (int row = 0; row <= pf_MaxRow; row++)
{
float[] vals = new float[pf_MaxCol];
// Read an entire row by passing the first element byref.
// The GetRow function will return all the values
mwSourceGrid.GetRow(row, vals[0]);
for (int col = 0; col <= pf_MaxCol; col++)
{
// Populate the SourceGrid by directly reading values from the grid
SourceGrid[col, row] = vals[col];
}
}
}//End CopySource
















