maptek.vulcan.tri_attributes

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

To download all the example scripts on this page, click Python Tri_Attributes Example Scripts.


clear(tri_attributes self)

Clear all attributes from a triangulation.

# Clear attributes from triangulation

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.

# Delete attribute key

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.

# Check if an attribute exists

from maptek import vulcan

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

attribute = 'grade'  # attribute 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'}.

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

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.

Example:  ['Date Modified', 'Volume']

# Get list of keys from the attributes of a triangulation

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.

# Get the last error thrown by an attribute method

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..

# Return attribute values as a list of strings

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.

# Get attribute type

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.

# Get list of attribute types

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.

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

# Get list of attribute values

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.

# Add attributes to triangulation.

from maptek import vulcan

input_tri = "stockpile.00t"  # triangulation to use
input_attributes = [['grade','10.33','Double'],
                    ['oxd','waste','String'],
                    ['int','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.")
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.

# Add attributes to triangulation.

from maptek import vulcan

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

with vulcan.tri_attributes(input_tri) as tri:
    if tri.is_ok(): # Check if triangulation is open
        # Add attributes
        test = tri.put('oxd','waste','String')
        if test:
            print('Attribute successfully added.')
        else:
            print('Attribute was not added.')

    else:
        print('Error: Triangulation not open.  No attributes 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.

# Add attributes to triangulation.

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.")