GXLTB class

class GXLTB(handle=0)

GXLTB class.

An GXLTB 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 GXLTB 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 GXTB class.

Note:

An GXLTB 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(key, rec)

Add a new record.

Parameters:
  • key (str) – Key name
  • rec (int_ref) – Returned record number

New in version 5.0.

License: Geosoft Open License

Note: If the record exists, the existing record is cleared and the record number is returned.

contract(lt_bc)

Contract the contents of two same-key and same-fields tables.

Parameters:lt_bc (GXLTB) – Contract GXLTB
Returns:x - Handle to GXLTB object NULL - Error of some kind
Return type:GXLTB

New in version 5.1.

License: Geosoft Open License

Note: The “Key” of the child must be the same as the “Key” of the Master. The fields of two GXLTB must be the same.

Contracting takes place as follows:

  1. The Master GXLTB is copied to the New GXLTB.
  2. All records in the contract LIB are deleted from the New GXLTB (if there are any)
  3. The New GXLTB is returned.
classmethod create(file, type, delim, key)

Creates a GXLTB object from a file.

Parameters:
  • file (str) – File name, .csv assumed, searched locally then in GEOSOFT.
  • type (int) – LTB_TYPE constants
  • delim (int) – LTB_DELIM constants
  • key (str) – Key to find if only one record required, “” to read entire table.
Returns:

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

Return type:

GXLTB

New in version 5.0.

License: Geosoft Open License

Note: If the file has no header, field names are assumed to be “0”, “1”, etc.

classmethod create_crypt(file, type, delim, case, key, crypt)

Creates a GXLTB object from an encrypted file.

Parameters:
Returns:

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

Return type:

GXLTB

New in version 6.2.

License: Geosoft Open License

Note: If the file has no header, field names are assumed to be “0”, “1”, etc.

classmethod create_ex(file, type, delim, case, key)

Creates a GXLTB object from a file.

Parameters:
Returns:

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

Return type:

GXLTB

New in version 6.1.

License: Geosoft Open License

Note: If the file has no header, field names are assumed to be “0”, “1”, etc.

delete_record(rec)

Delete a record.

Parameters:rec (int) – Record number to delete

New in version 5.0.

License: Geosoft Open License

Note: Record numbers after the deleted record will be reduced by 1.

fields()

Get number of fields.

Returns:Number of fields in the GXLTB.
Return type:int

New in version 5.0.

License: Geosoft Open License

find_field(field)

Return the field number for the specified field.

Parameters:field (str) – Field name
Returns:-1 if field does not exist. field number if field does exist.
Return type:int

New in version 5.0.

License: Geosoft Open License

find_key(key)

Return the key index of a record.

Parameters:key (str) – Key name
Returns:-1 if key does not exist. record number if key does exist.
Return type:int

New in version 5.0.

License: Geosoft Open License

get_con_lst(fld, match, match_type, lst)

Populate a GXLST with GXLTB names from matching fields.

Parameters:
  • fld (int) – Field
  • match (str) – String to match to field, must be lower-case
  • match_type (int) – LTB_CONLST constants
  • lst (GXLST) – List to populate

New in version 5.0.

License: Geosoft Open License

Note: The GXLST object will be in the order of the file. The GXLST names will be the GXLTB key fields and the GXLST values will be the GXLTB record numbers.

get_double(record, field)

Get a real entry from the GXLTB

