def test_format_time(self): GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s") madate = '2018-01-31 13:21:46' t = GPSTime.readTimestamp(madate) self.assertEqual("31/01/2018 13:21:46", str(t)) GPSTime.setReadFormat("4Y-2M-2DT2h:2m:2s1Z") madate = '2018-01-31T11:17:46Z' t = GPSTime.readTimestamp(madate) self.assertEqual("31/01/2018 11:17:46", str(t)) d = GPSTime.readUnixTime(1550941038.0) self.assertIsInstance(d, GPSTime) self.assertEqual('23/02/2019 16:57:18', str(d)) self.assertEqual(23, d.day) self.assertEqual(2, d.month) self.assertEqual(2019, d.year) self.assertEqual(16, d.hour) self.assertEqual(57, d.min) self.assertEqual(18, d.sec)
def intersection(track1, track2, withTime=-1): if not (track1.getSRID() == track2.getSRID()): print("Error: tracks must have same SRID to compute intersections") exit() I = Track() TMP_I = [] TMP_J = [] TMP_TPS2 = [] for i in range(len(track1) - 1): x11 = track1[i].position.getX() y11 = track1[i].position.getY() x12 = track1[i + 1].position.getX() y12 = track1[i + 1].position.getY() seg1 = [x11, y11, x12, y12] for j in range(len(track2) - 1): x21 = track2[j].position.getX() y21 = track2[j].position.getY() x22 = track2[j + 1].position.getX() y22 = track2[j + 1].position.getY() seg2 = [x21, y21, x22, y22] if isSegmentIntersects(seg1, seg2): P1 = cartesienne(seg1) P2 = cartesienne(seg2) A = np.zeros((2, 2)) B = np.zeros((2, 1)) A[0, 0] = P1[0] A[0, 1] = P1[1] B[0, 0] = -P1[2] A[1, 0] = P2[0] A[1, 1] = P2[1] B[1, 0] = -P2[2] X = np.linalg.solve(A, B) x = X[0, 0] y = X[1, 0] p = Utils.makeCoords(x, y, 0, track1.getSRID()) # Linear interpolation on track 1 w1 = p.distance2DTo(track1[i].position) w2 = p.distance2DTo(track1[i + 1].position) p.setZ((w1 * track1[i + 1].position.getZ() + w2 * track1[i].position.getZ()) / (w1 + w2)) t1 = track1[i].timestamp.toAbsTime() t2 = track1[i].timestamp.toAbsTime() ta = (w1 * t2 + w2 * t1) / (w1 + w2) # Linear interpolation on track 2 w1 = p.distance2DTo(track2[j].position) w2 = p.distance2DTo(track2[j + 1].position) t1 = track2[i].timestamp.toAbsTime() t2 = track2[i].timestamp.toAbsTime() tb = (w1 * t2 + w2 * t1) / (w1 + w2) # Add intersection if (withTime == -1) or (abs(tb - ta) < withTime): I.addObs(Obs(p, GPSTime.readUnixTime(ta))) TMP_TPS2.append(GPSTime.readUnixTime(tb)) TMP_I.append(i) TMP_J.append(j) if I.size() > 0: I.createAnalyticalFeature("timestamp2", TMP_TPS2) I.createAnalyticalFeature("id1", TMP_I) I.createAnalyticalFeature("id2", TMP_J) return I