Translator

These examples illustrate how to use lidario.Translator to translate point cloud data.

Tif file to Pandas dataframe

Transform raster (.tif) file into a pandas.Dataframe.

import lidario as lio

# Instantiate a Translator object which take a tif file
# and return a dataframe.
translator = lio.Translator("geotiff", "dataframe")

# Translate the tif file and get the pandas.Dataframe
point_cloud = translator.translate("/path/to/file.tif")

Rasterio.mask to Numpy array

Transform a rasterio.mask into a Numpy array.

import rasterio
from rasterio.mask import mask
import lidario as lio

# Instantiate a Translator object which take rasterio.mask
# and return a numpy array.
translator = lio.Translator("mask", "numpy")

# Load a raster and create a polygon shape
reader = rasterio.open("/path/to/file.tif")
shape = [{'type': 'Polygon', 'coordinates': [[(0, 0),  (0, 10), (10, 10), (0, 0)]]}]

# Crop the tif file with the shape
mask_values = rasterio.mask.mask(reader, shapes=shape, crop=True)

# Translate the mask_values and get the np.array
point_cloud = translator.translate(mask_values)

Translate to CSV and get metadata

Transform a raster (.tif) file into a CSV without applying the affine geo-transformation, and get the metadata.

import lidario as lio

# Instantiate a Translator object which take a tif file,
# save the point cloud to a CSV and return the metadata.
translator = lio.Translator("geotiff", "csv", affine_transform=False, metadata=True)

# With metadata=True, translator return a tuple with
# the point cloud and the metadata.
point_cloud, metadata = translator.translate("/path/to/file.tif")

In this case, the point_cloud is None, because we save the values to a CSV file.

Translate to PLY file

Transform a raster (.tif) file into a PLY (.ply) file.

import lidario as lio

# Instantiate a Translator object which take a tif file
# and the point cloud to a PLY file.
translator = lio.Translator("geotiff", "ply")

# Translate the tif to a binary .ply file
translator.translate("/path/to/file.tif", out_format="binary")

# Translate the tif to a text .ply file (may be slow !)
translator.translate("/path/to/file.tif", out_format="ascii")