remotior_sensus.tools.raster_edit module
Raster edit.
This tool allows for the direct editing of a raster band. Warning, this tool edits the original input raster.
Typical usage example:
>>> # import Remotior Sensus and start the session
>>> import remotior_sensus
>>> rs = remotior_sensus.Session()
>>> # start the process
>>> edit = rs.raster_edit(raster_path='input_path',
... vector_path='vector_path')
- remotior_sensus.tools.raster_edit.check_expression(expression, constant_value)
- remotior_sensus.tools.raster_edit.raster_edit(raster_path: str, vector_path: None | str = None, field_name: None | str = None, expression: None | str = None, constant_value: None | int | float = None, old_array: ndarray | None = None, column_start: None | int = None, row_start: None | int = None, available_ram: None | int = None, progress_message: bool | None = True) OutputManager
Edit a raster band based on a vector file.
This tool allows for editing the values of a raster using a vector file. All pixel intersecting the vector will be edited with a new value. New pixel values can be a constant value or defined by a custom expression defining a condition. The input raster is directly edited, without producing a new file.
- Parameters:
raster_path – path of raster used as input.
vector_path – string of vector path (optional for undo operation).
field_name – string of vector field name.
expression – optional conditional expression; pixels are edited if intersecting the vector and the expression is True; the variable “raster” is used to refer to the raster pixel values; e.g. where(“raster” > 500, 10, “raster”).
constant_value – optional new value for pixels.
old_array – optional previous array for undo operation.
column_start – optional starting column for undo operation.
row_start – optional starting row for undo operation.
available_ram – number of megabytes of RAM available to processes.
progress_message – if True then start progress message, if False does not start the progress message (useful if launched from other tools).
- Returns:
- object
OutputManager()
with extra = {‘old_array’: previous array for undo operation, ‘column_start’: starting column for undo operation, ‘row_start’: starting row for undo operation}
- object
Examples
- Perform the edit of a raster
>>> edit_1 = raster_edit(raster_path='input_path', ... vector_path='output_path')
- Perform the undo of edit of a raster
>>> edit_2 = raster_edit(raster_path='input_path', ... column_start=edit_1.extra['column_start'], ... row_start=edit_1.extra['row_start'], ... old_array=edit_1.extra['old_array'] ... )
- Perform the edit of a raster with condition
>>> edit_3 = raster_edit(raster_path='input_path', ... vector_path='output_path', ... expression='where("raster" > 500, 10, "raster")' ... )