-
-
Notifications
You must be signed in to change notification settings - Fork 15
Box
Carlos edited this page Aug 18, 2019
·
3 revisions
Box original implementation. Provides an easy interface to manipulate, save and restore, box-like values from the database. Works very similar to the ActiveRecord::Point
, but for a list of 2 points each one with an x
and y
value. PostgreSQL Docs
Just set the type of the column as box
when creating a table.
create_table "region" do |t|
t.string "title", null: false
t.box "area"
end
The column is automatically identified and its value turned into what is defined in geometry.box_class
or into a Torque::PostgreSQL::Box
.
This original implementation provides a couple of methods:
region = Region.new
region.area.x1
region.area.y1
region.area.x2
region.area.y2
region.area.points # Which will return the 4 points of the box
The value can be set in some different manners:
region.area = '1,1,10,10'
region.area = '[1,1],[10,10]'
region.area = '((1,1),(10,10))'
region.area = [1,1,10,10]
region.area = [[1,1],[10,10]]
region.area = { x1: 1, y1: 1, x2: 10, y2: 10 }
Can't find what you're looking for? Add an issue to the issue tracker.