[OSM-dev] Map rendering code... API or database direct?
lars at aronsson.se
Fri Mar 31 06:37:13 BST 2006
> > SELECT id,path FROM segments WHERE
> > ((xmin BETWEEN $bbox_xmin AND $bbox_xmax) OR
> > (xmax BETWEEN $bbox_xmin AND $bbox_xmax) OR
> > (xmin<$bbox_xmin AND xmax>$bbox_xmax)) AND
> > ((ymin BETWEEN $bbox_ymin AND $bbox_ymax) OR
> > (ymax BETWEEN $bbox_ymin AND $bbox_ymax) OR
> > (ymin<$bbox_ymin AND ymax>$bbox_ymax))
> > where xmin, xmax, ymin and ymax are the bounding box of each segment, and
> > $bbox_xmin, $bbox_xmax etc. are the bounding box of the current map view
> > (tile).
> with postgresql 8.1 (that includes the postgis geometric objects), it's even
> easier :D
> SELECT * FROM segments WHERE
> ( point_a @ box('(x1,y1),(x2,y2)') ) OR
> ( point_b @ box('(x1,y1),(x2,y2)') )
I don't think that is an equivalent solution. Both A and B can be
outside the tile, with the line segment still passing across the
tile. What the previous example tests is whether the bounding box
around A and B, box(point_a, point_b), overlaps with the tile.
This could be elegantly formulated with PostgreSQL, but not the
way you did.
+ - - A bounding box of line segment A-B
. / .
.|/ overlap |
B|- - + |
At my local university bookstore, there are now several books with
basic algorithms for computer game design that are useful here.
Lars Aronsson (lars at aronsson.se)
Aronsson Datateknik - http://aronsson.se
More information about the dev