pyrsgis.raster.shift¶
- pyrsgis.raster.shift(ds, x=0, y=0, shift_type='coordinate')[source]¶
Shift the datasource of a raster file
This function can modify the geographic extent in the datasource object of the raster file. When the modified datasource object is used, the exported raster file will be shifted towards a given direction.
- Parameters
- dsdatasource object
A datasource object of the raster. Ideally, the datasource should be the same as one generated by the
pyrsgis.raster.readfunction.- shift_typestring
Available options are ‘coordinates’ and ‘cell’, which correspond to shifting the datasource either by the projection units of the raster or by number of cells respectively.
- xnumber
The amount of shift required in x direction (longitude). Please note that this can not be float value if the
shift_typeparameter is set to ‘cell’.- ynumber
The amount of shift required in y direction (latitude). Please note that this can not be float value if the
shift_typeparameter is set to ‘cell’.
- Returns
- new_dsdatasource object
A new modified datasource object which when used to export a raster will result in a shifted raster file.
Examples
>>> from pyrsgis import raster >>> infile = r'E:/path_to_your_file/your_file.tif' >>> ds, data_arr = raster.read(infile) >>> new_ds = raster.shift(ds, x=10, y=10) >>> print('Original bounding box:', ds.bbox) >>> print('Modified bounding box:', new_ds.bbox) Original geo transform: ([752895.0, 1405185.0], [814215.0, 1466805.0]) Modified geo transform: ([752905.0, 1405195.0], [814225.0, 1466815.0])
Notice that the bounding box values in the
dsobject have both shifted by 10 units. Negative values can be given to shift thedsonject in the opposite direction.The
dsobject can also be shifted by number of cells by switching theshift_typeparameter.>>> new_ds = raster.shift(ds, x=10, y=10, shift_type='cell') >>> print('Modified bounding box:', new_ds.GeoTransform) Modified geo transform: ([753195.0, 1405485.0], [814515.0, 1467105.0])
Notice that the modified
dsobject is now shifted by 10*cell size (30 - a Landsat data used for demonstration).The modified
dsobject can be used to export raste file.>>> raster.export(data_arr, new_ds, r'E:/path_to_your_file/shifted_file.tif')