Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large dataset in a PostGIS database. I am viewing it via a web interface that loads the data as GeoJSON. There is too much data to give the client all at once (10s of MBs worth...) so I would like to get an area of data within the bounding box formed by the edges of the window (the dotted line in the image below). Getting the coordinates for points f and g is easy.

Question 1: Is this a good way of doing things? Should I be thinking of caching them as tiles or is this method likely to be efficient enough?

Question 2: How do I retrieve just the data within this bounding box?

Question 3: If a shape overlaps the edge of the bounding box (e.g. shape A below) is there a simple way to crop it as it is queried like in the second image?

enter image description here

share|improve this question
Which viewer are you running on the client? – underdark Feb 16 '11 at 12:29
Mapstraction. I'm currently using OpenLayers as the provider. – Mr_Chimp Feb 16 '11 at 12:32
up vote 8 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.