LandSurveyCodesImport.toolbelt.qlsc_reader module#

Read QGIS Land Survey Codification (QLSC) files, which are YAML.

exception LandSurveyCodesImport.toolbelt.qlsc_reader.BadQlscStructure[source]#

Bases: Exception

Custom exception.

class LandSurveyCodesImport.toolbelt.qlsc_reader.QlscYamlReader(in_yaml: Union[str, pathlib.Path, io.BufferedIOBase])[source]#

Bases: object

Read and validate a QLSC (YAML) file.

Parameters

in_yaml – path to the yaml file to read.

QLSC_KEYS = ['AllPoints', 'BoundingGeometry', 'Codification', 'CodeSeparator', 'ErrorPoints', 'ParameterSeparator']#
property as_dict: dict#

Returns the YAML loaded into a Python dictionary.

Returns:

dict: YAML document as Python dictionary object

check_yaml_buffer(yaml_buffer: io.BufferedIOBase) io.BufferedIOBase[source]#

Perform some checks on passed yaml file.

Parameters

yaml_buffer – bytes reader of the yaml file to check

Returns

checked bytes object

Return type

BufferedIOBase

check_yaml_file(yaml_path: Union[str, pathlib.Path]) pathlib.Path[source]#

Perform some checks on passed yaml file and load it as Path object.

Parameters

yaml_path – path to the yaml file to check

Returns

sanitized yaml path

Return type

Path

check_yaml_structure(in_yaml_data: dict) bool[source]#

Look into the YAML structure and check everything it’s OK.

Parameters

in_yaml_data (dict) – YAML file data loaded as dict

Returns

check result

Return type

bool

Example

# here comes an example in Python
my_yaml = Path("sample.yml")
with my_yaml.open(mode="r") as op:
    yaml_data = yaml.full_load_all(bytes_data)
    if not check_yaml_structure(yaml_data):
        print("Bad YAML spotted!")
replace_parent_paths(original_path: str, new_path: str) dict[source]#

Helper to replace string parts within QLSC layers paths.

Parameters
  • original_path (str) – string to replace

  • new_path (str) – replacement string

Raises

BadQlscStructure – [description]

Returns

modified YAML content ready to be dumped

Return type

dict

Example

qlsc_rdr = QlscYamlReader("codification.qlsc")

with open("codification_replaced.qlsc", "w") as stream:
    yaml.dump(
        qlsc_rdr.replace_parent_paths("/tmp/lsci", "/tmp/youpi"),
        stream,
        default_flow_style=False,
    )