maptek.vulcan.tri_attributes

The following functions can be used to edit or set Vulcan triangulation attributes.

To download all the example scripts, click here.


clear(tri_attributes self)

Clear all attributes from a triangulation.

# Filename: tri_att_clear.py
# Purpose: Clear attributes from triangulation
# Returns: Null

from maptek import vulcan

input_tri = 'pit_solid.00t'  # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    attr_dict = tri.get_hash()  # create dictionary of attributes with values
    print(f"Before: {attr_dict}")

    tri.clear()  # true if the attribute exists, false if the attribute does not exist

    attr_dict = tri.get_hash()  # create dictionary of attributes with values
    print(f"After: {attr_dict}")
delete_key(tri_attributes self, std::string const & name)

Delete a key (attribute) from a triangulation.

# Filename: tri_att_delete_key.py
# Purpose: Delete attribute key
# Returns: Null

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

key = "flagged"  # key to delete

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    if not tri.exists(key): # check if key exists
        key_list = tri.get_keys() # get list of keys
        print(f"The key '{key}' does not exist")
        print(f"List of keys: {key_list}")
    else:
        tri.delete_key(key)  # deletes the key if it exists
        key_list = tri.get_keys() # get list of keys
        print(f"The key '{key}' has been deleted")
        print(f"List of keys: {key_list}")
    
exists(tri_attributes self, std::string const & name) → bool

Check if an attribute exists. Return True if exists, False is it does not exist.

# Filename: tri_att_exists.py
# Purpose: Check if an attribute exists
# Returns: Bool

from maptek import vulcan

input_tri = 'pit_solid.00t'  # triangulation to use

attribute = 'grade'  # attribute we want to check

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    exists = tri.exists(attribute)  # true if the attribute exists, false if the attribute does not exist
    print(f"{exists}")
get_hash(tri_attributes self) → dictionary

Create a dictionary of attributes and values {'attribute' : 'value'}.

# Filename: tri_att_get_hash.py
# Purpose: Create a dictionary of attributes and values {'attribute' : 'value'}
# Returns: dictionary

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    attr_dict = tri.get_hash()  # create dictionary of attributes with values
    print(f"{attr_dict}")
get_keys(tri_attributes self) → string_list

Create a list of keys from the dictionary of attributes for a triangulation. The key is the attribute name.

['Date Modified', 'Volume']

# Filename: tri_att_get_keys.py
# Purpose: Get list of keys from the attributes of a triangulation
# Returns: string list

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    keys = tri.get_keys()  # create list of keys
    print(f"{keys}")
get_last_error(tri_attributes self) → std::string

Get the last error thrown by an attribute method.

# Filename: tri_att_get_last_error.py
# Purpose: Get the last error thrown by an attribute method
# Returns: string

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    tri.is_ok()  # Check triangulation is open and ready to add attributes

    # Add attribute
    tri.put('flagged', '2', 'Boolean')

    # get last error, blank if no error. In this case, the second argument passed
    # to the method above is invalid. Boolean operations only accept 0 or 1, not a 2.
    last_error = tri.get_last_error()
    print(f"Error: {last_error}")

    tri.save()  # save the attribute data
get_string(tri_attributes self, std::string const & name) → std::string

Return attribute values as a list of strings..

# Filename: tri_att_get_string.py
# Purpose: Get value from all string type attributes from input list
# Returns: string

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

input_attributes = ['oxd','bench','flagged']

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    for string in input_attributes:
        val = tri.get_string(string)  # return the attribute value as a string
        print(f"{val}")
get_type(tri_attributes self, std::string const & name) → std::string

Returns the attribute type as a string.

# Filename: tri_att_get_type.py
# Purpose: Get attribute type
# Returns: string

from maptek import vulcan

input_tri = "pit_solid.00t" # triangulation to use

input_attributes = ['oxd', 'bench', 'flagged'] # attribute to pass

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    for key in input_attributes:
        type = tri.get_type(key)  # get attribute type
        print(f"{type}")
get_types(tri_attributes self) → string_list

Returns a list of attribute types.

# Filename: tri_att_get_types.py
# Purpose: Get list of attribute types
# Returns: string list

from maptek import vulcan

input_tri = "pit_solid.00t" # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    types = tri.get_types()
    print(f"{types}")
get_values(tri_attributes self) → string_list

Create a list of attribute values for a triangulation.

['2023/1/24', '24160303.885194']

# Filename: tri_att_get_values.py
# Purpose: Get list of attribute values
# Returns: string list

from maptek import vulcan

input_tri = "pit_solid.00t" # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation in read mode
    values = tri.get_values()  # get the attribute values
    print(f"{values}")
is_ok(tri_attributes self) → bool

Verify if triangulation is open and can be read by Python.

# Filename: tri_att_is_ok.py
# Purpose: Check if the attributes are open and returns True of False.
# Returns: Bool

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use

with vulcan.tri_attributes(input_tri) as tri:  # open triangulation attributes in write mode
    is_ok = tri.is_ok()
    print(f"{is_ok}")

put(tri_attributes self, std::string const & name, int value, std::string const & type) → bool
put(tri_attributes self, std::string const & name, std::string const & value, std::string const & type) → bool

Add attributes to a triangulation and return True if successful. There are two versions of this function and both use the same format for passing arguments: put(attribute name, attribute value, attribute type).

Note:  Also see is_ok() above for example script showing how to add multiple attributes using a list.

# Filename: tri_att_put.py
# Purpose: Add attributes to triangulation.
# Returns: Bool

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use
input_attributes = [['oxd','waste','String'],
                    ['bench',23,'Integer'],
                    ['flagged',1,'Boolean']]

with vulcan.tri_attributes(input_tri) as tri:
    assert tri.is_ok(), 'Error: Triangulation not open.  No attributes added.'
    for attribute in input_attributes:
        attr = tri.put(*attribute)
        if attr:
            print(f"{attribute} successfully added.")
        else:
            print(f"{attribute} was not added.")
save(tri_attributes self)

Save changes to triangulation attributes.

Note:  This function must be used if the triangulation is not opened using a with statement.

# Filename: tri_att_save.py
# Purpose: Add attributes to triangulation.
# Returns: Null

from maptek import vulcan

input_tri = "pit_solid.00t"  # triangulation to use
input_attributes = [['grade','10.33','Double'],
                    ['oxd','waste','String'],
                    ['int',23,'Integer'],
                    ['flagged',1,'Boolean']]

tri = vulcan.tri_attributes(input_tri)

assert tri.is_ok(), 'Error: Triangulation not open.  No attributes added.'
for attribute in input_attributes:
    attr = tri.put(*attribute)
    if attr:
        print(f"{attribute} successfully added.")
    else:
        print(f"{attribute} was not added.")