This little magic gem attempts to provide a nice DSL for performing Geo functionality.
It levearegs some of my other geo- gems.
Geo Magic should mainly be a DSL sugar-coating on top of these geo gems and integrate them all in a nice, convenient way under the cover.
- Find points within a radius (circle or square from center)
- Generate random points within a radius (for testing purposes)
Refactoring in progress
From a given radius, you can create random points either in a square or circle radius.
- create_points_in(shape_type, number)
radius = center_point.within(10.km) square_points = radius.create_points_in :square, 6 circle_points = radius.create_points_in :circle 4
The closest n points:
Or using container objects (objects containing a location):
Where @people is an array of Person and @house is an instance of House and where both House and Person has a #location, #to_point or #point method that returns an object
with latitude and longitude methods that each return a float.
Within bounding rectangle (see Geo::Shapes in ‘geo_shapes’ gem) :
rectangle = GeoMagic::Rectangle.new(GeoMagic::Point.new(-115, 50), GeoMagic::Point.new(-100, 20)) # or # rect = GeoMagic::Rectangle.create_from_coords lat1, long1, lat2, long2 @points.as_map_points.within_rectangle(rect).from(@center_point)
You can also include the functionality directly into any class like this
class Map include Geo::Calculate end class MapCalc geo_magic :calc end dist = Map.distance [@long1, @lat1], [@long2, @lat2] dist = MapCalc.distance [@long1, @lat1], [@long2, @lat2]
- Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
- Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
- Fork the project
- Start a feature/bugfix branch
- Commit and push until you are happy with your contribution
- Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright © 2011 Kristian Mandrup. See LICENSE.txt for