diff trafficintelligence/moving.py @ 1075:67144f26609e

Updates crop
author Wendlasida
date Wed, 11 Jul 2018 15:01:37 -0400
parents 75a6ad604cc5
children 108c5dc4e34a
line wrap: on
line diff
--- a/trafficintelligence/moving.py	Fri Jul 06 18:42:58 2018 -0400
+++ b/trafficintelligence/moving.py	Wed Jul 11 15:01:37 2018 -0400
@@ -1150,6 +1150,29 @@
         self.setNObjects(nObjects) # a feature has None for nObjects
         self.features = None
         # compute bounding polygon from trajectory
+        
+    @staticmethod
+    def cropedTimeInterval(obj, value, after = True):
+        newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant())
+        if obj.positions is not None :
+            newPositions = obj.positions[slice(newTimeInterval.first, newTimeInterval.last+1)]
+        else:
+            newPositions = None
+        if obj.velocities is not None :
+            newVelocities = obj.velocities[slice(newTimeInterval.first, newTimeInterval.last+1)]
+        else:
+            newVelocities = None
+        if obj.features is not None :
+            newFeatures = [f.cropedTimeInterval(value, after) for f in obj.features]
+        else:
+            newFeatures = None
+        res = MovingObject(obj.getNum(), newTimeInterval, newPositions, newVelocities, obj.geometry, obj.userType, obj.nObjects)
+        res.features = newFeatures
+        res.featureNumbers = obj.featureNumbers
+        if hasattr(obj, 'projectedPositions'):
+            res.projectedPositions = obj.projectedPositions[slice(newTimeInterval.first, newTimeInterval.last+1)]
+        return res
+
 
     @staticmethod
     def aggregateTrajectories(features, interval = None, aggFunc = mean):
@@ -1339,6 +1362,7 @@
             self.nObjects = nObjects
         else:
             print('Number of objects represented by object {} must be greater or equal to 1 ({})'.format(self.getNum(), nObjects))
+            self.nObjects = None
         
     def setFeatures(self, features, featuresOrdered = False):
         '''Sets the features in the features field based on featureNumbers