.create_reader(+)
Description
The factory method that allows you to create (manufacture) network reader instances of a chosen type. Currently, the following options are supported:
NetworkReaderType:OSM
generates anOsmNetworkReader
instance to parse Open Street Map networksNetworkReaderType:TNTP
generates aTntpNetworkReader
instance to parse networks in TNTP formatNetworkReaderType:PLANIT
generates aPlanitNetworkReader
instance to parse networks in the native PLANit format
Whenever a country name is/needs to be supplied, make sure this name complies with the ISO 3166 standard (see for example https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes).
Only for the Open Street Map reader it is recommended to provide the country of origin of the input file as it is used to create the appropriate defaults that are not embedded in the OSM files. If not provided or the country is not yet supported with OSM defaults by PLANit, the reader falls back to less accurate global defaults.
Each network reader can be configured further via its settings, where each type of network reader exposes different settings depending on its type
Signature
.create_reader(network_reader_type:NetworkReaderType, country:str=None)
with
Parameter | Type | Unit | Compulsory | Description |
---|---|---|---|---|
network_reader_type |
NetworkReaderType.<enum> |
None |
YES | Type of network reader to create |
country |
String |
None |
No | The Country the network is sourced from (ISO 3166). |
Return type
NetworkReader
implementation
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
NetworkReaderType.<enum>
for the various network reader types available
OsmNetworkReader
for more information on the OSM network reader
TntpNetworkReader
for more information on the TNTP network reader
PlanitNetworkReader
for more information on the PLANit network reader
Source code
Class NetworkConverter
in converter.py