Module: Sequel::Plugins::Mappable::DatasetMethods

Defined in:
lib/sequel_mappable.rb

Instance Method Summary collapse

Instance Method Details

#f_origin(origin, within) ⇒ Object



58
59
60
61
# File 'lib/sequel_mappable.rb', line 58

def f_origin(origin, within)
  sql = model.distance_sql(origin)
  f_origin_bbox(origin, within).filter{sql.lit <= within}
end

#f_origin_bbox(origin, within) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sequel_mappable.rb', line 46

def f_origin_bbox(origin, within)
  bounds = Geokit::Bounds.from_point_and_radius(origin, within, :units => :kms)
  sw, ne = bounds.sw, bounds.ne
  filter = self
  if bounds.crosses_meridian?
    filter = filter.filter{(lng < ne.lng) | (lng > sw.lng)}
  else
    filter = filter.filter{(lng < ne.lng) & (lng > sw.lng)}
  end
  filter.filter{(lat < ne.lat) & (lat > sw.lat)}
end