SpeedLimit.java

  1. package org.opentrafficsim.road.network.sampling.data;

  2. import org.djunits.unit.SpeedUnit;
  3. import org.djunits.value.vfloat.scalar.FloatSpeed;
  4. import org.djutils.exceptions.Throw;
  5. import org.opentrafficsim.core.gtu.GtuException;
  6. import org.opentrafficsim.core.network.NetworkException;
  7. import org.opentrafficsim.kpi.sampling.data.ExtendedDataSpeed;
  8. import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
  9. import org.opentrafficsim.road.network.sampling.GtuDataRoad;

  10. /**
  11.  * Speed limit for trajectories.
  12.  * <p>
  13.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  15.  * </p>
  16.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  17.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  18.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  19.  */
  20. public class SpeedLimit extends ExtendedDataSpeed<GtuDataRoad>
  21. {

  22.     /**
  23.      * Constructor.
  24.      */
  25.     public SpeedLimit()
  26.     {
  27.         super("speedLimit", "Speed limit");
  28.     }

  29.     /** {@inheritDoc} */
  30.     @Override
  31.     public final FloatSpeed getValue(final GtuDataRoad gtu)
  32.     {
  33.         Throw.whenNull(gtu, "GTU may not be null.");
  34.         LaneBasedGtu laneGtu = gtu.getGtu();
  35.         try
  36.         {
  37.             return new FloatSpeed(laneGtu.getReferencePosition().lane().getSpeedLimit(laneGtu.getType()).si,
  38.                     SpeedUnit.SI);
  39.         }
  40.         catch (NetworkException | GtuException exception)
  41.         {
  42.             throw new RuntimeException("Could not obtain speed limit.", exception);
  43.         }
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public final String toString()
  48.     {
  49.         return "SpeedLimit";
  50.     }

  51. }