Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 113:606010d1d9a4
corrected errors in trajectories (if empty) and getTrajectoryInPolygon
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 18 Jul 2011 14:29:07 -0400 |
parents | 6efe470ea5e5 |
children | 680d4c82886d |
line wrap: on
line diff
--- a/python/moving.py Mon Jul 18 14:28:40 2011 -0400 +++ b/python/moving.py Mon Jul 18 14:29:07 2011 -0400 @@ -206,7 +206,10 @@ the class is iterable.''' def __init__(self, positions=None): - self.positions = positions + if positions: + self.positions = positions + else: + self.positions = [[],[]] @staticmethod def load(line1, line2): @@ -234,11 +237,8 @@ return self[self.iterInstantNum-1] def addPositionXY(self, x, y): - if not self.positions: - self.positions = [[x],[y]] - else: - self.positions[0].append(x) - self.positions[1].append(y) + self.positions[0].append(x) + self.positions[1].append(y) def addPosition(self, p): self.addPositionXY(p.x, p.y) @@ -334,15 +334,12 @@ '''Returns the set of points inside the polygon (array of Nx2 coordinates of the polygon vertices)''' import matplotlib.nxutils as nx - t = Trajectory() + traj = Trajectory() result = nx.points_inside_poly(self.asArray().T, polygon) for i in xrange(self.length()): if result[i]: - t.addPositionXY(self.positions[0][i], self.positions[1][i]) - if t.length()>0: - return t - else: - return None + traj.addPositionXY(self.positions[0][i], self.positions[1][i]) + return traj # version 2: use shapely polygon contains