Skip to content

Commit

Permalink
can now set preference for output with coordinates. refs #14422
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Feb 29, 2024
1 parent 375da6f commit c3e2342
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tools/import/matsim/matsim_importPlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def get_options(args=None):
default=False, help="Repair routes after import (needs a SUMO net)")
op.add_argument("--remove-loops", action="store_true", category="processing",
default=False, help="Remove loops in routes after import (needs a SUMO net)")
op.add_argument("--prefer-coordinate", action="store_true", category="processing",
default=False, help="Use coordinates instead of link ids if both are given")
op.add_argument("--default-start", metavar="TIME", default="0:0:0", category="time",
help="default start time for the first activity")
op.add_argument("--default-end", metavar="TIME", default="24:0:0", category="time",
Expand All @@ -67,8 +69,8 @@ def get_options(args=None):
return options


def getLocation(activity, attr, prj = None):
if activity.link:
def getLocation(options, activity, attr, prj = None):
if activity.link and (not options.prefer_coordinate or not activity.x):
return '%s="%s"' % (attr, activity.link)
elif activity.x and activity.y:
if prj:
Expand Down Expand Up @@ -141,8 +143,8 @@ def main(options):
leg = lastLeg
leg.dep_time = lastAct.end_time
writeLeg(outf, options, idveh, leg,
getLocation(lastAct, "from", prj),
getLocation(item, "to", prj))
getLocation(options, lastAct, "from", prj),
getLocation(options, item, "to", prj))
lastLeg = None
lastAct = item
durations.append(item.max_dur if item.max_dur else options.default_dur)
Expand Down Expand Up @@ -171,7 +173,7 @@ def main(options):
lastLeg = None
for item in plan.getChildList():
if "act" in item.name: # act or activity
end = getLocation(item, "to", prj)
end = getLocation(options, item, "to", prj)
if lastLeg is not None:
if lastLeg.mode == "non_network_walk":
pass
Expand All @@ -187,7 +189,7 @@ def main(options):
else:
timing = 'duration="%s"' % durations[actIndex]
outf.write(' <stop %s %s actType="%s"/>\n' %
(getLocation(item, "edge", prj), timing, item.type))
(getLocation(options, item, "edge", prj), timing, item.type))
actIndex += 1
if item.name == "leg":
lastLeg = item
Expand Down

0 comments on commit c3e2342

Please sign in to comment.