Skip to content
Snippets Groups Projects
Commit d722ffcc authored by Maciej Wielgosz's avatar Maciej Wielgosz
Browse files

implemented low vegatation removal in folders

parent df38aa13
No related branches found
No related tags found
No related merge requests found
import argparse
import os
from glob import glob
from tqdm import tqdm
from joblib import Parallel, delayed
from nibio_preprocessing.distance_filtering_dem_based import DistanceFilteringDemBased # Import your existing class
def process_file(las_file, DISTANCE, OUTPUT_FOLDER, VERBOSE):
if VERBOSE:
print(f"Processing {las_file}...")
# Determine the output file path
filename = os.path.basename(las_file)
filename = filename.replace('.las', '_filtered.las')
output_las_file = os.path.join(OUTPUT_FOLDER, filename)
# Run the distance filtering
distance_filtering = DistanceFilteringDemBased(
distance=DISTANCE,
input_las_file_path=las_file,
output_las_file_path=output_las_file,
verbose=VERBOSE
)
distance_filtering.run()
if VERBOSE:
print(f"Filtered {las_file} and saved to {output_las_file}")
if __name__ == '__main__':
# Command-line argument parser
parser = argparse.ArgumentParser(description='Batch processing of distance filtering based on DEM')
parser.add_argument('-d', '--distance', help='Distance in meters e.g. 0.5', default=0.5, required=False, type=float)
parser.add_argument('-i', '--input_folder', help='Input folder containing LAS files', required=True)
parser.add_argument('-o', '--output_folder', help='Output folder to save filtered LAS files', required=True)
parser.add_argument('-v', '--verbose', action='store_true', help="Print information about the process")
args = vars(parser.parse_args())
DISTANCE = args['distance']
INPUT_FOLDER = args['input_folder']
OUTPUT_FOLDER = args['output_folder']
VERBOSE = args['verbose']
# Make sure output folder exists
if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER)
# List all LAS files in the input folder
las_files = glob(os.path.join(INPUT_FOLDER, '*.las'))
# Run parallel processing using joblib
Parallel(n_jobs=-1)(delayed(process_file)(las_file, DISTANCE, OUTPUT_FOLDER, VERBOSE) for las_file in tqdm(las_files))
if VERBOSE:
print("Batch processing complete.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment