Skip to content

Location from IP, geocoding, distance calculation, and geo/map utilities

License

Notifications You must be signed in to change notification settings

kristianmandrup/geo_magic

Repository files navigation

Geo Magic

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.

Main features:

  • Find points within a radius (circle or square from center)
  • Generate random points within a radius (for testing purposes)

Update April 1 2012

Refactoring in progress

Create random points in Radius

From a given radius, you can create random points either in a square or circle radius.

  • create_points_in(shape_type, number)

Example use:

  radius = center_point.within(10.km)
  square_points = radius.create_points_in :square, 6
  circle_points = radius.create_points_in :circle 4  

Points within an area or distance

Within distance:

@points.as_map_points.within(4.km).of(@center_point)

The closest n points:

@points.as_map_points.the_closest(4).from(@center_point)

Or using container objects (objects containing a location):

@people.as_map_points.the_closest(4).from(@house)

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)

Meta magic

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]    

Contributing to geo_magic

  • 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

Copyright © 2011 Kristian Mandrup. See LICENSE.txt for
further details.

About

Location from IP, geocoding, distance calculation, and geo/map utilities

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages