Module: PostgisAdapter::Functions::ClassMethods
- Defined in:
- lib/postgis_adapter/functions/class.rb,
lib/postgis_adapter/acts_as_geom.rb
Overview
Class Methods
Instance Method Summary collapse
- #all_dwithin(other, margin = 1) ⇒ Object
- #all_within(other) ⇒ Object
- #by_area(sort = 'asc') ⇒ Object
- #by_boundaries(sort = 'asc') ⇒ Object
- #by_length(opts = {}) ⇒ Object
- #by_perimeter(sort = 'asc') ⇒ Object
-
#close_to(p, opts = {}) ⇒ Object
Order by distance.
-
#closest_to(p, opts = {}) ⇒ Object
Returns the closest record.
- #contain(p, srid = 4326) ⇒ Object
- #contains(p, srid = 4326) ⇒ Object
- #get_geom_type(column) ⇒ Object
-
#has_geom(*geom) ⇒ Object
(also: #acts_as_geom)
has_geom :db_field => :geom_type Examples:.
- #longest ⇒ Object
Instance Method Details
#all_dwithin(other, margin = 1) ⇒ Object
51 52 53 54 |
# File 'lib/postgis_adapter/functions/class.rb', line 51 def all_dwithin(other, margin=1) # find(:all, :conditions => "ST_DWithin(geom, ST_GeomFromEWKB(E'#{other.as_ewkt}'), #{margin})") find(:all, :conditions => "ST_DWithin(geom, ST_GeomFromEWKT(E'#{other.as_hex_ewkb}'), #{margin})") end |
#all_within(other) ⇒ Object
56 57 58 |
# File 'lib/postgis_adapter/functions/class.rb', line 56 def all_within(other) find(:all, :conditions => "ST_Within(geom, ST_GeomFromEWKT(E'#{other.as_hex_ewkb}'))") end |
#by_area(sort = 'asc') ⇒ Object
43 44 45 |
# File 'lib/postgis_adapter/functions/class.rb', line 43 def by_area sort='asc' find(:all, :order => "ST_Area(geom) #{sort}" ) end |
#by_boundaries(sort = 'asc') ⇒ Object
60 61 62 |
# File 'lib/postgis_adapter/functions/class.rb', line 60 def by_boundaries sort='asc' find(:all, :order => "ST_Boundary(geom) #{sort}" ) end |
#by_length(opts = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/postgis_adapter/functions/class.rb', line 25 def by_length opts = {} sort = opts.delete(:sort) || 'asc' opts.merge!(:order => "ST_length(geom) #{sort}") find(:all, opts) end |
#by_perimeter(sort = 'asc') ⇒ Object
47 48 49 |
# File 'lib/postgis_adapter/functions/class.rb', line 47 def by_perimeter sort='asc' find(:all, :order => "ST_Perimeter(geom) #{sort}" ) end |
#close_to(p, opts = {}) ⇒ Object
Order by distance
19 20 21 22 23 |
# File 'lib/postgis_adapter/functions/class.rb', line 19 def close_to(p, opts = {}) srid = opts.delete(:srid) || 4326 opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))") find(:all, opts) end |
#closest_to(p, opts = {}) ⇒ Object
Returns the closest record
11 12 13 14 15 |
# File 'lib/postgis_adapter/functions/class.rb', line 11 def closest_to(p, opts = {}) srid = opts.delete(:srid) || 4326 opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))") find(:first, opts) end |
#contain(p, srid = 4326) ⇒ Object
39 40 41 |
# File 'lib/postgis_adapter/functions/class.rb', line 39 def contain(p, srid=4326) find(:first, :conditions => ["ST_Contains(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))"]) end |
#contains(p, srid = 4326) ⇒ Object
35 36 37 |
# File 'lib/postgis_adapter/functions/class.rb', line 35 def contains(p, srid=4326) find(:all, :conditions => ["ST_Contains(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))"]) end |
#get_geom_type(column) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/postgis_adapter/acts_as_geom.rb', line 33 def get_geom_type(column) self.postgis_geoms.values[0] rescue nil # self.columns.select { |c| c.name == column.to_s }[0].geometry_type # rescue ActiveRecord::StatementInvalid => e # nil end |
#has_geom(*geom) ⇒ Object Also known as: acts_as_geom
has_geom :db_field => :geom_type Examples:
has_geom :data => :point has_geom :geom => :line_string has_geom :geom => :polygon
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/postgis_adapter/acts_as_geom.rb', line 21 def has_geom(*geom) cattr_accessor :postgis_geoms self.postgis_geoms = geom[0] # {:columns => column send :include, case geom[0].values[0] when :point then PointFunctions when :polygon then PolygonFunctions when :line_string, :multi_line_string then LineStringFunctions when :multi_polygon then MultiPolygonFunctions end unless geom[0].kind_of? Symbol end |
#longest ⇒ Object
31 32 33 |
# File 'lib/postgis_adapter/functions/class.rb', line 31 def longest find(:first, :order => "ST_length(geom) DESC") end |