NetworkConverter

NetworkConverter instance

The NetworkConverter class instance can be created via the ConverterFactory. Once created it can be used to create network readers and writers that in turn can be offered to this converter to convert from the reader format to the writer format.

Via its .create_reader(+) and .create_writer(+) methods, the converter can manufacture readers and writers of supported types. The reader takes a NetworkReaderType while the writer takes a NetworkWriterType to indicate what reader/writer is to be created. The result is an instance of the desired reader/writer. The user then can/should configure the reader/writer based on the available settings. Once configured, the actual conversion can be performed through this converter by providing the created reader/writer to the .convert(+) method.

The user is expected to configure each reader/writers minimum required settings, often involving setting input/output file locations and/or directories for example. For each reader/writer these minimum user configuration actions are clearly indicated. Failing to do so will cause the conversion to fail as information is missing.

Methods

NetworkConverter exposes the following methods

Name Description
.create_reader(+) Create a new network reader based on the provided NetworkReaderType
.create_writer(+) Create a new network writer based on the provided NetworkWriterType
.convert(+) Convert the network reader’s input into the network writer’s output format

Properties

N/A

Example 1

from planit import *

# create a network converter
planit_instance = Planit()
network_converter = planit_instance.converter_factory.create(ConverterType.NETWORK)

# example Open Street Map (OSM) network reader        
osm_reader = network_converter.create_reader(NetworkReaderType.OSM, "<country_name>")
osm_reader.settings.set_input_file("<path_to_input_file>")

# example Planit network writer
planit_writer = network_converter.create_writer(NetworkWriterType.PLANIT)
planit_writer.settings.set_output_directory("<path_to_output_dir>")
planit_writer.settings.set_country("<country_name>")

# perform conversion
network_converter.convert(osm_reader,planit_writer)

See also

ConverterFactory for the converter factory to create other types of converters
NetworkReaderType for the supported network reader types
NetworkWriterType for the supported network writer types

Source code

Class NetworkConverter in converter.py


.convert(+)

NetworkConverter method

.create_reader(+)

NetworkConverter reader factory method

.create_writer(+)

NetworkConverter writer factory method