Sha256: d1021842b9c100b8702b46c318ec5e8e243b0cef5ba18d90fd62525e9855be4d
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
module Mongoid module Geospatial extend ActiveSupport::Concern LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude] LAT_SYMBOLS = [:y, :lat, :latitude] EARTH_RADIUS_KM = 6371 # taken directly from mongodb RAD_PER_DEG = Math::PI / 180 EARTH_RADIUS = { :km => EARTH_RADIUS_KM, :m => EARTH_RADIUS_KM * 1000, :mi => EARTH_RADIUS_KM * 0.621371192, # taken directly from mongodb :ft => EARTH_RADIUS_KM * 5280*0.621371192, :sm => EARTH_RADIUS_KM * 0.53995680345572 # sea mile } mattr_accessor :lng_symbols mattr_accessor :lat_symbols mattr_accessor :earth_radius mattr_accessor :factory @@lng_symbols = LNG_SYMBOLS.dup @@lat_symbols = LAT_SYMBOLS.dup @@earth_radius = EARTH_RADIUS.dup included do attr_accessor :geo cattr_accessor :spatial_fields, :spatial_fields_indexed @@spatial_fields = [] @@spatial_fields_indexed = [] end def self.use_rgeo require 'mongoid_geospatial/wrappers/rgeo' end def self.use_georuby require 'mongoid_geospatial/wrappers/georuby' end module ClassMethods #:nodoc: # create spatial index for given field # @param [String,Symbol] name # @param [Hash] options options for spatial_index # http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-geoNearCommand def spatial_index name, options = {} self.spatial_fields_indexed << name index({name => '2d'}, options) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid_geospatial-2.3.0 | lib/mongoid_geospatial/geospatial.rb |
mongoid_geospatial-2.2.0 | lib/mongoid_geospatial/geospatial.rb |