module EasyPostgis

Constants

VERSION

Public Instance Methods

distance_select_sql(other) click to toggle source
# File lib/easy_postgis.rb, line 16
def distance_select_sql(other)
  "ST_Distance(#{geography_from_table},#{geography_from_point(other.lng,other.lat)}) as distance"
end
geography_from_point(lon, lat) click to toggle source
# File lib/easy_postgis.rb, line 24
def geography_from_point(lon, lat)
  "ST_GeographyFromText('SRID=4326;POINT(%f %f)')" % [lon, lat]
end
geography_from_table() click to toggle source
# File lib/easy_postgis.rb, line 20
def geography_from_table
  "ST_GeographyFromText('SRID=4326;POINT(' || #{table_name}.lng || ' ' || #{table_name}.lat || ')')"
end
near_sql(other, distance_in_meters) click to toggle source
# File lib/easy_postgis.rb, line 12
def near_sql(other, distance_in_meters)
  "ST_DWithin(#{geography_from_table},#{geography_from_point(other.lng,other.lat)},%d)" % [distance_in_meters]
end