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
Post a Comment