class Geonames::Data::LocationIndex
Public Class Methods
load(filepath, &filter)
click to toggle source
# File lib/geonames/data/location_index.rb, line 22 def self.load(filepath, &filter) new(Features.load(filepath, filter)) end
new(features)
click to toggle source
# File lib/geonames/data/location_index.rb, line 6 def initialize(features) @features = features.inject({}) { |index, feature| index.update(feature.geoname_id => feature) } points = features.map do |feature| [ feature.latitude, feature.longitude, feature.geoname_id ] end @index = Kdtree.new(points) end
Public Instance Methods
nearest(latitude, longitude)
click to toggle source
# File lib/geonames/data/location_index.rb, line 14 def nearest(latitude, longitude) @features[@index.nearest(latitude, longitude)] end
nearestk(latitude, longitude, count)
click to toggle source
# File lib/geonames/data/location_index.rb, line 18 def nearestk(latitude, longitude, count) @features.values_at(*@index.nearestk(latitude, longitude, count)) end