88import pandas as pd
99from laspy import LasReader , ScaleAwarePointRecord
1010from omegaconf import DictConfig
11+ from pdaltools .las_info import get_tile_origin_using_header_info
1112
1213import patchwork .constants as c
1314from patchwork .indices_map import create_indices_map
@@ -125,20 +126,20 @@ def get_field_from_header(las_file: LasReader) -> List[str]:
125126 return [dimension .name .lower () for dimension in header .point_format .dimensions ]
126127
127128
128- def test_field_exists (file_path : str , colmun : str ) -> bool :
129+ def test_field_exists (file_path : str , column : str ) -> bool :
129130 output_file = laspy .read (file_path )
130- return colmun in get_field_from_header (output_file )
131+ return column in get_field_from_header (output_file )
131132
132133
133134def append_points (config : DictConfig , extra_points : pd .DataFrame ):
134135 # get field to copy :
135136 recipient_filepath = os .path .join (config .filepath .RECIPIENT_DIRECTORY , config .filepath .RECIPIENT_NAME )
136- ouput_filepath = os .path .join (config .filepath .OUTPUT_DIR , config .filepath .OUTPUT_NAME )
137+ output_filepath = os .path .join (config .filepath .OUTPUT_DIR , config .filepath .OUTPUT_NAME )
137138 with laspy .open (recipient_filepath ) as recipient_file :
138139 recipient_fields_list = get_field_from_header (recipient_file )
139140
140141 # get fields that are in the donor file we can transmit to the recipient without problem
141- # classification is in the fields to exclude because it will be copy in a special way
142+ # classification is in the fields to exclude because it will be copied in a special way
142143 fields_to_exclude = [
143144 c .PATCH_X_STR ,
144145 c .PATCH_Y_STR ,
@@ -152,7 +153,7 @@ def append_points(config: DictConfig, extra_points: pd.DataFrame):
152153 if (field .lower () in extra_points .columns ) and (field .lower () not in fields_to_exclude )
153154 ]
154155
155- copy2 (recipient_filepath , ouput_filepath )
156+ copy2 (recipient_filepath , output_filepath )
156157
157158 if len (extra_points ) == 0 : # if no point to add, the job is done after copying the recipient file
158159 return
@@ -165,11 +166,11 @@ def append_points(config: DictConfig, extra_points: pd.DataFrame):
165166 column name in { recipient_filepath } "
166167 )
167168 new_column_type = get_type (config .NEW_COLUMN_SIZE )
168- output_las = laspy .read (ouput_filepath )
169+ output_las = laspy .read (output_filepath )
169170 output_las .add_extra_dim (laspy .ExtraBytesParams (name = config .NEW_COLUMN , type = new_column_type ))
170- output_las .write (ouput_filepath )
171+ output_las .write (output_filepath )
171172
172- with laspy .open (ouput_filepath , mode = "a" ) as output_las :
173+ with laspy .open (output_filepath , mode = "a" ) as output_las :
173174 # put in a new table all extra points and their values on the fields we want to keep
174175 new_points = laspy .ScaleAwarePointRecord .zeros (extra_points .shape [0 ], header = output_las .header )
175176 for field in fields_to_keep :
@@ -227,12 +228,15 @@ def get_donor_path(config: DictConfig) -> Tuple[str, str]:
227228
228229def patchwork (config : DictConfig ):
229230 _ , donor_name = get_donor_path (config )
230- if not donor_name : # if no matching donor, we simply copy the recipient to the output without doing anything
231- recipient_filepath = os .path .join (config .filepath .RECIPIENT_DIRECTORY , config .filepath .RECIPIENT_NAME )
232- ouput_filepath = os .path .join (config .filepath .OUTPUT_DIR , config .filepath .OUTPUT_NAME )
233- copy2 (recipient_filepath , ouput_filepath )
234- return
231+ recipient_filepath = os .path .join (config .filepath .RECIPIENT_DIRECTORY , config .filepath .RECIPIENT_NAME )
232+ if donor_name :
233+ complementary_bd_points = get_complementary_points (config )
234+ append_points (config , complementary_bd_points )
235+
236+ else : # if no matching donor, we simply copy the recipient to the output without doing anything
237+ output_filepath = os .path .join (config .filepath .OUTPUT_DIR , config .filepath .OUTPUT_NAME )
238+ copy2 (recipient_filepath , output_filepath )
239+ complementary_bd_points = pd .DataFrame () # No points to add
235240
236- complementary_bd_points = get_complementary_points (config )
237- append_points (config , complementary_bd_points )
238- create_indices_map (config , complementary_bd_points )
241+ corner_x , corner_y = get_tile_origin_using_header_info (filename = recipient_filepath , tile_width = config .TILE_SIZE )
242+ create_indices_map (config , complementary_bd_points , corner_x , corner_y )
0 commit comments