maptek.vulcan.layer

The following functions can be used to edit Vulcan layers and manipulate properties.

To download all the example scripts, click here.


Here is a basic framework for creating a layer. Use this template to create layers with a Python script. In this example, a design database is opened in write mode, a simple point is created, then the layer is saved.

# Framework for creating a layer

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access

with vulcan.dgd(dgd_file, "w") as dgd:                  # 1. open the database in write mode
    layer = vulcan.layer('POINT')                       # 2. make a new layer
    new_pt = vulcan.polyline([[76500.0, 4500.0, 0.0]])  # 3. create an object
    layer.append(new_pt)                                # 4. put new object into the layer
    dgd.save_layer(layer)                               # 5. save layer
append(layer self, obj object)

Appends an object to the layer.

# Create a 10 x 10 grid of points

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database we want to access
layer_name = 'POINT_GRID'
origin_x = 75000.0
origin_y = 4700.0
origin_z = 0.0
index = 0

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in read mode
    layer = vulcan.layer(layer_name)  # Make a new layer

    for i in range(10):
        origin_y = 4700.0 # reset y coordinate after each column is created
        for j in range(10):
            new_pt = vulcan.polyline([[origin_x, origin_y, origin_z]])  # create object with one point
            new_pt[0].name = 'pt_' + str(i) + str(j)  # create point name based on grid index
            new_pt.colour = index + 1

            layer.append(new_pt)  # put newly edited object into the layer

            layer.set_object(index, new_pt)  # make each point a unique object

            index += 1
            origin_y += 100
        origin_x += 100

    dgd.save_layer(layer)  # save layer
clear_objects(layer self)

Deletes all objects from the layer.

# Delete all objects from a layer.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database we want to access
layer_name = "POINT"  # layer we want to use

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in write mode
    layer = dgd.get_layer(layer_name)  # get layer

    layer.clear_object()  # remove the object

    dgd.save_layer(layer)  # save the layer

delete_object(layer self, int index) → bool

Deletes an object by index from the layer.

# Delete an object from a layer given its index

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database we want to access
layer_name = "POINT"  # layer we want to use

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in write mode
    layer = dgd.get_layer(layer_name)  # get layer
    index = layer.num_objects()  # get the highest indexed object
    assert index > 0, f"Error: no objects in the layer."

    layer.delete_object(index-1)  # remove the object

    dgd.save_layer(layer)  # save the layer

find_object(layer self, std::string name) → VulcanObj

Finds an object by name.

# Find an object from a layer by name.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access
layer_name = 'POINT'  # layer to use

with vulcan.dgd(dgd_file, "r") as dgd:  # open up the database in read mode
    layer = dgd.get_layer(layer_name) # access layer

    obj = layer.find_object('POLYLINE')  # find the object
    print(f"{obj}")

get_name(layer self) → std::string

Gets the layer name.

# Filename: layer_get_name.py
# Purpose: Get the name of a layer.
# Returns: Name of layer as string.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access

with vulcan.dgd(dgd_file, "r") as dgd: # open up the database in read mode
    layer_list = dgd.list_layers() # list layers in database
    list_item = dgd.get_layer(layer_list[0])  # get layer object from database
    layer_name = list_item.get_name() # get the name of the layer
    
    # do something with layer name...
    print(f"layer name: {layer_name}")

Note:   Calling the properties instead of using the get_name() function can be an alternative method for achieving the same thing. See the script example below.

# Filename: layer_name_property.py
# Purpose: Get the name of a layer by calling properties.
# Returns: Name of layer as string.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access

with vulcan.dgd(dgd_file, "r") as dgd: # open up the database in read mode
    layer_list = dgd.list_layers() # list layers in database
    list_item = dgd.get_layer(layer_list[0]) # get layer object from database
    layer_name = list_item.name

    # do something with layer name...
    print(f"layer name: {layer_name}")
get_description(layer self) → std::string

Gets the layer description.

# Get the name of a layer

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access

with vulcan.dgd(dgd_file, "r") as dgd:  # open up the database in read mode
    layer_list = dgd.list_layers()  # get the list of layers
    for i, layer in enumerate(layer_list): # loop through layer_list with i as index
        new_layer = dgd.get_layer(layer_list[i])  # get a layer from the layer list
        layer_name = new_layer.get_name()  # get the name of the layer
        layer_description = new_layer.get_description()  # get the description of the layer
        print(f"layer name: {layer_name}\n   description: {layer_description}")

Note:   Calling the properties instead of using the get_description() function can be an alternative method for achieving the same thing. See the script example below.

# Filename: layer_description_property.py
# Purpose: Get the description of a layer by calling properties.
# Returns: Description of layer as string.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access

with vulcan.dgd(dgd_file, "r") as dgd: # open up the database in read mode
    layer_list = dgd.list_layers() # list layers in database
    list_item = dgd.get_layer(layer_list[0]) # get layer object from database
    layer_descr = list_item.description # get the layer description

    # do something with description string...
    print(f"layer description: {layer_descr}")
get_object(layer self, int index) → VulcanObj

