0

I have a Rails app and a bunch of points and polygons in a model

I am using mysql > 5.6 and the Geokit gem to generate polygon objects and I'm wondering if it's possible to find neighbouring polygons - That is, polygons that touch the polygon I'm in.

Any help is appreciated - Thanks!

-- UPDATE

Thinking of a solution I came up with this 1. Find all polygons objects 2. see which ones intersect with the one I have - if they intersect, they'd be neighbouring

Now I'm onto find how to find if they intersect. I believe you can do this with mysql spatial functions. I'll report back with an update.

lsaffie
  • 1,764
  • 1
  • 17
  • 22

1 Answers1

0

Found an answer to my question. Although not geokit specific, it works well.

I did this by using spatial mysql functions, in particular st_disjoint

Given a table with polygons I can find all polygons that are joint with the following query

select * from polygon where st_disjoint( ( select polygon from polygons where id=1), neighbourhoods.polygon) =0

I was hoping to get st_touches to work for this but it didn't work as I expected. Regardless st_disjoint does the work

Here's a reference to the functions.

http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html

lsaffie
  • 1,764
  • 1
  • 17
  • 22