pyrsgis.raster.north_east_coordinates¶
- pyrsgis.raster.north_east_coordinates(ds, arr, layer='both')[source]¶
Generate arrays with cell latitude and longitude value.
This function can generate arrays that contain the centroid latitude and longitude values of each cell.
- Parameters
- dsdatasource object
A datasource object of a raster, typically generated using the
pyrsgis.raster.read
function.- arrarray
A 2D or 3D array of the raster corresponding to the daasource object.
- layerstring
Either of these options: ‘both’, ‘north’, ‘east’
- 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.
The generated latitude and longitude arrays can be exported using the following:
>>> raster.export(north_arr, ds, r'E:/path_to_your_file/northing.tif', dtype='float32') >>> raster.export(east_arr, ds, r'E:/path_to_your_file/easting.tif', dtype='float32')