Reference

cjio.cityjson module

class cjio.cityjson.CityJSON(file=None, j=None, ignore_duplicate_keys=False)[source]

Bases: object

add_bbox_each_cityobjects()[source]
add_lineage_item(description: str, features: Optional[list] = None, source: Optional[list] = None, processor: Optional[dict] = None)[source]

Adds a lineage item in metadata.

Parameters
  • description – A string with the description of the process

  • features – A list of object ids that are affected by it

  • source – A list of sources. Every source is a dict with the respective info (description, sourceReferenceSystem etc.)

  • processor – A dict with contact information for the person that conducted the processing

add_to_j()[source]
calculate_bbox()[source]

Calculate the bbox of the CityJSON.

compress(important_digits=3)[source]
compute_metadata(overwrite=False, new_uuid=False)[source]

Returns the metadata of this CityJSON file

copy_textures(new_loc, json_path)[source]

Copy the texture files to a new location :param new_loc: path to new texture directory :type new_loc: string :param json_path: path to the CityJSON file directory :type json_path: string :returns: None – modifies the CityJSON :raises: InvalidOperation, IOError

decompress()[source]
export2b3dm()[source]
export2gltf()[source]
export2obj()[source]
export2stl()[source]
extract_lod(thelod)[source]
fetch_schema(folder_schemas=None)[source]
fetch_schema_cityobjects(folder_schemas=None)[source]
get_bbox()[source]
get_centroid(coid)[source]
get_cityobjects(type=None, id=None)[source]

Return a subset of CityObjects

Parameters
  • type – CityObject type. If a list of types are given, then all types in the list are returned.

  • id – CityObject ID. If a list of IDs are given, then all objects matching the IDs in the list are returned.

get_epsg()[source]
get_identifier()[source]

Returns the identifier of this file.

If there is one in metadata, it will be returned. Otherwise, the filename will.

get_info(long=False)[source]
get_metadata()[source]

Returns the “metadata” property of this CityJSON file

Raises a KeyError exception if metadata is missing

get_ordered_ids_top_co(limit, offset)[source]
get_subset_bbox(bbox, exclude=False)[source]
get_subset_cotype(cotype, exclude=False)[source]
get_subset_ids(lsIDs, exclude=False)[source]
get_subset_random(number=1, exclude=False)[source]
get_textures_location()[source]

Get the location of the texture files

Assumes that all textures are in the same location. Relative paths are expanded to absolute paths.

Returns

path to the directory or URL of the texture files

Return type

string (path) or None (on failure)

Raises

NotADirectoryError

get_title()[source]

Returns the description of this file from metadata.

If there is none, the identifier will be returned, instead.

get_version()[source]
has_metadata()[source]

Returns whether metadata exist in this CityJSON file or not

is_co_toplevel(co)[source]
is_empty()[source]
is_transform()[source]
load_from_j(transform: bool = True)[source]

Populates the CityJSON API members from the json schema member ‘j’.

If the CityJSON API members have values, they are removed and updated.

merge(lsCMs)[source]
number_city_objects()[source]
number_top_co()[source]
read(file, ignore_duplicate_keys=False)[source]
reference_geometry()[source]

Build a coordinate list and index the vertices for writing out to CityJSON.

remove_duplicate_vertices(precision=3)[source]
remove_materials()[source]
remove_orphan_vertices()[source]
remove_textures()[source]
reproject(epsg)[source]
set_cityobjects(cityobjects)[source]

Creates or updates CityObjects

Note

If a CityObject with the same ID already exists in the model, it will be overwritten

Parameters

cityobjects – Dictionary of CityObjects, where keys are the CityObject IDs. Same structure as returned by get_cityobjects()

set_epsg(newepsg)[source]
to_dataframe()[source]

Converts the city model to a Pandas data frame where fields are CityObject attributes

translate(values, minimum_xyz)[source]
triangulate_face(face, vnp)[source]
update_bbox()[source]

