Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. 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

Finding neighbouring shapes in MySQL spatial table made up of ID and 2D geometry (polygon) fields.

I have a table with an ID column and a geometry column (holding a polygon) representing various areas on a map. Given the ID of a particular row, say ID 4, I would like to find every polygon in the table that meets/touches the polygon held at ID 4.

I am aware MySQL < 5.6.1 only uses Minimum bounding rectangle rather than a proper function for this so could accept any MBR of another geometry column that intersects it for example.

I am having a little difficulty starting to write such a query. It would go something along the lines of:

check all rows for MBR_Intersects(some geometry column, geometry column for ID=4)

My SQL is like so:

(SELECT `geometry` as gp FROM geometrytable WHERE `id` = 4) AS TT  
WHERE MBRTouches(, geometrytable.`geometry`) = 1; 

I appreciate I am horribly off the mark in both the above but would really appreciate some guidance on how to tackle this.

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.