On Wed, Aug 14, 2013 at 6:01 PM, René Fournier <[email protected]> wrote:
> The reason is that each of the rectangles are actually subdivided into 12 > smaller, equal rectangles, numbered/lettered A-L. How would you go about > doing this? It doesn't seem like something I can compute in the initial > query to retrieve the containing rectangle… Any ideas? > Sounds to me like you have data your database isn't modeling. Any particular reason you don't want to store the further divided rectangles? Assuming you have a reason you don't want to, width_bucket<http://www.postgresql.org/docs/9.2/static/functions-math.html>comes to mind: SELECT width_bucket(ST_X(point), ST_XMin(rect), ST_XMax(rect), 4) AS horizontal_subrect , width_bucket(ST_Y(point), ST_YMin(rect), ST_YMax(rect), 3) AS vertical_subrect FROM (SELECT ST_GeomFromText('POLYGON ((0 0,0 100,100 100,100 0,0 0))') AS rect) r , (SELECT ST_MakePoint(50,50) AS point) p; gives horizontal_subrect = 3, vertical_subrect = 2. You would need to be able to coordinate that column and row number to a rectangle letter, of course. Someone else might be able to expound on this a bit more about whether it's a good idea, but if your data is always rectangles, maybe Box2D would be better than geometry. SELECT ST_MakeBox2D(ST_MakePoint(0,0), ST_MakePoint(10,10)); I'm not sure if that gives any performance gains, but I wouldn't be surprised at all if it did.
_______________________________________________ postgis-users mailing list [email protected] http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
