Last active
September 3, 2015 21:26
-
-
Save alamsal/e70b8528a59c9754e5ca to your computer and use it in GitHub Desktop.
GDAL: Python's alternative to ReadAsArray in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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