Update the bbox ([“metadata”][“bbox”]) of the CityJSON. If there is none then it is added.

update_metadata(overwrite=False, new_uuid=False)[source]

Computes and updates the “metadata” property of this CityJSON file

update_textures_location(new_loc, relative=True)[source]

Updates the location of the texture files

If the new location is a directory in the local file system, it is expected to exists with the texture files in it.

Parameters
  • new_loc (string) – path to new texture directory

  • relative (boolean) – create texture links relative to the CityJSON file

Returns

None – modifies the CityJSON

Raises

InvalidOperation, NotADirectoryError

upgrade_version(newversion)[source]
upgrade_version_v06_v08()[source]
upgrade_version_v08_v09(reasons)[source]
upgrade_version_v09_v10(reasons)[source]
validate(skip_schema=False, folder_schemas=None, longerr=False)[source]
validate_extensions(folder_schemas=None, longerr=False)[source]
validate_textures()[source]

Check if the texture files exist

cjio.cityjson.load(path, transform: bool = True)[source]

Load a CityJSON file for working with it though the API

Parameters
  • path – Absolute path to a CityJSON file

  • transform – Apply the coordinate transformation to the vertices (if applicable)

Returns

A CityJSON object

cjio.cityjson.off2cj(file)[source]
cjio.cityjson.poly2cj(file)[source]
cjio.cityjson.reader(file, ignore_duplicate_keys=False)[source]
cjio.cityjson.save(citymodel, path: str, indent: bool = False)[source]

Save a city model to a CityJSON file

Parameters
  • citymodel – A CityJSON object

  • path – Absolute path to a CityJSON file

cjio.models module

Demonstrate what is when we define the CityModel-objects in a top-down approach

class cjio.models.CityObject(id, type: Optional[str] = None, geometry: Optional[Iterable] = None, attributes: Optional[Mapping] = None, children: Optional[Iterable] = None, parents: Optional[Iterable] = None)[source]

Bases: object

CityObject class

build_index(vtx_lookup: Optional[Mapping] = None, vtx_idx: int = 0)[source]

Build a coordinate list and index the vertices for Geometry objects in the CityObject.

get_vertices()[source]

Dump the vertex coordinates of the CityObject into a list

to_json()[source]

Return a dictionary that conforms the CityJSON schema

class cjio.models.Geometry(type: Optional[str] = None, lod: Optional[str] = None, boundaries: Optional[Iterable] = None, semantics_obj: Optional[Mapping] = None, vertices=None, transform=None, texture_obj=None, appearance=None)[source]

Bases: object

CityJSON Geometry object

build_index(vtx_lookup: Optional[Mapping] = None, vtx_idx: int = 0)[source]

Build a coordinate list and index the vertices in the boundary.

This method is used when converting the Geometry to the JSON output.

build_semantic_surface_index()[source]

Index the semantic surfaces in way that is stored in JSON.

get_surface_boundaries(surface)[source]

Get the surface at the index location from the Geometry boundary

Note

Interior surfaces don’t have semantics and they are returned with the exterior.

Parameters

surface – A semantic surface

Returns

Surfaces from the boundary that correspond to the index.

get_surfaces(type: Optional[str] = None, lod: Optional[str] = None)[source]

Get the semantic surfaces of the given type

The whole boundary is returned if a geometry does not have semantics, or has a LoD < 2, or the surface type is not provided.

Parameters
  • type – Semantic Surface type. If not provided, the whole boundary is returned.

  • lod – Level of Detail

Returns

Return a subset of the specific surfaces of the geometry

get_vertices()[source]

Dump the vertex coordinates into a list

to_json()[source]

Return a dict that in the CityJSON schema

transform(transform: dict)[source]

Apply coordinate transformation to the boundary

Parameters

transformTransform object from CityJSON

Returns

A copy of the Geometry object with a boundary with transformed coordinates