Gets an object from a layer by index.

# Find an object from a layer by name.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access
layer_name = 'POINT'  # layer to use

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in write mode
    layer = dgd.get_layer(layer_name)  # access layer

    # find the object by index
    obj = layer.get_object(0)

    # do something with the object
    obj.colour = 5

    # put object back into layer and save
    layer.append(obj)
    dgd.save_layer(layer)
get_objects(types: list)

Gets the objects of a layer by type. This is not suitable for putting objects back into layers with enumerate() since the objects are filtered and indices are unknown. To have indices for modifying objects, use get_objects_enumerate().

# Get the objects of a specified type from layer.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access
layer_name = 'POINT'  # layer to use

with vulcan.dgd(dgd_file, "r") as dgd:  # open up the database in read mode
    layer = dgd.get_layer(layer_name) # access layer
    types = [vulcan.polyline]

    for obj in layer.get_objects(types):
        print(type(obj))
get_objects_enumerate(types: list)

Gets objects by type from a layer along with layer indices.

List of object types
polyline arrow dim_arc
text dim_radius dim_line
text3d dim_angle  

Note:  Both get_objects() and get_objects_enumerate() (shown immediately below) are helpful when you want to isolate all the objects of certain types and do something with them, eliminating the need to write out functions for each type separately.

# Get the objects of a specified type from layer and layer indices.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access
layer_name = 'POINTS'  # layer to use

with vulcan.dgd(dgd_file, "r") as dgd:  # open up the database in read mode
    layer = dgd.get_layer(layer_name) # access layer
    types = [vulcan.polyline]

    for i, obj in layer.get_objects_enumerate(types):
        print(i, type(obj))
num_objects(layer self) → int

Returns the number of objects in the layer.

# Get the number of objects in a layer.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database we want to access
layer_name = "POINT"  # layer we want to use

with vulcan.dgd(dgd_file, "r") as dgd:  # open up the database in read mode
    layer = dgd.get_layer(layer_name)  # get layer

    n_obj = layer.num_objects()  # get the number of objects
    
    if n_obj == 1:
        print(f"The {layer_name} layer has {n_obj} object")
    if n_obj > 1:
        print(f"The {layer_name} layer has {n_obj} objects")

set_name(layer self, std::string const & name)

Sets the layer name.

# Filename: layer_set_name.py
# Purpose: Sets the name of a layer.
# Returns: None.  Layer name is set.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access
layer_name = "NEW_POINT" # current name of layer
new_layer_name = "COLLAR_LOC" # new layer name

with vulcan.dgd(dgd_file, "w") as dgd: # open up the database in write mode
    assert dgd.is_layer(layer_name), 'Error: Layer does not exist.'
    layer = dgd.get_layer(layer_name)
    current_layer_name = layer.get_name() # get the old name of the layer
    layer.set_name(new_layer_name) # set the new name of the layer
    dgd.delete_layer(layer_name) # removes reference to old layer from dgd
    dgd.save_layer(layer) # save the layer

Note:   Calling the properties instead of using the set_name() function can be an alternative method for achieving the same thing. See the script example below.

(missing or bad snippet)
set_description(layer self, std::string const & description)

Sets the layer description.

# Filename: layer_set_description.py
# Purpose: Sets the description of a layer.
# Returns: None.  Layer description is set.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access
layer_name = "NEW_POINT" # name of layer
new_layer_desc = "Collar: DH1203" # new layer description

with vulcan.dgd(dgd_file, "w") as dgd: # open up the database in write mode
    assert dgd.is_layer(layer_name), 'Error: Layer does not exist.'
    layer = dgd.get_layer(layer_name) # get layer
    layer.set_description(new_layer_desc) # sets layer description
    dgd.save_layer(layer) # save the layer

Note:   Calling the properties instead of using the set_description() function can be an alternative method for achieving the same thing. See the script example below.

# Filename: layer_set_description_using_properties.py
# Purpose: Sets the description of a layer using properties.
# Returns: None.  Layer description is set.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis" # design database to access
layer_name = "NEW_POINT" # name of layer
new_layer_desc = "Collar: DH1203" # new layer description

with vulcan.dgd(dgd_file, "w") as dgd: # open up the database in write mode
    assert dgd.is_layer(layer_name), 'Error: Layer does not exist.'
    layer = dgd.get_layer(layer_name) # get layer
    layer.set_description = new_layer_desc # sets layer description using property
    dgd.save_layer(layer) # save the layer
set_object(layer self, int index, obj object) → bool

Sets an object by index.

# Add a point to a layer

from maptek import vulcan

dgd_file = 'pydemo.dgd.isis'  # design database to access
layer_name = 'POINT'  # layer to use

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in write mode
    layer = dgd.get_layer(layer_name) # access layer
    new_pt = vulcan.polyline([[76600.0, 4500.0, 0.0]])  # create an object
    layer.append(new_pt)  # put new object into the layer

    layer.set_object(1, new_pt)  # assign object to index 0
    
    dgd.save_layer(layer)  # save layer