SIM Model¶
- class sim_model.sim.DATA_TYPE¶
A class that defines a set of constants for possible data types for attributes. These types are used when adding an attrbute to the model.
- class sim_model.sim.ENT_TYPE¶
A class that defines a set of constants for different entity types. These types are used when adding an attrbute to the model.
- class sim_model.sim.SIM¶
A class for creating Spatial Information Models (SIM models).
The model can contain three types of objects: points, polyline, and polygons.
Objects are creating by specifing positions, which have XYZ coordinates.
Objects can be groouped into collections. Collections can contain heterogeneous sets of points, polylines, polygons and other collections.
Objects have sub-entities that define their topology. The three types of sub-entities are vertices, edges, and wires. Attributes can also be attached to these sub-emtities.
Point objects contain just one vertex.
Polyline objects contain vertices, edges, and one wire.
Polygon objects cotain vertices, edges and multiple wires. The first wire specifies the polygon boundary. Subsequent wires spcify the polygon holes.
- add_attrib(ent_type, att_name, att_data_type)¶
Create a new attribute in the model, specifying the entity type, the attribute name, and the data type. Note that for each entity type, the attribute name must be a unique name.
- Parameters
ent_type – The entity type for the attribute. (See ENT_TYPE)
att_name – The name of the attribute to create.
att_data_type – The data type for the attribute values. (See DATA_TYPE)
- Returns
No value.
- add_coll()¶
Add a new empty collection to the model.
- Returns
The ID of the collection.
- add_coll_ent(coll, ent)¶
Add an entity to an existing collection in the model. Collections can contain points, polylines, polygons, and other collections. Collections cannot contain positions, vertices, edges or wires.
- Parameters
coll – The ID of the collection to which the entity will be added.
ent – The ID of the entity to be added to the collection.
- Returns
No value.
- add_pgon(posis)¶
Add a polygon object to the model, specifying a list of positions.
- Parameters
posis – A list of position IDs.
- Returns
The ID of the new polygon.
- add_pline(posis, closed)¶
Add a polyline object to the model, specifying a list of positions.
- Parameters
posis – A list of position IDs.
closed – A boolean indicating if the polyline is closed or open.
- Returns
The ID of the new polyline.
- add_point(posi)¶
Add a point object to the model, specifying a single position.
- Parameters
posi – A position ID.
- Returns
The ID of the new point.
- add_posi(xyz)¶
Add a position to the model, specifying the XYZ coordinates.
- Parameters
xyz – The XYZ coordinates, a list of three numbers.
- Returns
The ID of the new position.
- export_sim()¶
Return a JSON formatted string representing that data in the model.
- Returns
A JSON string in the SIM format.
- export_sim_data()¶
Return JSON representing that data in the SIM model.
- Returns
JSON data.
- export_sim_file(filepath)¶
Import SIM file.
- Returns
No value.
- get_attrib_val(ent, name)¶
Get an attribute value from an entity in the model, specifying the attribute name.
- Parameters
ent – The ID of the entity for which to get the attribute value.
name – The name of the attribute.
- Returns
The attribute value or None if no value.
- get_attribs(ent_type)¶
Get a list of attribute in the model, specifying the entity type.
- Parameters
ent_type – The entity type for getting attributes. (See ENT_TYPE)
- Returns
A list of attrib names.
- get_ents(target_ent_type, source_ents=None)¶
Get entities of a specific type. A list of entity IDs is returned.
If source_ents is None, then all entities of the specified type in the model are returned. If there are no entities of that type in the model, then an empty list is returned.
If source_ents contains a list of entities, then entities will be extracted from the source ents. For example, if ent_type is ‘posis’ and ‘source_ents’ is a polyline and a polygon, then a list containing the positions used in the polyline and polygon are returned. Similarly, if ent_type is ‘pgons’ and ‘source_ents’ is a list of positions, then a list of polygons is returned, of polygons that make use of the specified positions.
- Parameters
target_ent_type – The type of entity to get from the model.
source_ents – None, or a single entity ID or a list of entity IDs from which to get the target entities.
- Returns
A list of unique entity IDs.
- get_model_attrib_val(att_name)¶
Get an attribute value from the model, specifying a name. Model attributes are top level attributes that apply to the whole model. As such, they are not attached to any specific entities.
- Parameters
att_name – The name of the attribute.
- Returns
The attribute value or None if no value.
- get_model_attribs()¶
Get a list of attribute names from the model. Model attributes are top level attributes that apply to the whole model. As such, they are not attached to any specific entities.
- Returns
A list of attribute names.
- get_pgon_posis(pgon)¶
Get a list of lists of position IDs for an polygon. Each list represents one of the polygon wires. All wires are assumed to be closed. (The last position is not duplicated.)
- Parameters
pgon – A polygon ID from which to get the positions.
- Returns
A list of lists of position IDs. The lists may contain duplicates.
- get_pline_posis(pline)¶
Get a list of position IDs for a polyline. If the polyline is closed, the first and last positions will be the same.
- Parameters
pline – A polyline ID from which to get the positions.
- Returns
A list of position IDs. The list may contain duplicates.
- get_point_posi(point)¶
Get the position ID for a point.
- Parameters
point – A point ID from which to get the position.
- Returns
A position ID.
- import_sim(json_str)¶
Import SIM string.
- Returns
No value.
- import_sim_data(json_data)¶
Import SIM JSON data.
- Returns
No value.
- import_sim_file(filepath)¶
Import SIM file.
- Returns
No value.
- info()¶
Print information about the model. This is mainly used for debugging.
- Returns
A string describing the data in the model.
- num_ents(ent_type)¶
Get the number of entities in the model of a specific type.
- Parameters
ent_type – The type of entity to search for in the model.
- Returns
A number of entities of the specified type in the model.
- pline_is_closed(pline)¶
Check if a polyline is open or closed.
- Parameters
pline – A polyline ID.
- Returns
True if closed, False if open.
- set_attrib_val(ent, att_name, att_value)¶
Set the value of an attribute, specifying the entity in the model, the attribute name and the attribute value.
Note that an attribute with the specified name must already exist in the model. If the attribute does not exist, an exception will be thrown. In addition, the attribute value and the data type for the attribute must match.
- Parameters
ent – The ID of the entity.
att_name – The name of the attribute.
att_value – The attribute value to set.
- Returns
No value.
- set_model_attrib_val(att_name, att_value)¶
Set an attribute value from the model, specifying a name and value. Model attributes are top level attributes that apply to the whole model. As such, they are not attached to any specific entities.
- Parameters
att_name – The name of the attribute.
att_value – The attribute value to set.
- Returns
No value.