Geos ruby - 创建点
Geos ruby - Create point
我正在为 Ruby 使用 GEOS 库而苦苦挣扎,我只想用 IRB 创建一个简单的点。
require geos
return true 所以安装成功。但是我真的不明白 documentation and nothing helps on the github 页面。
我试过 Geos::Point.new('POINT(0 0)')
但它 return 是 TypeError: allocator undefined for Geos::Point
GEOS 是一个 C++ 库。查看那里的文档以了解所需的 Ruby 语法没有多大帮助。
你需要这个 rgeo
gem.
这里有一个很好的教程:"Geo-Rails Part 3: Spatial Data Types with RGeo"
举个例子:
# 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
我正在为 Ruby 使用 GEOS 库而苦苦挣扎,我只想用 IRB 创建一个简单的点。
require geos
return true 所以安装成功。但是我真的不明白 documentation and nothing helps on the github 页面。
我试过 Geos::Point.new('POINT(0 0)')
但它 return 是 TypeError: allocator undefined for Geos::Point
GEOS 是一个 C++ 库。查看那里的文档以了解所需的 Ruby 语法没有多大帮助。
你需要这个 rgeo
gem.
这里有一个很好的教程:"Geo-Rails Part 3: Spatial Data Types with RGeo"
举个例子:
# 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