Take the 2-minute tour ×
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. It's 100% free, no registration required.

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 * FROM 
(SELECT `geometry` as gp FROM geometrytable WHERE `id` = 4) AS TT  
WHERE MBRTouches(TT.gp, 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

 
discard

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

Browse other questions tagged or ask your own question.