Bases: ConfigurableResource
The 3DBAG specifications.
Source: https://github.com/3DBAG/3dbag-specs
Source code in packages/common/src/bag3d/common/resources/specs.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 | class Specs3DBAGResource(ConfigurableResource):
"""
The 3DBAG specifications.
Source: https://github.com/3DBAG/3dbag-specs
"""
_attributes_specs: Optional[Dict[str, Attribute]] = PrivateAttr(default=None)
@property
def attributes(self) -> Dict[str, Attribute]:
"""Returns the complete attributes specification."""
# Lazy load the attributes
if self._attributes_specs is None:
self._attributes_specs = load_attributes_spec()
return self._attributes_specs
def applies_to(
self,
data_format: str,
locations: Union[
tuple[CityJSONLocation], tuple[GpkgLocation], tuple[Cesium3dTilesLocation]
],
) -> Generator[Tuple[str, Attribute], None, None]:
"""Filter the attributes spec for the specified data format and location.
Args:
data_format: The data format that contains the attribute (`cityjson`, `gpkg`, `cesium3dtiles`).
locations: The tuple of locations for the attribute in the data format.
Returns:
A generator that only contains the attributes that are only in the requested data format and location.
"""
allowed_formats = ["cityjson", "gpkg", "cesium3dtiles"]
requested_locations = set(locations)
if data_format not in allowed_formats:
raise ValueError(
f"Unsupported data format: {data_format}. Allowed formats are: {allowed_formats}"
)
for a_name, a_spec in self.attributes.items():
if format_spec := getattr(a_spec.applies_to, data_format):
if attribute_locations := format_spec["locations"]:
if len(requested_locations.intersection(attribute_locations)) > 0:
yield a_name, a_spec
|
attributes
property
Returns the complete attributes specification.
applies_to(data_format, locations)
Filter the attributes spec for the specified data format and location.
Parameters:
Name |
Type |
Description |
Default |
data_format
|
str
|
The data format that contains the attribute (cityjson , gpkg , cesium3dtiles ).
|
required
|
locations
|
Union[tuple[CityJSONLocation], tuple[GpkgLocation], tuple[Cesium3dTilesLocation]]
|
The tuple of locations for the attribute in the data format.
|
required
|
Returns:
Type |
Description |
None
|
A generator that only contains the attributes that are only in the requested data format and location.
|
Source code in packages/common/src/bag3d/common/resources/specs.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 | def applies_to(
self,
data_format: str,
locations: Union[
tuple[CityJSONLocation], tuple[GpkgLocation], tuple[Cesium3dTilesLocation]
],
) -> Generator[Tuple[str, Attribute], None, None]:
"""Filter the attributes spec for the specified data format and location.
Args:
data_format: The data format that contains the attribute (`cityjson`, `gpkg`, `cesium3dtiles`).
locations: The tuple of locations for the attribute in the data format.
Returns:
A generator that only contains the attributes that are only in the requested data format and location.
"""
allowed_formats = ["cityjson", "gpkg", "cesium3dtiles"]
requested_locations = set(locations)
if data_format not in allowed_formats:
raise ValueError(
f"Unsupported data format: {data_format}. Allowed formats are: {allowed_formats}"
)
for a_name, a_spec in self.attributes.items():
if format_spec := getattr(a_spec.applies_to, data_format):
if attribute_locations := format_spec["locations"]:
if len(requested_locations.intersection(attribute_locations)) > 0:
yield a_name, a_spec
|