lidario.Translator

Convert a raster (.tif) or a rasterio.mask into a point cloud (x, y, z). See the examples for more details about how to use this class.

class lidario.Translator(input_type, output_type, affine_transform=True, metadata=False)[source]

Instantiate a Translator object which will handle the translation between given input and desired output type.

Parameters
  • input_type (str) –

    Type of raster data provided: “geotiff” or “mask”.

    • ”geotiff”: a .tif raster file.

    • ”mask”, a rasterio.mask.mask() result.

  • output_type (str) –

    Type of point cloud data to return: “csv”, “numpy”, “pandas”, “dictionary”, “list”, “tuple”.

    • ”csv”: a CSV file.

    • ”ply”: a .ply file.

    • ”numpy”: a Numpy array. Alternatives: “np”, “array”.

    • ”dataframe”: A Pandas dataframe: Alternatives: “pandas”, “pd”, “df”.

    • ”dictionary”: A pure Python dictionary: Alternative: “dict”.

    • ”list” a pure Python list.

    • ”tuple”: a pure Python tuple.

  • affine_transform (bool, optional) – If True (default), apply an affine geo-transformation to the translated coordinates.

  • metadata (bool, optional) – If True, the “translate” method will return a tuple with the point cloud and the metadata. If False (default), it will only return the point cloud.

translate(input_values, out_file='output1.csv', out_format='binary', no_data=None, decimal=None, transpose=False, band=1)[source]

Translate a given “input_values” into a X, Y, Z point cloud.

Parameters
  • input_values (str or np.array) –

    Data values to translate. Depend on the Translator’s “input_type” parameter:

    • For a “geotiff”: Takes the path to your .tif file (string).

    • For a “mask”: Takes the np.array returned by a rasterio.mask.mask() method.

  • out_file (str, optional) – Name of the file to save the point cloud. Used only if the Translator’s “output_type” is a file type: “csv”, “ply”. Optional, default: “output.csv”.

  • out_format – Data format to save the file: “binary” (default) or “ascii” (not recommended, may be slow). Used only when “ply” is specified as “output_type”. Optional.

  • no_data (int, optional) –

    Value to exclude from the translation.

    • For a “geotiff”: By default, use the nodata value stored in the tif file. If this value is missing, use -9999.

    • For a “mask”: By default, use -9999.

  • band (bool, optional) – Band of the raster to translate. Used only if Translator’s “input_values” is “geotiff”. Default: 1.

  • decimal (int, optional) – Round the coordinate numbers to the given decimal. Default: None.

  • transpose (bool, optional) – If True, transpose the coordinates. Default: False.

  • out_format – str, optional

Returns

The translated point cloud, typed as specified. If Translator’s “output_type” is set to “csv”, return None instead and save the CSV file. If Translator’s “metadata” is set to True, return a tuple with the point cloud and the metadata.