Skip to content

Instantly share code, notes, and snippets.

@alamsal
Last active September 3, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamsal/e70b8528a59c9754e5ca to your computer and use it in GitHub Desktop.
Save alamsal/e70b8528a59c9754e5ca to your computer and use it in GitHub Desktop.
GDAL: Python's alternative to ReadAsArray in C#
//Let's assume you read pixels of a band with width x height dimensions:
byte[] bits = new byte[width * height];
band.ReadRaster(0, 0, width, height, bits, width, height, 0, 0);
//Now, you can calculate index of a pixel according to this formula: column + row * width
for (int col = 0; col < width; col++)
{
for (int row = 0; row < height; row++)
{
// equivalent to bits[col][row] if bits is 2-dimension array
byte pixel = bits[col + row * width];
}
}
//Source: http://stackoverflow.com/questions/1238897/gdal-c-sharp-readasarray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment