eatyourgreens / mongo_geo

A MongoMapper plugin that adds geospatial functionality.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mongo_geo

mongo_geo is a plugin for MongoMapper that exposes the GeoSpatial indexing features in MongoDb.

I've started testing against ruby 1.8.7 and 1.9.1. So far, so good.

Usage

On the model

	class TestAsset
	  include MongoMapper::Document
	  plugin GeoSpatial

	  geo_key :coords, Array
	end

Plucky style queries:

	TestAsset.where(:coords.near => [50, 50]).limit(10).to_a
	TestAsset.where(:coords.within => { "$center" => [[50, 50], 10] }).to_a				# "$center" => [center, radius]
	TestAsset.where(:coords.within => { "$box" => [ [45, 45], [55, 55] ] }).to_a		# [lower_left, top_right]

N.B. bounds queries are syntactically ugly at the moment and are likely to change soon

geoNear and convenience methods

	nearby = TestAsset.near([50, 50], :num => 15, :query => { ... })
	nearby.average_distance						# average distance of all results from the target point
	nearby.first.distance						# distance of this result from the target
	TestAsset.first.distance_from([50, 50])		# distance from any point
	TestAsset.first.neighborhood(:limit => 10)  # closest objects to this one

Queries can be specified with the ruby driver style finders

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

About

A MongoMapper plugin that adds geospatial functionality.

License:MIT License


Languages

Language:Ruby 100.0%