Code Monkey home page Code Monkey logo

acts_as_line's Introduction

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'})

acts_as_line's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.