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
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.