README.md in mongoid_spacial-0.2.0 vs README.md in mongoid_spacial-0.2.2
- old
+ new
@@ -20,21 +20,19 @@
field :name, type: String
field :length, type: Integer
field :average_discharge, type: Integer
field :source, type: Array, spacial: true
- # if you want something besides the defaults {bit: 24, min: -180, max: 180} just set index to the options on the index
- # field :source, type: Array, spacial: true
- # try not set index for this field manually as we record what spacial fields are index for some handy fields later
# set return_array to true if you do not want a hash returned all the time
- field :mouth, type: Array, spacial: {lat: 'latitude', lng: 'longitude', return_array: true }
+ field :mouth, type: Array, spacial: {lat: :latitude, lng: :longitude, return_array: true }
# simplified spacial indexing
- # you can only index one
+ # you can only index one point in mongodb version below 1.9
+ # if you want something besides the defaults {bit: 24, min: -180, max: 180} just set index to the options on the index
spacial_index :source
- # alternative
+
end
```
Before we manipulate the data mongoid_spacial handles is what we call points.
@@ -55,19 +53,21 @@
length: 315,
average_discharge: 21_400,
# when setting array LONGITUDE MUST BE FIRST LATITUDE MUST BE SECOND
# source: [-73.935833,44.106667],
# but we can use hash in any order,
- # the default keys for latitude and longitude are 'lat' and 'lng' respectively
- source: {'lat' => 44.106667, 'lng' => -73.935833},
- # remember keys must be strings
- mouth: {'latitude' => 40.703056, 'longitude' => -74.026667}
+ # the default keys for latitude and longitude are :lat and :lng respectively
+ source: {:lat => 44.106667, :lng => -73.935833},
+ mouth: {:latitude => 40.703056, :longitude => -74.026667}
)
# now to access this spacial information we can now do this
-hudson.source #=> {'lng' => -73.935833, 'lat' => 44.106667}
+hudson.source #=> {:lng => -73.935833, :lat => 44.106667}
hudson.mouth #=> [-74.026667, 40.703056] # notice how this returned as a lng,lat array because return_array was true
# notice how the order of lng and lat were switched. it will always come out like this when using spacial.
+# Also adds a handy distance function
+hudson.distance_from(:source, [-74,40], :mi)
+
```
Mongoid Geo has extended all built in spacial symbol extentions
* near
* River.where(:source.near => [-73.98, 40.77])