view python/processing.py @ 1010:c90c4682c67e

concatenateWith,addFeatures,delFeatures,updatePosition, (new functions) ; concatenate (update) : from line 1145 to 1320
author Wendlasida
date Fri, 25 May 2018 15:14:27 -0400
parents 15e244d2a1b5
children 933670761a57
line wrap: on
line source

#! /usr/bin/env python
'''Algorithms to process trajectories and moving objects'''

import moving

import numpy as np


def extractSpeeds(objects, zone):
    speeds = {}
    objectsNotInZone = []
    import matplotlib.nxutils as nx        
    for o in objects:
        inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T)
        if inPolygon.any():
            objspeeds = [o.getVelocityAt(i).norm2() for i in xrange(int(o.length()-1)) if inPolygon[i]]
            speeds[o.num] = np.mean(objspeeds) # km/h
        else:
            objectsNotInZone.append(o)
    return speeds.values(), speeds, objectsNotInZone