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
18
19
20
21
22
23
24
25
26 public class ShapeModel extends AbstractOTSModel
27 {
28
29 private static final long serialVersionUID = 20140815L;
30
31
32 private Map<String, OTSRoadNode> nodes;
33
34
35 private Map<String, Link> shpLinks;
36
37
38 private OTSRoadNetwork network = new OTSRoadNetwork("shape model network", true, getSimulator());
39
40
41
42
43 public ShapeModel(final OTSSimulatorInterface simulator)
44 {
45 super(simulator);
46 }
47
48
49 @Override
50 public final void constructModel() throws SimRuntimeException
51 {
52 try
53 {
54
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
68 @Override
69 public final OTSRoadNetwork getNetwork()
70 {
71 return this.network;
72 }
73
74
75 @Override
76 public Serializable getSourceId()
77 {
78 return "ShapeModel";
79 }
80
81 }