GXLTB class

class geosoft.gx.GXLTB
An LTB object is typically created from a CSV (comma-separated values)
file, and is a table of information that may be accessed by row
or column. The LTB class is recommended for use with small tables
produced from short lists (of the order of 1000's or records) such
as the different geographic projections and their defining parameters.
Large tables, such as those required for table-lookup functions, should
be accessed using the TB class.

Note:

An LTB ASCII table file has the following structure:

      / comments
      key_name,col_1,col_2,col_3,etc...    /field names
      key_1,token,token,token,etc...       /data lines
      key_2,token,token,token,etc...
      etc...

The first column must be the key column (all entries unique).

The header line is optional and can be used to find entries.

Comment and empty lines are ignored.
add_record((str)arg1, (int_ref)arg2) → None:
Add a new record.
Parameters:
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

If the record exists, the existing record is cleared
and the record number is returned.
contract((GXLTB)arg1) → GXLTB:
Contract the contents of two same-key and same-fields tables.
Parameters:arg1 (geosoft.gx.GXLTB) – Contract LTB
Returns:x - Handle to LTB object NULL - Error of some kind
Return type:geosoft.gx.GXLTB

New in version 5.1.0.

Note:

The "Key" of the child must be the same as the "Key" of the Master.
The fields of two LTB must be the same.

Contracting takes place as follows:

     1. The Master LTB is copied to the New LTB.
     2. All records in the contract LIB are deleted from the New LTB (if there are any)
     3. The New LTB is returned.
static create((GXContext)ctx, (str)arg1, (int)arg2, (int)arg3, (str)arg4) → GXLTB:
Creates a LTB object from a file.
Parameters:
  • ctx (geosoft.gx.GXContext) – The GX execution context
  • arg1 (str) – file name, .csv assumed, searched locally then in GEOSOFT.
  • arg2 (int) – LTB_TYPE constants
  • arg3 (int) – LTB_DELIM constants
  • arg4 (str) – Key to find if only one record required, “” to read entire table.
Returns:

x - Handle to LTB object NULL - Error of some kind

Return type:

geosoft.gx.GXLTB

New in version 5.0.0.

Note:

If the file has no header, field names are assumed to be "0", "1", etc.
static create_crypt((GXContext)ctx, (str)arg1, (int)arg2, (int)arg3, (int)arg4, (str)arg5, (str)arg6) → GXLTB:
Creates a LTB object from an encrypted file.
Parameters:
Returns:

x - Handle to LTB object NULL - Error of some kind

Return type:

geosoft.gx.GXLTB

New in version 6.2.0.

Note:

If the file has no header, field names are assumed to be "0", "1", etc.
static create_ex((GXContext)ctx, (str)arg1, (int)arg2, (int)arg3, (int)arg4, (str)arg5) → GXLTB:
Creates a LTB object from a file.
Parameters:
Returns:

x - Handle to LTB object NULL - Error of some kind

Return type:

geosoft.gx.GXLTB

New in version 6.1.0.

Note:

If the file has no header, field names are assumed to be "0", "1", etc.
delete_record((int)arg1) → None:
Delete a record.
Parameters:arg1 (int) – record number to delete
Returns:Nothing
Return type:None

New in version 5.0.0.

Note:

Record numbers after the deleted record will be reduced
by 1.
fields() → int:
Get number of fields.
Returns:number of fields in the LTB.
Return type:int

New in version 5.0.0.

find_field((str)arg1) → int:
Return the field number for the specified field.
Parameters:arg1 (str) – field name
Returns:-1 if field does not exist. field number if field does exist.
Return type:int

New in version 5.0.0.

find_key((str)arg1) → int:
Return the key index of a record.
Parameters:arg1 (str) – key name
Returns:-1 if key does not exist. record number if key does exist.
Return type:int

New in version 5.0.0.

get_con_lst((int)arg1, (str)arg2, (int)arg3, (GXLST)arg4) → None:
Populate a LST with LTB names from matching fields.
Parameters:
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

The LST object will be in the order of the file.
The LST names will be the LTB key fields and the
LST values will be the LTB record numbers.
get_double((int)arg1, (int)arg2) → float:
Get a real entry from the LTB
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
Returns:

If the record or field are out of range, an empty string or dummy value is returned.

Return type:

float

New in version 5.0.0.

get_english_string((int)arg1, (int)arg2, (str_ref)arg3) → None:
Get the English entry from the LTB
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
  • arg3 (geosoft.gx.str_ref) – returned field token
Returns:

Nothing

Return type:

None

New in version 8.2.0.

Note:

If the record or field are out of range,
an empty string or dummy value is returned.
get_field((int)arg1, (str_ref)arg2) → None:
Get a field name by index.
Parameters:
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

If the record or field are out of range, an empty string is returned.
get_int((int)arg1, (int)arg2) → int:
Get a int entry from the LTB
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
Returns:

If the record or field are out of range, an empty string or dummy value is returned.

Return type:

int

New in version 5.0.0.

get_lst((int)arg1, (GXLST)arg2) → None:
Populate an LST with LTB names
Parameters:
  • arg1 (int) – field to get, 0 for key field
  • arg2 (geosoft.gx.GXLST) – list to populate
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

The LST object will be in the order of the file.
The LST names will be the LTB fields and the
LST values will be the LTB record numbers.
get_lst2((int)arg1, (int)arg2, (GXLST)arg3) → None:
Populate an LST with LTB names and values
Parameters:
  • arg1 (int) – field for names, 0 for key field
  • arg2 (int) – field for values, 0 for key field
  • arg3 (geosoft.gx.GXLST) – list to populate
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

The LST object will be in the order of the file.
The LST names will come from the LTB name field and the
LST values will come from value field specified.
get_string((int)arg1, (int)arg2, (str_ref)arg3) → None:
Get an entry from the LTB
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
  • arg3 (geosoft.gx.str_ref) – returned field token
Returns:

Nothing

Return type:

None

New in version 5.0.0.

Note:

If the record or field are out of range,
an empty string or dummy value is returned.
is_null() → bool

Check if the instance of geosoft.gx.GXLTB is null (undefined)

Returns:True if this is a null instance of geosoft.gx.GXLTB, False otherwise.
Return type:bool`
merge((GXLTB)arg1) → GXLTB:
Merge the contents of two same-key tables.
Parameters:arg1 (geosoft.gx.GXLTB) – Child LTB
Returns:x - Handle to LTB object NULL - Error of some kind
Return type:geosoft.gx.GXLTB

New in version 5.0.0.

Note:

Merging takes place as follows:

1. The "Key" of the child must be the same as the "Key" of the Master.
2. The fields of the Master LTB are collected in-order.
3. Any new fields of the Child LTB are added to the end of the list.
4. A new LTB is created to contain the new field list (in-order).
5. The Child table contents are added to the New LTB.
6. The Master table contents are added/replace the New LTB.
7. The New LTB is returned.

If the fields of the Master and Child are the same, steps 4, 5, 6 are
replaced by:

4. The Master LTB is copied to the New LTB.
5. Any New records found in the child are added to the New LTB
static null() → GXLTB

A null (undefined) instance of geosoft.gx.GXLTB

Returns:A null geosoft.gx.GXLTB
Return type:geosoft.gx.GXLTB
records() → int:
Get number of records in LTB.
Returns:number of records in the LTB.
Return type:int

New in version 5.0.0.

save((str)arg1) → None:
Save LTB changes to existing or new file
Parameters:arg1 (str) – file name, .csv assumed. If “”, save to original file.
Returns:Nothing
Return type:None

New in version 5.0.0.

save_crypt((str)arg1, (str)arg2) → None:
Save LTB to a new file using encryption
Parameters:
  • arg1 (str) – file name, .csv assumed. If “”, save to original file.
  • arg2 (str) – encryption key SYS_CRYPT_KEY constants
Returns:

Nothing

Return type:

None

New in version 6.2.0.

search((int)arg1, (int)arg2, (str)arg3) → int:
Search for a record containing field value
Parameters:
  • arg1 (int) – search start record
  • arg2 (int) – field number
  • arg3 (str) – search string (case sensitive)
Returns:

-1 if search failed. record number if search succeeds

Return type:

int

New in version 5.0.0.

set_double((int)arg1, (int)arg2, (float)arg3) → None:
Set a double entry
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
  • arg3 (float) – entry
Returns:

Nothing

Return type:

None

New in version 5.0.0.

set_int((int)arg1, (int)arg2, (int)arg3) → None:
Set a long entry
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
  • arg3 (int) – entry
Returns:

Nothing

Return type:

None

New in version 5.0.0.

set_string((int)arg1, (int)arg2, (str)arg3) → None:
Set an entry
Parameters:
  • arg1 (int) – record number
  • arg2 (int) – field number
  • arg3 (str) – entry
Returns:

Nothing

Return type:

None

New in version 5.0.0.

LTB_CASE constants

Case handling of LTB strings
gx.LTB_CASE_INSENSITIVE = 0
Ignore case
gx.LTB_CASE_SENSITIVE = 1
Case is used

LTB_CONLST constants

Matching types
gx.LTB_CONLST_EXACT = 0
gx.LTB_CONLST_ANY = 1

LTB_DELIM constants

Types of LTB Delimiters
gx.LTB_DELIM_SPACE = 0
Spaces
gx.LTB_DELIM_COMMA = 1
Commas
gx.LTB_DELIM_SPACECOMMA = 2
Spaces and Commas

LTB_TYPE constants

Types of LTB Headers
gx.LTB_TYPE_HEADER = 0
Has a header
gx.LTB_TYPE_NOHEADER = 1
Has no header