Parameters:
  • record (int) – Record number
  • field (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.

License: Geosoft Open License

get_english_string(record, field, token)

Get the English entry from the GXLTB

Parameters:
  • record (int) – Record number
  • field (int) – Field number
  • token (str_ref) – Returned field token

New in version 8.2.

License: Geosoft Open License

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

get_field(field_num, field)

Get a field name by index.

Parameters:
  • field_num (int) – Field number
  • field (str_ref) – Returned field name

New in version 5.0.

License: Geosoft Open License

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

get_int(record, field)

Get a int entry from the GXLTB

Parameters:
  • record (int) – Record number
  • field (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.

License: Geosoft Open License

get_lst(fld, lst)

Populate an GXLST with GXLTB names

Parameters:
  • fld (int) – Field to get, 0 for key field
  • lst (GXLST) – List to populate

New in version 5.0.

License: Geosoft Open License

Note: The GXLST object will be in the order of the file. The GXLST names will be the GXLTB fields and the GXLST values will be the GXLTB record numbers.

get_lst2(fld_n, fld_v, lst)

Populate an GXLST with GXLTB names and values

Parameters:
  • fld_n (int) – Field for names, 0 for key field
  • fld_v (int) – Field for values, 0 for key field
  • lst (GXLST) – List to populate

New in version 5.0.

License: Geosoft Open License

Note: The GXLST object will be in the order of the file. The GXLST names will come from the GXLTB name field and the GXLST values will come from value field specified.

get_string(record, field, token)

Get an entry from the GXLTB

Parameters:
  • record (int) – Record number
  • field (int) – Field number
  • token (str_ref) – Returned field token

New in version 5.0.

License: Geosoft Open License

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

is_null()

Check if this is a null (undefined) instance

Returns:True if this is a null (undefined) instance, False otherwise.
Return type:bool
merge(lt_bc)

Merge the contents of two same-key tables.

Parameters:lt_bc (GXLTB) – Child GXLTB
Returns:x - Handle to GXLTB object NULL - Error of some kind
Return type:GXLTB

New in version 5.0.

License: Geosoft Open License

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 GXLTB are collected in-order.
  3. Any new fields of the Child GXLTB are added to the end of the list.
  4. A new GXLTB is created to contain the new field list (in-order).
  5. The Child table contents are added to the New GXLTB.
  6. The Master table contents are added/replace the New GXLTB.
  7. The New GXLTB is returned.

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

  1. The Master GXLTB is copied to the New GXLTB.
  2. Any New records found in the child are added to the New GXLTB
classmethod null()

A null (undefined) instance of GXLTB

Returns:A null GXLTB
Return type:GXLTB
records()

Get number of records in GXLTB.

Returns:Number of records in the GXLTB.
Return type:int

New in version 5.0.

License: Geosoft Open License

save(file)

Save GXLTB changes to existing or new file

Parameters:file (str) – File name, .csv assumed. If “”, save to original file.

New in version 5.0.

License: Geosoft Open License

save_crypt(file, crypt)

Save GXLTB to a new file using encryption

Parameters:
  • file (str) – File name, .csv assumed. If “”, save to original file.
  • crypt (str) – Encryption key SYS_CRYPT_KEY constants

New in version 6.2.

License: Geosoft Open License

search(rec, fld, field)

Search for a record containing field value

Parameters:
  • rec (int) – Search start record
  • fld (int) – Field number
  • field (str) – Search string (case sensitive)
Returns:

-1 if search failed. record number if search succeeds

Return type:

int

New in version 5.0.

License: Geosoft Open License

set_double(record, field, data)

Set a double entry

Parameters:
  • record (int) – Record number
  • field (int) – Field number
  • data (float) – Entry

New in version 5.0.

License: Geosoft Open License

set_int(record, field, data)

Set a long entry

Parameters:
  • record (int) – Record number
  • field (int) – Field number
  • data (int) – Entry

New in version 5.0.

License: Geosoft Open License

set_string(record, field, token)

Set an entry

Parameters:
  • record (int) – Record number
  • field (int) – Field number
  • token (str) – Entry

New in version 5.0.

License: Geosoft Open License

LTB_CASE constants

Case handling of GXLTB strings

LTB_CASE_INSENSITIVE

Ignore case

gxapi.LTB_CASE_INSENSITIVE = 0
LTB_CASE_SENSITIVE

Case is used

gxapi.LTB_CASE_SENSITIVE = 1

LTB_CONLST constants

Matching types

LTB_CONLST_EXACT

Exact

gxapi.LTB_CONLST_EXACT = 0
LTB_CONLST_ANY

Any

gxapi.LTB_CONLST_ANY = 1

LTB_DELIM constants

Types of GXLTB Delimiters

LTB_DELIM_SPACE

Spaces

gxapi.LTB_DELIM_SPACE = 0
LTB_DELIM_COMMA

Commas

gxapi.LTB_DELIM_COMMA = 1
LTB_DELIM_SPACECOMMA

Spaces and Commas

gxapi.LTB_DELIM_SPACECOMMA = 2

LTB_TYPE constants

Types of GXLTB Headers

LTB_TYPE_HEADER

Has a header

gxapi.LTB_TYPE_HEADER = 0
LTB_TYPE_NOHEADER

Has no header

gxapi.LTB_TYPE_NOHEADER = 1