6

RGeo has convex hull method available, but no documentation at all in this matter.

Given set of Points, how to I find their convex hull?

1 Answers1

4

Good question. Turns out there is a geometry type called "MultiPoint" that works for this. I made a simple example to test it out and it appears to work well.

f = RGeo::Geos.factory(:srid => 3361, :buffer_resolution => 8) #my typical local rectilinear projection factory with my default settings.
coords = [[1,1], [2,2], [1,3]]
points = []
coords.each {|x,y| points << f.point(x,y)}

points

f.multi_point(points).convex_hull

looks good to me

Harry Wood
  • 2,220
  • 2
  • 24
  • 46
boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
  • I tried your solution but getting **NoMethodError: undefined method `factory' for #** error – shrikant1712 Oct 19 '16 at 12:31
  • 1
    Looks like you're calling the factory method on a factory – boulder_ruby Oct 23 '16 at 18:26
  • fix that issue, need to install `libgeos` package – shrikant1712 Oct 24 '16 at 06:49
  • To really illustrate the "convex hull" behaviour, this answer should show adding another point which lies within the area of the triangle formed by the other three points. As expected, the `convex_hull` method returns a polygon still with only the outside three points. – Harry Wood Dec 20 '16 at 22:43
  • (by the way, I edited the answer to fix the factory method on factory) – Harry Wood Dec 21 '16 at 23:55
  • This appears to work for a `RGeo::Geos.factory` but not for a `RGeo::Geographic.spherical_factory`. You can use a `RGeo::Geos.factory` and then convert to the other type but the conversion might create an invalid polygon. – Jacob Dalton Jun 13 '19 at 20:58