pyrsgis.raster.north_east¶
- pyrsgis.raster.north_east(arr, layer='both', flip_north=False, flip_east=False)[source]¶
Generate row and column number arrays
This function can generate 2D arrays containing row or column number of each cell, which are referred to as northing and easting arrays here.
- Parameters
- arrarray
A 2D or 3D numpy array.
- layerstring
Either of these options: ‘both’, ‘north’, ‘east’
- flip_northboolean
Whether to flip the northing array. If True, the array will be flipped such that the values increase from bottom to top instead of top to bottom, which is the default way.
- flip_eastboolean
Whether to flip the easting array. If True, the array will be flipped such that the values increase from right to left instead of left to right, which is the default way.
- Returns
- array(s)2D numpy array(s)
If
layers
argument was left default or set to ‘both’, then the function returns a tuple of both the northing and easting arrays. Otherwise, either northing or easting array will be returned depending on thelayers
argument.
Examples
>>> from pyrsgis import raster >>> input_file = r'E:/path_to_your_file/your_file.tif' >>> ds, data_arr = raster.read(your_file) >>> north_arr, east_arr = raster.north_east(data_arr) >>> print(north_arr.shape, east_arr.shape)
The above line will generate both the arrays of same size as the input array. If you want either of north or east rasters, you can do so by specifying the
layer
parameter:>>> north_arr = raster.north_east(data_arr, layer='north')
To check, you can display them one by one using matplotlib:
>>> from matplotlib import pyplot as plt >>> plt.imshow(north_arr) >>> plt.show() >>> plt.imshow(east_arr) >>> plt.show()
The arrays will be displayed as image one by one. You can hover over the displayed image to check the cell values. If you wish to flip the northing array upside down or easting array left to right, you can do so by specifying the
flip_north
and/orflip_east
toTrue
.>>> north_arr, east_arr = raster.north_east(data_arr, flip_north=True, flip_east=True)
You can again display these new arrays and hover the mouse to check values, which will now be different from the default ones.