使用 rgeo,它看起来像这样......
注意:我将为此使用我的本地直线投影,SRID:3361,应该可以正常工作。单位以英尺为单位。但基本上只是一个笛卡尔网格CRS(坐标参考系统)
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 you have to build the polygons, its a 3 step process. array of points --> linear ring --> polygon
polygons = []
[p1, p2].each do |pointset|
points = []
pointset.each do |x, y|
points << f.point(x,y)
end
polygons << f.polygon(f.linear_ring(points))
end
#then you'd just use rgeo's methods to do the work
polygons[0].overlaps?(polygons[1])
#=> true
测试了这个。有用