Whats going on: I am working with postGIS and spatial datas. I am having trouble to fully understand the R-tree algorithm.

Example query: In which town is point P located?

My understanding so far is: Each polygon has a boundingBox, this boundingBox has an idex. These boundingBoxes are then merged into another larger boundingBox which also has an idex. Continuing the process creates the R-tree. With the help of the R-tree the query is much faster. But ...

My question is at what point are these indexes created? Does the R-tree exists per se? Or is the R-tree created on the run time when I start a query?


You have to create a spatial index.

Create index idx_mytable_geom ON my_table USING gist(geom);

Then it is often a good idea to run

ANALYZE mytable;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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