/usr/share/sumo/tools/osmBuild.py is in sumo-tools 0.32.0+dfsg1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #!/usr/bin/env python
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
# Copyright (C) 2009-2017 German Aerospace Center (DLR) and others.
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# @file osmBuild.py
# @author Daniel Krajzewicz
# @author Jakob Erdmann
# @author Michael Behrisch
# @date 2009-08-01
# @version $Id$
from __future__ import absolute_import
import os
import optparse
import subprocess
from os import path
import sumolib # noqa
vclassRemove = {"passenger": ["--keep-edges.by-vclass", "passenger"],
"road": ["--remove-edges.by-vclass", "tram,rail_urban,rail_electric,bicycle,pedestrian"],
"all": []}
possibleVClassOptions = '|'.join(vclassRemove.keys())
DEFAULT_NETCONVERT_OPTS = "--geometry.remove,--roundabouts.guess,--ramps.guess,-v,--junctions.join,--tls.guess-signals,--tls.discard-simple,--tls.join,--output.original-names,--junctions.corner-detail,5,--output.street-names"
optParser = optparse.OptionParser()
optParser.add_option("-p", "--prefix", default="osm", help="for output file")
# don't know whether area or bbox call was used
optParser.add_option(
"-f", "--osm-file", help="full name of the osm file to import")
optParser.add_option("-m", "--typemap", default=None,
help="typemap file for the extraction of colored areas (optional)")
optParser.add_option("--netconvert-typemap", default=None,
help="typemap files for netconverter (optional)")
optParser.add_option("-o", "--oldapi-prefix", default=None,
help="prefix that was used for retrieval with the old API")
optParser.add_option("-t", "--tiles", type="int", default=1,
help="number of tiles used for retrieving OSM-data via the old api")
optParser.add_option("-c", "--vehicle-classes", default='all',
help="[(%s)]extract network for a reduced set of vehicle classes" % possibleVClassOptions)
optParser.add_option("-d", "--output-directory", default=os.getcwd(),
help="directory in which to put the output files")
optParser.add_option("-n", "--netconvert-options",
default=DEFAULT_NETCONVERT_OPTS, help="comma-separated options for netconvert")
optParser.add_option("--pedestrians", action="store_true",
default=False, help="add pedestrian infrastructure to the network")
optParser.add_option("-y", "--polyconvert-options",
default="-v,--osm.keep-full-type", help="comma-separated options for polyconvert")
def build(args=None, bindir=None):
(options, args) = optParser.parse_args(args=args)
if ((options.oldapi_prefix and options.osm_file) or
not (options.oldapi_prefix or options.osm_file)):
optParser.error(
"exactly one of the options --osm-file and --oldapi-prefix must be supplied")
if options.typemap and not path.isfile(options.typemap):
# fail early because netconvert may take a long time
optParser.error('typemap file "%s" not found' % options.typemap)
if not (options.vehicle_classes in vclassRemove):
optParser.error('invalid vehicle class "%s" given' %
options.vehicle_classes)
if not path.isdir(options.output_directory):
optParser.error('output directory "%s" does not exist' %
options.output_directory)
netconvertOpts = [sumolib.checkBinary('netconvert', bindir)]
if options.pedestrians:
netconvertOpts += ['--sidewalks.guess', '--crossings.guess']
if options.netconvert_typemap:
netconvertOpts += ["-t", options.netconvert_typemap]
netconvertOpts += options.netconvert_options.split(',') + ['--osm-files']
polyconvertOpts = [sumolib.checkBinary('polyconvert', bindir)] + \
options.polyconvert_options.split(',') + \
['--type-file', options.typemap, '--osm-files']
prefix = options.oldapi_prefix
if prefix: # used old API
num = options.tiles
tiles = ",".join(["%s%s_%s.osm.xml" % (prefix, i, num)
for i in range(num)])
netconvertOpts += [tiles]
polyconvertOpts += [tiles]
else: # used new API
netconvertOpts += [options.osm_file]
polyconvertOpts += [options.osm_file]
prefix = path.basename(options.osm_file).replace('.osm.xml', '')
if options.prefix:
prefix = options.prefix
basename = path.join(options.output_directory, prefix)
netfile = basename + '.net.xml'
netconvertOpts += vclassRemove[options.vehicle_classes] + ["-o", netfile]
subprocess.call(netconvertOpts)
# write config
subprocess.call(netconvertOpts +
["--save-configuration", basename + ".netccfg"])
if options.typemap:
polyconvertOpts += ["-n", netfile, "-o", basename + '.poly.xml']
subprocess.call(polyconvertOpts)
# write config
subprocess.call(polyconvertOpts +
["--save-configuration", basename + ".polycfg"])
if __name__ == "__main__":
build()
|