public int laszip_set_geoascii_params(ushort number, byte[] geoascii_params) { if(number==0) { error="number of geoascii_params is zero"; return 1; } if(geoascii_params==null) { error="geoascii_params pointer is zero"; return 1; } if(reader!=null) { error="cannot set geoascii_params after reader was opened"; return 1; } if(writer!=null) { error="cannot set geoascii_params after writer was opened"; return 1; } try { // fill a VLR laszip_vlr vlr=new laszip_vlr(); vlr.reserved=0xAABB; Array.Copy(Encoding.ASCII.GetBytes("LASF_Projection"), vlr.user_id, 16); vlr.record_id=34737; vlr.record_length_after_header=number; byte[] v=Encoding.ASCII.GetBytes(string.Format("LASzip DLL {0}.{1} r{2} ({3})", LASzip.VERSION_MAJOR, LASzip.VERSION_MINOR, LASzip.VERSION_REVISION, LASzip.VERSION_BUILD_DATE)); Array.Copy(v, vlr.description, Math.Min(v.Length, 32)); vlr.data=geoascii_params; // add the VLR if(laszip_add_vlr(vlr)!=0) { error=string.Format("setting {0} geoascii_params", number); return 1; } } catch { error="internal error in laszip_set_geoascii_params"; return 1; } error=null; return 0; }
public int laszip_add_vlr(laszip_vlr vlr) { if(vlr==null) { error="laszip_vlr_struct vlr pointer is zero"; return 1; } if((vlr.record_length_after_header>0)&&(vlr.data==null)) { error=string.Format("VLR has record_length_after_header of {0} but VLR data pointer is zero", vlr.record_length_after_header); return 1; } if(reader!=null) { error="cannot add vlr after reader was opened"; return 1; } if(writer!=null) { error="cannot add vlr after writer was opened"; return 1; } try { if(header.vlrs.Count>0) { // overwrite existing VLR ? for(int i=(int)header.number_of_variable_length_records-1; i>=0; i++) { if(header.vlrs[i].record_id==vlr.record_id&&!ArrayCompare(header.vlrs[i].user_id, vlr.user_id)) { if(header.vlrs[i].record_length_after_header!=0) header.offset_to_point_data-=header.vlrs[i].record_length_after_header; header.vlrs.RemoveAt(i); } } } header.vlrs.Add(vlr); header.number_of_variable_length_records=(uint)header.vlrs.Count; header.offset_to_point_data+=54; // copy the VLR header.offset_to_point_data+=vlr.record_length_after_header; } catch { error="internal error in laszip_add_vlr"; return 1; } error=null; return 0; }
public unsafe int laszip_set_geokeys(ushort number, laszip_geokey[] key_entries) { if(number==0) { error="number of key_entries is zero"; return 1; } if(key_entries==null) { error="key_entries pointer is zero"; return 1; } if(reader!=null) { error="cannot set geokeys after reader was opened"; return 1; } if(writer!=null) { error="cannot set geokeys after writer was opened"; return 1; } try { // create the geokey directory byte[] buffer=new byte[sizeof(laszip_geokey)*(number+1)]; fixed(byte* pBuffer=buffer) { laszip_geokey* key_entries_plus_one=(laszip_geokey*)pBuffer; key_entries_plus_one[0].key_id=1; // aka key_directory_version key_entries_plus_one[0].tiff_tag_location=1; // aka key_revision key_entries_plus_one[0].count=0; // aka minor_revision key_entries_plus_one[0].value_offset=number; // aka number_of_keys for(int i=0; i<number; i++) key_entries_plus_one[i+1]=key_entries[i]; } // fill a VLR laszip_vlr vlr=new laszip_vlr(); vlr.reserved=0xAABB; Array.Copy(Encoding.ASCII.GetBytes("LASF_Projection"), vlr.user_id, 16); vlr.record_id=34735; vlr.record_length_after_header=(ushort)(8+number*8); byte[] v=Encoding.ASCII.GetBytes(string.Format("LASzip DLL {0}.{1} r{2} ({3})", LASzip.VERSION_MAJOR, LASzip.VERSION_MINOR, LASzip.VERSION_REVISION, LASzip.VERSION_BUILD_DATE)); Array.Copy(v, vlr.description, Math.Min(v.Length, 32)); vlr.data=buffer; // add the VLR if(laszip_add_vlr(vlr)!=0) { error=string.Format("setting {0} geokeys", number); return 1; } } catch { error="internal error in laszip_set_geokey_entries"; return 1; } error=null; return 0; }