broughcut / acts_as_line
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (2)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Thu Mar 06 13:48:12 -0800 2008 | |
| |
README | Sat Mar 22 14:14:32 -0700 2008 | |
| |
Rakefile | Thu Mar 06 13:48:12 -0800 2008 | |
| |
generators/ | Fri Mar 28 16:47:52 -0700 2008 | |
| |
init.rb | Sat Mar 22 14:14:32 -0700 2008 | |
| |
install.rb | Thu Mar 06 13:48:12 -0800 2008 | |
| |
lib/ | Thu Apr 10 03:16:31 -0700 2008 | |
| |
tasks/ | Thu Mar 06 13:48:12 -0800 2008 | |
| |
test/ | Thu Mar 06 13:48:12 -0800 2008 | |
| |
uninstall.rb | Thu Mar 06 13:48:12 -0800 2008 |
README
being rewritten.
see lib/act_as_line.rb for options.
ActsAsLine
==========
Need to add tests as a priority, and must clean things up.
In order to maintain consistency with postgis methods, intersects
is now simply intersects, the 'touching' alias has been removed.
added:
a.intersects?(b)
a.covers?(b)
a.covered_by?(b)
Foo.within(b,:days,3,options={}) #also :secs, :hours
Foo.covers(b,options={})
Foo.covered_by(b,options={})
covers: 'Geom A covers Geom B if no points of B lie in the exterior of A'
Early days.
Things are progressing (and probably breaking in places).
Some big changes, and some very undry source....
acts_as_line.rb has been rewritten to include instance methods.
I am basically adding functions as I need them.
> b = Foo.find(:first)
Length of line in seconds:
> b.duration
also
> b.duration(:days)
> b.duration(:weeks)
Query against a part line, in this case the first half:
> Foo.touching_segment(b,[0,0.5])
- where 0.5 is the midpoint of b's geom. A new line is created using the
start/end points specified in the array.
Find records that do not intersect the latter two thirds of the line (and
have a bar_id of 5):
> Foo.not_touching_segment(b,[0.3,1], :bar_id => 5)
This needs to be able to support actual days/hours, rather than a proportion
of a line -- which is not very robost if you are using it for bookings and
such like.
'asunder' method is now not_touching.
> b = Booking.find(:first)
> Booking.not_touching(b)
Foo.asunder is now an alias for the class method, not_in_intersects
which uses joins to speed up queries against a large dataset.
class Property < ActiveRecord::Base
has_many :bookings
acts_as_line
end
class Booking < ActiveRecord::Base
belongs_to :property
acts_as_line
end
class Bookable < ActiveRecord::Base
acts_as_line
end
> week = Bookable.find(38)
Find all *unbooked* properties for the booking period 'week'
without selecting each property:
> Property.asunder(Booking,week)
SQL:
SELECT (id) FROM properties WHERE properties.id
NOT IN (SELECT DISTINCT on (properties.id) properties.id FROM bookings
INNER JOIN properties ON properties.id=bookings.property_id
WHERE (ST_Intersects(bookings.geom,(SELECT geom FROM bookables
WHERE id = 38)) = true))
[SQL (0.000791) -- small dataset as yet, but seems reasonable]
SELECT (id) FROM properties WHERE properties.id
NOT IN (SELECT DISTINCT on (properties.id) properties.id FROM bookings
INNER JOIN properties ON properties.id=bookings.property_id
WHERE (ST_Intersects(bookings.geom,(SELECT geom FROM bookables
WHERE id = 38)) = true))
Example
=======
table must already have a start_date and end_date column of type date or datetime.
script/generate datesgeom_migration table_name
runs the following on target table:
execute("ALTER TABLE table_name ADD COLUMN geom geometry;")
execute("CREATE INDEX idx_table_name_dates_geom ON table_name USING GIST (geom);")
object = Foo.find(:first)
results = Foo.touching(object) | results = Foo.intersects(object,true)
results = Foo.not_touching(object) | results = Foo.intersects(object,false)
results = Foo.touching(object,{:id => 123})
results = Foo.touching(object,{:id => '>123'})
results = Foo.touching(object,{:id => '<>123'}) etc
results = Foo.touching(object,{:id => 123, :title => 'bar'})
