#NEWLINE# def define_new_dimension( self , name , data_type , description = '' ) : #NEWLINE# #INDENT# old_vlrs = self . vlrs #NEWLINE# if ( self . has_point_records or ( not ( self . mode == 'w' ) ) ) : #NEWLINE# #INDENT# raise laspy . util . LaspyException ( 'New dimensions may be defined only for write mode files which do not yet possess point records.' ) #NEWLINE# #UNINDENT# eb_vlrs = [ x for x in self . vlrs if ( x . type == 1 ) ] #NEWLINE# if ( self . header . version == '1.4' ) : #NEWLINE# #INDENT# eb_evlrs = [ x for x in self . evlrs if ( x . type == 1 ) ] #NEWLINE# old_evlrs = self . evlrs #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# eb_evlrs = [ ] #NEWLINE# old_evlrs = [ ] #NEWLINE# #UNINDENT# if ( ( 'extra_bytes' in self . point_format . lookup ) and ( len ( eb_vlrs ) != 0 ) ) : #NEWLINE# #INDENT# raise laspy . util . LaspyException ( 'Adding a dimension is ambiguous when there are already extra bytes in the point records, but no VLR describing them.' ) #NEWLINE# #UNINDENT# new_dimension = laspy . header . ExtraBytesStruct ( name = name , data_type = data_type , description = description ) #NEWLINE# if ( ( len ( eb_vlrs ) + len ( eb_evlrs ) ) > 1 ) : #NEWLINE# #INDENT# raise laspy . util . LaspyException ( 'Only one ExtraBytes VLR currently allowed.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( len ( eb_vlrs ) + len ( eb_evlrs ) ) == 1 ) : #NEWLINE# #INDENT# if ( len ( eb_vlrs ) == 1 ) : #NEWLINE# #INDENT# extra_dimensions = eb_vlrs [ 0 ] . extra_dimensions #NEWLINE# extra_dimensions . append ( new_dimension ) #NEWLINE# self . extra_dimensions = extra_dimensions #NEWLINE# new_pt_fmt = laspy . util . Format ( self . point_format . fmt , extradims = extra_dimensions ) #NEWLINE# self . point_format = new_pt_fmt #NEWLINE# self . set_header_property ( 'data_record_length' , self . point_format . rec_len ) #NEWLINE# eb_vlr_index = [ x for x in range ( len ( self . vlrs ) ) if ( self . vlrs [ x ] . type == 1 ) ] [ 0 ] #NEWLINE# new_vlr = copy . copy ( eb_vlrs [ 0 ] ) #NEWLINE# nvlrbs = new_dimension . to_byte_string ( ) #NEWLINE# new_vlr . VLR_body += nvlrbs #NEWLINE# new_vlr . rec_len_after_header += len ( nvlrbs ) #NEWLINE# old_vlrs [ eb_vlr_index ] = new_vlr #NEWLINE# self . set_vlrs ( old_vlrs ) #NEWLINE# self . populate_vlrs ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( eb_evlrs ) == 1 ) : #NEWLINE# #INDENT# extra_dimensions = eb_evlrs [ 0 ] . extra_dimensions #NEWLINE# extra_dimensions . append ( new_dimension ) #NEWLINE# self . extra_dimensions = extra_dimensions #NEWLINE# new_pt_fmt = laspy . util . Format ( self . point_format . fmt , extradims = extra_dimensions ) #NEWLINE# self . point_format = new_pt_fmt #NEWLINE# self . set_header_property ( 'data_record_length' , self . point_format . rec_len ) #NEWLINE# eb_evlr_index = [ x for x in range ( len ( self . evlrs ) ) if ( self . evlrs [ x ] . type == 1 ) ] [ 0 ] #NEWLINE# new_vlr = copy . copy ( eb_evlrs [ 0 ] ) #NEWLINE# nvlrbs = new_dimension . to_byte_string ( ) #NEWLINE# new_vlr . VLR_body += nvlrbs #NEWLINE# new_vlr . rec_len_after_header += len ( nvlrbs ) #NEWLINE# old_vlrs [ eb_evlr_index ] = eb_evlrs #NEWLINE# self . set_evlrs ( old_evlrs ) #NEWLINE# self . populate_evlrs ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# new_vlr = laspy . header . VLR ( user_id = 'LASF_Spec' , record_id = 4 , VLR_body = new_dimension . to_byte_string ( ) ) #NEWLINE# old_vlrs . append ( new_vlr ) #NEWLINE# self . extra_dimensions = [ new_dimension ] #NEWLINE# new_pt_fmt = laspy . util . Format ( self . point_format . fmt , extradims = self . extra_dimensions ) #NEWLINE# self . point_format = new_pt_fmt #NEWLINE# self . set_header_property ( 'data_record_length' , self . point_format . rec_len ) #NEWLINE# self . set_vlrs ( old_vlrs ) #NEWLINE# self . populate_vlrs ( )