Reputation: 672
I'm struggling using the GEOS library for Ruby, I just want to create a simple point with IRB.
require geos
return true so the install works. But the I don't really understand the documentation and nothing helps on the github page.
I tried Geos::Point.new('POINT(0 0)')
but it returns a TypeError: allocator undefined for Geos::Point
Upvotes: 2
Views: 410
Reputation: 54223
GEOS is a C++ library. It doesn't help much to look at the documentation there to learn the required Ruby syntax.
You'd need this rgeo
gem.
Here's a good tutorial : "Geo-Rails Part 3: Spatial Data Types with RGeo"
As an example :
# gem install rgeo
require 'rgeo'
factory = RGeo::Cartesian.factory
point = factory.point(0, 0)
puts point
# POINT (0.0 0.0)
square = factory.parse_wkt("POLYGON((1 0, 0 1, -1 0, 0 -1, 1 0))")
puts square
# POLYGON ((1.0 0.0, 0.0 1.0, -1.0 0.0, 0.0 -1.0, 1.0 0.0))
puts square.contains?(point)
# true
Upvotes: 5