# Re: [sumo-user] Can you clarify how density is computed for lanes and edges

```Hello,

Consider an aggregation period of 1s. In that case each vehicle on the lane
results in 1 sampled second so sampleSeconds gives the number of vehicles
on the lane.
Since the length of the lane is in m we get the density #veh/m by dividing
by myLaneLength.
To get #veh/km we multiply by 1000```
```
For longer periods, if the number of vehicle on the lane stays constant, it
should be obvious that the sampleSeconds is a multiple of the number and
the period and the formula is correct as well.

If the number of vehicles changes during the aggregation period, the
formula gives the appropriate average.

regards,
Jakob

2018-03-06 18:59 GMT+01:00 eegea <ee...@protonmail.com>:

> According to the wiki (http://sumo.dlr.de/wiki/Simulation/Output/Lane-_or_
> Edge-based_Traffic_Measures)
> density is given as "#veh/km"
> However, looking at the source in MSMeanData_Net line 179 and 208 it is
> computed as
>
>
> dev.writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal)
> 1000 / myLaneLength)
>
> I cannot see why the above gives the number of vehicles per Km in the lane
> during the period. As far as I see, sampleSeconds is updated as expected
> sampleSeconds += timeOnLane
> so it seems to be what the wiki says "Number seconds vehicles were
> measured on the edge/lane".
> It seems that we have the fraction of time the lane has been occupied
> multiplied by 1000  and divided by the lane length.
> Is this an error or is this coming from some formula I do not know of?
>
> _______________________________________________
> sumo-user mailing list
> sumo-user@eclipse.org
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/sumo-user
>
>
```
```_______________________________________________
sumo-user mailing list
sumo-user@eclipse.org
this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user
```