Sha256: 368eacd932413f826b95bc00ed993fb4acb2bd12c69fb6ed238af8a8f198916e
Contents?: true
Size: 1.82 KB
Versions: 7
Compression:
Stored size: 1.82 KB
Contents
module PostgisAdapter module Functions # # Class Methods # module ClassMethods # # Returns the closest record 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 # # Order by distance 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 def by_length opts = {} sort = opts.delete(:sort) || 'asc' opts.merge!(:order => "ST_length(geom) #{sort}") find(:all, opts) end def longest find(:first, :order => "ST_length(geom) DESC") end def contains(p, srid=4326) find(:all, :conditions => ["ST_Contains(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))"]) end def contain(p, srid=4326) find(:first, :conditions => ["ST_Contains(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))"]) end def by_area sort='asc' find(:all, :order => "ST_Area(geom) #{sort}" ) end def by_perimeter sort='asc' find(:all, :order => "ST_Perimeter(geom) #{sort}" ) end 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 def all_within(other) find(:all, :conditions => "ST_Within(geom, ST_GeomFromEWKT(E'#{other.as_hex_ewkb}'))") end def by_boundaries sort='asc' find(:all, :order => "ST_Boundary(geom) #{sort}" ) end end end end
Version data entries
7 entries across 7 versions & 2 rubygems