Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/moving.py @ 1075:67144f26609e
Updates crop
author | Wendlasida |
---|---|
date | Wed, 11 Jul 2018 15:01:37 -0400 |
parents | 75a6ad604cc5 |
children | 108c5dc4e34a |
comparison
equal
deleted
inserted
replaced
1054:d13f9bfbf3ff | 1075:67144f26609e |
---|---|
1148 self.geometry = geometry | 1148 self.geometry = geometry |
1149 self.userType = userType | 1149 self.userType = userType |
1150 self.setNObjects(nObjects) # a feature has None for nObjects | 1150 self.setNObjects(nObjects) # a feature has None for nObjects |
1151 self.features = None | 1151 self.features = None |
1152 # compute bounding polygon from trajectory | 1152 # compute bounding polygon from trajectory |
1153 | |
1154 @staticmethod | |
1155 def cropedTimeInterval(obj, value, after = True): | |
1156 newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant()) | |
1157 if obj.positions is not None : | |
1158 newPositions = obj.positions[slice(newTimeInterval.first, newTimeInterval.last+1)] | |
1159 else: | |
1160 newPositions = None | |
1161 if obj.velocities is not None : | |
1162 newVelocities = obj.velocities[slice(newTimeInterval.first, newTimeInterval.last+1)] | |
1163 else: | |
1164 newVelocities = None | |
1165 if obj.features is not None : | |
1166 newFeatures = [f.cropedTimeInterval(value, after) for f in obj.features] | |
1167 else: | |
1168 newFeatures = None | |
1169 res = MovingObject(obj.getNum(), newTimeInterval, newPositions, newVelocities, obj.geometry, obj.userType, obj.nObjects) | |
1170 res.features = newFeatures | |
1171 res.featureNumbers = obj.featureNumbers | |
1172 if hasattr(obj, 'projectedPositions'): | |
1173 res.projectedPositions = obj.projectedPositions[slice(newTimeInterval.first, newTimeInterval.last+1)] | |
1174 return res | |
1175 | |
1153 | 1176 |
1154 @staticmethod | 1177 @staticmethod |
1155 def aggregateTrajectories(features, interval = None, aggFunc = mean): | 1178 def aggregateTrajectories(features, interval = None, aggFunc = mean): |
1156 'Computes the aggregate trajectory from list of MovingObject features' | 1179 'Computes the aggregate trajectory from list of MovingObject features' |
1157 positions = Trajectory() | 1180 positions = Trajectory() |
1337 def setNObjects(self, nObjects): | 1360 def setNObjects(self, nObjects): |
1338 if nObjects is None or nObjects >= 1: | 1361 if nObjects is None or nObjects >= 1: |
1339 self.nObjects = nObjects | 1362 self.nObjects = nObjects |
1340 else: | 1363 else: |
1341 print('Number of objects represented by object {} must be greater or equal to 1 ({})'.format(self.getNum(), nObjects)) | 1364 print('Number of objects represented by object {} must be greater or equal to 1 ({})'.format(self.getNum(), nObjects)) |
1365 self.nObjects = None | |
1342 | 1366 |
1343 def setFeatures(self, features, featuresOrdered = False): | 1367 def setFeatures(self, features, featuresOrdered = False): |
1344 '''Sets the features in the features field based on featureNumbers | 1368 '''Sets the features in the features field based on featureNumbers |
1345 if not all features are loaded from 0, one needs to renumber in a dict''' | 1369 if not all features are loaded from 0, one needs to renumber in a dict''' |
1346 if featuresOrdered: | 1370 if featuresOrdered: |