class TollGateConstraint: """TODO""" def __init__(self, pt1, pt2, time=None, type=TYPE_SELECT): """TODO""" self.gate = Track([Obs(pt1), Obs(pt2)]) self.time = time self.type = type def __str__(self): """TODO""" output = "Toll gate selecting constraint" if not self.time is None: output += " with " + str(self.time).lower() return output def plot(self, sym="ro-"): """TODO""" plt.plot(self.gate.getX(), self.gate.getY(), sym) def contains(self, track): """TODO""" return Geometry.intersects(self.gate, track) def select(self, tracks): """TODO""" if self.type == TYPE_SELECT: output = TrackCollection() for track in tracks: if self.contains(track): output.addTrack(track) return output if self.type == TYPE_CUT_AND_SELECT: return tracks
def test_selection_track_constraint(self): GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s") chemin = os.path.join(self.resource_path, './data/trace1.dat') trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",") trace.plot() # ===================================================================== trace1 = Track() c1 = trace.getObs(1350).position c0 = ENUCoords(c1.getX() + 5000, c1.getY()) c2 = ENUCoords(c1.getX() - 5000, c1.getY()) p1 = Obs(c0, GPSTime.readTimestamp("2018-07-31 14:00:00")) p2 = Obs(c1, GPSTime.readTimestamp("2018-07-31 14:01:00")) p3 = Obs(c2, GPSTime.readTimestamp("2018-07-31 14:02:00")) trace1.addObs(p1) trace1.addObs(p2) trace1.addObs(p3) plt.plot(trace1.getX(), trace1.getY(), 'r-') plt.show() c3 = TrackConstraint(trace1, mode=MODE_PARALLEL) s = Selector([c3]) selector = GlobalSelector([s]) isSelection = selector.contains(trace) self.assertFalse(isSelection) c4 = TrackConstraint(trace1, mode=MODE_CROSSES) s = Selector([c4]) selector = GlobalSelector([s]) isSelection = selector.contains(trace) self.assertTrue(isSelection) # ===================================================================== trace1 = Track() c0 = ENUCoords( trace.getObs(1349).position.getX(), trace.getObs(1349).position.getY()) c1 = ENUCoords( trace.getObs(1350).position.getX(), trace.getObs(1350).position.getY()) c2 = ENUCoords( trace.getObs(1351).position.getX(), trace.getObs(1351).position.getY()) p1 = Obs(c0, GPSTime.readTimestamp("2018-07-31 14:00:00")) p2 = Obs(c1, GPSTime.readTimestamp("2018-07-31 14:01:00")) p3 = Obs(c2, GPSTime.readTimestamp("2018-07-31 14:02:00")) trace1.addObs(p1) trace1.addObs(p2) trace1.addObs(p3) trace.plot() plt.plot(trace1.getX(), trace1.getY(), 'r-') plt.show() c3 = TrackConstraint(trace1, mode=MODE_PARALLEL) s = Selector([c3]) selector = GlobalSelector([s]) isSelection = selector.contains(trace) self.assertTrue(isSelection) c4 = TrackConstraint(trace1, mode=MODE_CROSSES) s = Selector([c4]) selector = GlobalSelector([s]) isSelection = selector.contains(trace) self.assertTrue(isSelection)