geolocation - check if 2 polygons overlap in ruby -


i'm looking way check if 2 polygons (set of lat/lon coordinates) overlap in ruby. example if have points usa , points california, should able tell overlap.

i looked rgeo, apparently requires linux-only binaries work , i'm looking cross platform solution.

for example let's have 2 polygons like:

p1 = [[30, 30], [30, 40], [40, 40], [40, 30], [30, 30]] p2 = [[35, 35], [35, 45], [45, 45], [45, 35], [35, 35]] 

how can show overlap in ruby?

using rgeo, this...

note: i'm going use local rectilinear projection this, srid:3361, should work fine. units in feet, were. cartesian grid crs (coordinate reference system)

require 'rgeo' f = rgeo::geos.factory(:srid => 3361) p1 = [[30, 30], [30, 40], [40, 40], [40, 30], [30, 30]] p2 = [[35, 35], [35, 45], [45, 45], [45, 35], [35, 35]] #first have build polygons, 3 step process. array of points --> linear ring --> polygon polygons = [] [p1, p2].each |pointset|   points = []   pointset.each |x, y|     points << f.point(x,y)   end   polygons << f.polygon(f.linear_ring(points)) end #then you'd use rgeo's methods work polygons[0].overlaps?(polygons[1]) #=> true 

tested this. works


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -