In my experience working with this I fired out that it is better to use
"haversine" directly on database, you can find haversine functions for
MySQL, Postgres and even for SQlite.

I dont know how one can write haversine with DAL api, but you can do it
with executesql() as you are going to turn this in to json.

BTW: you can use rows.exclude(lambda row: row.x == y) to remove items
I guess you can combine rows with Rows += Rows/ or Rows &= Rows if they are
scheme identically.

Take a look at row.exclude() on dal chapter of the book


On Mon, Sep 17, 2012 at 4:51 PM, Kenny <nis...@gmail.com> wrote:

> Basically, I get the place data with longitude and latitude, calculate it
> if it's more than 3000 miles, remove that row from Rows.
> I am sure that this is wrong. If I can remove the row from fetch rows, how
> can I add extra columns to the rows for distance between two points?
> P.S the result has to be Jsoned.
>
> Here's the code
>
> def tester():
>     items = db(db.dine_promotion.place_id==db.place.id).select()
>
>     latitude =float(23.790457)
>     longitude =float(-47.602542)
>     for row in items:
>         if row.place.latitude:
>             a=float(row.place.latitude)
>             b=float(row.place.longitude)
>             dist="%.2f" % calc_distance(latitude,longitude,a,b)
>             if  dist > 3000:
>                 items.remove(row)
>     return dict(restaurants = items)
>
>  --
>
>
>
>

-- 



Reply via email to