hi there.
Im doing som route(geo) calculations. I need to sort out some routes going in the "wrong" direction... all rides have "routes" and all routes consist of a lot of steps on the route.... each step has a lat. and a lng. pair. I hope this makes sense?
This is the way i do it now, and it works... however... im performing this operation on many(!) rides..routes...coordinate-pairs, so i could use a little speed-up in my code.
for ride in initial_rides:
steps = ride.route.steps.all()
for step in steps:
if lat_min < step.latitude< lat_max and lng_min< step.longitude< lng_max:
approved_rides.append(ride)
break
I better admit already that i'm no super programmer :)
i have tried construction something like this(without any luck):
for i in ride:
number = sum(itertools.ifilter(lambda x: lat_min< x.latitude< lat_max and lng_min< x.longitude< lng_max, ride.route.steps.all()))
if number >= 1:
approved_rides.append(ride)
tried to combine lambda and ifilter however i get an error saying operator doesn't support types "int" and "step"... Am i doing something wrong?
should i be using list comprehensions?? map()?? or something else?
i have read through http://www.python.org/doc/essays/list2str.html without any luck.
any help is greatly appreciated. thank you, and good day :)
Peter