Search code examples
pythonsimulationsumo

Obtain GEO Coordinates from sumo simulation using TraCI


I am using TraCI library in python to launch and control a sumo simulation from code, step by step. My problem is that I need the coordinates of the vehicles in lat, lon UTM evey step of the simulation. I obtain the x,y coordinates from the simulation every step with a TraCI listener and then I try to convert these values to lat and lon:

for vehicleId in traci.vehicle.getIDList():
        speed = traci.vehicle.getSpeed(vehicleId)
        x, y = traci.vehicle.getPosition(vehicleId)
        lon, lat = traci.simulation.convertGeo(x, y)
        lon, lat = self.net.convertXY2LonLat(x, y)

None of the two conversions work, first one returns the same values and the second one usually throws an error:

"RuntimeError: b'projection not named'"

Which I guess is because there is no projection properly described in the network file. Problem here is that NONE of the scenarios work here, even though some of them can do the fcd-output (projected coordinates).

Does any one have encountered a similar problem?

Regards and thank you!


Solution

  • Problem was that the networks where not geo-referenced properly. It is needed that the projection parameter is '+proj=utm ...' instead of '!'.

    This means any fcd-output you are getting is also provided in terms of x,y (cartesian) network coordinates. Likewise, the lower left-right corner in sumo-gui will not provide correct lat,lon values for such a network.

    Refer to this issue.