PreProcessing Module
The PreProcessing module contains functions for preprocessing LiDAR data in LAS format.
To import the module
import terravide.src.PreProcessing as LFP
Module Dependencies
The PreProcessing module has the following dependencies:
numpypandaslaspy
These modules must be installed before using the functions in this module.
API
Read_lasFile
- Read_lasFile(filepath: str) laspy.File
Reads a LAS file and returns a laspy File object.
- Parameters:
filepath (str) – The path to the LAS file to be read.
- Returns:
A laspy File object.
Here is an example of how to use the Read_lasFile function:
import terravide.src.PreProcessing as LFP
filepath = "/path/to/myfile.las"
lasfile = LFP.Read_lasFile(filepath)
This will read the LAS file located at filepath and return a laspy File object.
Create_lasFileDataframe
- Create_lasFileDataframe(lasfileObject: laspy.File) pd.DataFrame
Take a lasfile object after reading <filename>.las and convert into a Pandas Dataframe. The columns stored in the dataframe are {‘X’,’Y’,’Z’,’return_number’,’number_of_returns’}. The coordinates are in feet.
Args:
lasfileObject (_type_): lasfile Object after running Read_lasFile(filepath) function.
Returns:
lidar_Dataframe: Pandas Dataframe of lidar points as well as return number and number of returns for each data point.
Here is an example of how to use the Create_lasFileDataframe function:
import laspy
import pandas as pd
from PreProcessing import Create_lasFileDataframe
# Read a las file using laspy
las_file = laspy.read('my_las_file.las')
# Convert las file to Pandas DataFrame
lidar_df, rawPoints = Create_lasFileDataframe(las_file)
# Print the lidar data in the Pandas DataFrame
print(lidar_df)
Get_MRpoints
- Get_MRpoints(lidar_Dataframe: pd.DataFrame) pd.DataFrame
Filters Multiple Return points from a LiDAR DataFrame.
- Parameters:
lidar_Dataframe (pd.DataFrame) – A Pandas DataFrame containing lidar points and the number of returns for each point.
- Returns:
A filtered Pandas DataFrame containing only the points with multiple returns.
Here is an example usage of the Get_MRpoints function:
import pandas as pd
import terravide.src.PreProcessing as PreProcessing
# Create a Pandas DataFrame of LiDAR points
lidar_df = pd.read_csv("lidar_data.csv")
# Call the Get_MRpoints function to filter the DataFrame by multiple return points
filtered_df = PreProcessing.Get_MRpoints(lidar_df)
# Print the filtered DataFrame
print(filtered_df)
Get_SRpoints
- Get_SRpoints(lidar_Dataframe: pd.DataFrame) pd.DataFrame
Filter Single Return points from a lidar data frame
- Parameters:
lidar_Dataframe (pandas DataFrame) – Pandas DataFrame of lidar points as well as return number and number of returns for each data point.
- Returns:
Filtered points with number of returns = 1 as a pandas DataFrame.
LasTile Class
- class PreProcessing.lasTile
The lasTile class provides methods for preprocessing and dividing a LiDAR point cloud data tile into sub-tiles. The constructor takes two arguments:
LiDAR_Dataframe: A Pandas Dataframe object containing the LiDAR point cloud data.
TileDivision: An integer specifying the number of divisions to divide the tile into. The default value is 1, which means the tile is not divided.
Class attributes:
- lidar_DataframePandas DataFrame
A Pandas Dataframe object containing the LiDAR point cloud data.
- TileDivisionint
An integer specifying the number of divisions to divide the tile into. The default value is 1, which means the tile is not divided.
- rowsint
The number of rows in the Matrix_Buffer 2D array.
- colsint
The number of columns in the Matrix_Buffer 2D array.
- Matrix_Buffer2D list
A 2D list of lasTile objects representing the sub-tiles of the tile.
- Matrix_BufferFilledbool
A boolean indicating whether the Matrix_Buffer 2D list has been filled with lasTile objects representing the sub-tiles of the tile. The default value is False.
Class methods:
- Get_TileBounds()
Get bounding values of tiles.
- Returns:
A tuple (X_max, X_min, Y_max, Y_min) containing the maximum and minimum values of X and Y coordinates.
- Get_SubTileDimensions()
Get the dimensions of the subtiles.
- Returns:
A tuple (X_div_len, Y_div_len) containing the length and breadth of subtiles.
- Get_subtile(X_div_len, Y_div_len, row_ID, col_ID)
Get X, Y, Z points of specific lidar tile.
- Get_subtileArray()
Return a 2D matrix buffer of lidar subtiles indexed by row and column.
- Returns:
A 2D numpy array of size Nx3.
Here is an example usage of the lasTile class:
import pandas as pd
from terravide.src.PreProcessing import lasTile
# Load the LiDAR data into a Pandas DataFrame
df = pd.read_csv('lidar_data.csv')
# Create an instance of the lasTile class
tile = lasTile(df, TileDivision=10)
# Get the bounding values of the tiles
X_max, X_min, Y_max, Y_min = tile.Get_TileBounds()
# Get the dimensions of the subtiles
X_div_len, Y_div_len = tile.Get_SubTileDimensions()
# Get a subtile of the LiDAR data
subtile_df = tile.Get_subtile(X_div_len, Y_div_len, row_ID=0, col_ID=0)
# Get a matrix buffer of the LiDAR subtiles
matrix_buffer = tile.Get_subtileArray()