Search code examples
postgresqlgispostgis

PostGis -> ST_Contains: how to check in which BBox of a table is the current BBox


I have a table graphs with a column bbox.

This column contains geometry and I save all kinds of bboxes there

SELECT AddGeometryColumn('graphs', 'bbox', 4326, 'POLYGON', 2 );

How could I check in which Bbox from column bbox lays the current bbox?

As I understand I have to do it with ST_Contains but I need a little help regarding the syntax.

I tried this kind of approach:

SELECT bbox,BBOX_Diagonale,file FROM graphs WHERE ST_CONTAINS(bbox,ST_MakeEnvelope( 11.58624574 , 47.71313579 , 12.21446607 , 48.13538804 , 4326)) order by BBOX_Diagonale ASC LIMIT 1;

And my table has these values:

-[ RECORD 1 ]-----------------------------
left_xmin   | 11.66952931
bottom_ymin | 47.79336862
right_xmax  | 12.18612053
top_ymax    | 48.14030283
filename    | my_sfn_cache1619119545.38177
-[ RECORD 2 ]-----------------------------
left_xmin   | 11.58624574
bottom_ymin | 47.71313579
right_xmax  | 12.21446607
top_ymax    | 48.13538804
filename    | my_sfn_cache1619119600.90796

So this query should provide me at least one entry fromm the table?


Solution

  • I had a small mistake where I write to db. Basically number mixup. Anyway if someone want to know how to find bbox that is inside other one in db this is how you do it.