Model
model
Package containing models, the pythonic representation of feature classes.
They inherit from BaseFeature, which extends the Pydantic BaseModel with some utility, and are resolved via an Appschema instance.
A feature collection is represented by the BaseCollection class.
Example
Load the BP_Plan model for XPlanung v6.0 and instantiate it with some data:
Appschema
Bases: BaseModel
Models a supported appschema.
Used to access metadata like name, version and description for an appschema.
During instantion, validation if an appschema is supported occurs, based on the modules
in appschema subdirectory.
The instance stores a reference to the appschema's module, which is used in the model_factory method the retrieve appschema classes.
Usage example
# get a featuretype from appschema
appschema = Appschema.from_prefix(prefix="xplan", version="6.0")
plan = appschema.model_factory(name="BP_Plan")
# show list of supported appschemas
Appschema.supported_appschemas()
# get an enum of supported appschemas
SupportedAppschemas = Appschema.enum()
SupportedAppschemas.XPLAN_6_0.value # -> XPlanGML 6_0
code
property
The enum code of the appschema.
version
property
The version of the appschema in <major>.<minor> format.
enum()
classmethod
Return an enumeration of supported appschemas.
Source code in xplan_tools/model/base.py
from_enum(code)
classmethod
Return an Appschema instance from enum code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
an appschema code, e.g. |
required |
Source code in xplan_tools/model/base.py
from_module(module_name)
cached
classmethod
Builds an Appschema instance from module name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
the fully qualified module name |
required |
Source code in xplan_tools/model/base.py
from_namespace(namespace)
classmethod
Builds an Appschema instance from the appschema's namespace.
Might return a compatible appschema version if no exact match is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
the namespace URI of the appschema |
required |
Source code in xplan_tools/model/base.py
from_prefix(prefix, version)
classmethod
Builds an Appschema instance from the appschema's prefix and version.
Might return a compatible appschema version if no exact match is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
the namespace prefix of the appschema, e.g. |
required |
version
|
str
|
the version of the appschema; major and minor are required |
required |
Source code in xplan_tools/model/base.py
model_factory(name)
Factory method for retrieving the corresponding pydantic model representation of a feature class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the feature class or enumeration |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
requested FeatureType not found |
Returns:
| Type | Description |
|---|---|
type[BaseFeature]
|
The concrete feature class inheriting from BaseFeature. |
Source code in xplan_tools/model/base.py
supported_appschemas()
classmethod
Return a list of currently supported appschemas.
Source code in xplan_tools/model/base.py
BaseFeature
Bases: _ConfiguredBaseModel, GMLAdapter, CoretableAdapter, JsonFGAdapter
Base class for application schema classes.
It extends pydantic BaseModel with Feature-related helper methods as well as conversion capabilities from/to other formats via inheriting from respective adapter classes.
appschema()
cached
classmethod
Return metadata about the application schema for the feature class.
get_associations()
cached
classmethod
Returns the classes association fields.
Source code in xplan_tools/model/base.py
get_geom_field()
cached
classmethod
Returns the classes geometry field name, if any.
Source code in xplan_tools/model/base.py
get_geom_srid()
get_geom_types()
cached
classmethod
Returns the types of the geometry attribute.
Source code in xplan_tools/model/base.py
get_geom_wkt()
Returns the object's eWKT geometry's WKT representation withouth SRID, if any.
get_name()
cached
classmethod
get_property_info(name)
cached
classmethod
Property information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The property's name. |
required |
Returns:
| Type | Description |
|---|---|
PropertyInfo
|
A typed dataclass holding the information. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
The name was not found in the model fields. |
Source code in xplan_tools/model/base.py
model_dump_coretable()
model_dump_coretable_bulk()
Dumps the model data to feature and refs dicts to bulk insert in a database.
model_dump_gml(**kwargs)
BaseCollection
Bases: BaseModel
Container for features that provides validation of references.
The features are stored in a dictionary with their ID as key and the feature instance as value.
add_style_properties(to_text=False, always_populate_schriftinhalt=False)
Add styling properties to presentational objects.
This method parses object (dientZurDarstellungVon) and property (art) references from presentational objects and derives styling information (stylesheetId, schriftinhalt) based on a set of defined rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_text
|
bool
|
Whether to convert symbolic presentational objects to textual ones. Defaults to False. |
False
|
always_populate_schriftinhalt
|
bool
|
Populate |
False
|
Source code in xplan_tools/model/base.py
check_references_and_srs()
Checks if all objects referenced via UUID are part of the collection and if all features have the same SRS, version and appschema.
Source code in xplan_tools/model/base.py
get_features()
get_single_plans(with_name=False)
Yields BaseCollection objects for every plan in the original collection.
Source code in xplan_tools/model/base.py
list_to_dict(data)
classmethod
Takes a list of BaseFeatures and returns a BaseCollection dict.
Source code in xplan_tools/model/base.py
make_copy(with_id_map=False)
Return a copy of the collection with new IDs.
All feature IDs are renewed and respective references are updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
with_id_map
|
bool
|
whether to additionally return a map of old IDs to new IDs |
False
|