Selecting by bounding box with PostGIS
just change the order of the questions and you have a procedure:
2)Select only what intersects the bbox (ST_Intersects
).
3)Intersect it with the bbox to clip the polygons (ST_Intersection
).
1)Create a new table with the results (CREATE TABLE newtable AS SELECT...
).
ST_Intersection docs contain a code sample. You will need to adapt it and use ST_PolygonFromText as the bbox.
I think most (all) web-clients (and desktop gis too) is doing this. You cannot send the whole dataset.
If you should set up some sort of caching depends on if your data is vary static or if it is changing.
To make this bounding box check to get the data will be very fast (if you have a spatial index), but of course it is not for free. You will pay with some cpu-power.
As said before: To find the polygons inside your extent you use ST_Intersects.
To get only the portion inside your extent use ST_Intersection, but don't do that. ST_Intersection is a costly process. Unless you have extremely big polygons I think it is better to send the whole polygons.
But I guess you want to do this on the fly instead of putting it in a table