예제 #1
0
파일: phem.py 프로젝트: sequielo/sumo
def fcd2fzp(inpFCD, outSTRM, further):
    """
    Reformats the contents of the given fcd-output file into a .fzp file, readable
    by PHEM. The fcd-output "fcd" must be a valid file name of an fcd-output.

    The "sIDm" parameter must be a map from SUMO-edge ids to their numerical 
    representation as generated by toSTR(inpNET, outSTRM).
    Returns two maps, the first from vehicle ids to a numerical representation,
    the second from vehicle type ids to a numerical representation.
    """
    sIDm = further["phemStreetMap"]
    if outSTRM != None:
        print(
            "t,WeltX,WeltY,Veh. No,v,Gradient,veh.Typ-Id,Str-Id", file=outSTRM)
    vIDm = sumolib._Running(further["orig-ids"], True)
    vtIDm = sumolib._Running()
    vtIDm.g("PKW")
    vtIDm.g("PKW_equipped")
    vtIDm.g("LKW")
    vtIDm.g("BUS")
    for q in inpFCD:
        if q.vehicle:
            for v in q.vehicle:
                vid = vIDm.g(v.id)
                aType = _convType(v.type)
                vtid = vtIDm.g(aType)
                sid = sIDm.g(v.edge)
                percSlope = math.sin(float(v.slope)) * 100.
                if outSTRM != None:
                    print("%s,%s,%s,%s,%s,%s,%s,%s" % (
                        sumolib._intTime(q.time), float(v.x), float(v.y),
                        vid, float(v.speed) * 3.6, percSlope, vtid, sid), file=outSTRM)
    return vIDm, vtIDm
예제 #2
0
def net2str(net, outSTRM):
  """
  Writes the network object given as "inpNET" as a .str file readable by PHEM.
  Returns a map from the SUMO-road id to the generated numerical id used by PHEM.

  The following may be a matter of changes:
  - currently, only the positions of the start and the end nodes are written, 
    the geometry of the edge as defined in the SUMO-network is not exported.
    A map between the edge id and a segment to a numerical id would be necessary 
  """
  if outSTRM!=None:
    print("Str-Id,Sp,SegAnX,SegEnX,SegAnY,SegEnY", file=outSTRM)
  sIDm = sumolib._Running()
  for e in net._edges:
    eid = sIDm.g(e._id)
    if outSTRM!=None:
      c1 = e._from._coord
      c2 = e._to._coord
      print("%s,%s,%s,%s,%s,%s" % (eid, len(e._lanes), c1[0], c2[0], c1[1], c2[1]), file=outSTRM)
  return sIDm 
def net2str(net, outSTRM):
    """
    Writes the network object given as "inpNET" as a .str file readable by PHEM.
    Returns a map from the SUMO-road id to the generated numerical id used by PHEM.

    The following may be a matter of changes:
    - currently, only the positions of the start and the end nodes are written, 
      the geometry of the edge as defined in the SUMO-network is not exported.
      A map between the edge id and a segment to a numerical id would be necessary 
    """
    if outSTRM != None:
        print("Str-Id,Sp,SegAnX,SegEnX,SegAnY,SegEnY", file=outSTRM)
    sIDm = sumolib._Running()
    for e in net._edges:
        eid = sIDm.g(e._id)
        if outSTRM != None:
            c1 = e._from._coord
            c2 = e._to._coord
            print("%s,%s,%s,%s,%s,%s" %
                  (eid, len(e._lanes), c1[0], c2[0], c1[1], c2[1]),
                  file=outSTRM)
    return sIDm