Sha256: edba3519007f6cfea0ecde9d5a23b0e9a6a4c08736a9ff4651e0dcf1dc60aa31

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

module PostgisFunctions
  
  
    ###
    ##
    #
    # Class Methods
    #
    # Falling back to AR here.
    #
    module ClassMethods

      #
      # Returns the closest record 
      #
      def closest_to(p, srid=4326)
        find(:first, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" )
      end

      def close_to(p, srid=4326)
        find(:all, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" )
      end

      #
      #
      #
      def by_length sort='asc'
        find(:all, :order => "ST_length(geom) #{sort}" )
      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_within(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 by_boundaries sort='asc'
        find(:all, :order => "ST_Boundary(geom) #{sort}" )
      end

    end
  
  
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
nofxx-postgis_adapter-0.1.8 lib/postgis_functions/class.rb
nofxx-postgis_adapter-0.2.1 lib/postgis_functions/class.rb
nofxx-postgis_adapter-0.2.2 lib/postgis_functions/class.rb
nofxx-postgis_adapter-0.3.0 lib/postgis_functions/class.rb
nofxx-postgis_adapter-0.3.1 lib/postgis_functions/class.rb
nofxx-postgis_adapter-0.3.3 lib/postgis_functions/class.rb
postgis_adapter-0.3.0 lib/postgis_functions/class.rb
postgis_adapter-0.2.3 lib/postgis_functions/class.rb
postgis_adapter-0.2.1 lib/postgis_functions/class.rb
postgis_adapter-0.1.8 lib/postgis_functions/class.rb