View Javadoc
1   package org.opentrafficsim.demo.geometry.shape;
2   
3   import java.io.Serializable;
4   import java.util.LinkedHashMap;
5   import java.util.Map;
6   
7   import org.djunits.value.vdouble.scalar.Time;
8   import org.opentrafficsim.core.dsol.AbstractOTSModel;
9   import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
10  import org.opentrafficsim.core.network.Link;
11  import org.opentrafficsim.road.network.OTSRoadNetwork;
12  import org.opentrafficsim.road.network.lane.OTSRoadNode;
13  
14  import nl.tudelft.simulation.dsol.SimRuntimeException;
15  
16  /**
17   * <p>
18   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * <p>
21   * $LastChangedDate: 2020-05-08 11:08:12 +0200 (Fri, 08 May 2020) $, @version $Revision: 6464 $, by $Author: pknoppers $,
22   * initial version Sep 9, 2014 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
25   */
26  public class ShapeModel extends AbstractOTSModel
27  {
28      /** */
29      private static final long serialVersionUID = 20140815L;
30  
31      /** Nodes from shape file. */
32      private Map<String, OTSRoadNode> nodes;
33  
34      /** Links from shape file. */
35      private Map<String, Link> shpLinks;
36  
37      /** the network. */
38      private OTSRoadNetwork network = new OTSRoadNetwork("shape model network", true, getSimulator());
39  
40      /**
41       * @param simulator OTSSimulatorInterface; the simulator
42       */
43      public ShapeModel(final OTSSimulatorInterface simulator)
44      {
45          super(simulator);
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public final void constructModel() throws SimRuntimeException
51      {
52          try
53          {
54              // Read the shape files with the function:
55              this.nodes = ShapeFileReader.readNodes(network, "/gis/TESTcordonnodes.shp", "NODENR", true, true);
56              this.shpLinks = new LinkedHashMap<>();
57              ShapeFileReader.readLinks(network, "/gis/TESTcordonlinks_aangevuld.shp", this.shpLinks, this.nodes, this.simulator);
58  
59              this.simulator.scheduleEventAbs(Time.ZERO, this, this, "ntmFlowTimestep", null);
60          }
61          catch (Throwable exception)
62          {
63              exception.printStackTrace();
64          }
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public final OTSRoadNetwork getNetwork()
70      {
71          return this.network;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public Serializable getSourceId()
77      {
78          return "ShapeModel";
79      }
80  
81  }