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