Giter Club home page Giter Club logo

geo_point's Introduction

Geo Point

Adds the concept of a GeoPoint for geo libraries. A GeoPoint encapsulates latitude and longitude, and:

  • a coordinates mode (coord_mode) that can be set to either :lng_lat or :lat_lng
  • calculations such as: distance_to, bearing_to, midpoint, intersection and destination point
  • parsing from various String, Hash or Array formats, including from DMS string format, such as “58 38 38N, 003 04 12W”

Using GeoPoints makes it much easier and more efficient to transport location point data and various geo libraries adds additional functionality such as
vector operations on top (see fx geo_vectors gem). Enjoy!

Install

Gemfile:

gem 'geo_point'

$ bundle

Status Sept 2012

Currently a few of the specs break. Please help Fix. They might be related to geo_calc and/or geo_units gems.

Quick start (Usage)

First define the points on the globe you want to work with.
The GeoPoint initializer is very flexible with regards to the arguments it can handle.

  # factory method on core ruby classes
  "51 12 03 N, 24 10 02 E".geo_point
  [51.5136, -0.0983].geo_point
  {:latitude => 27.3, :longitude => "24 10 02 E"}.geo_point

  # two arguments
  p1 = GeoPoint.new 51.5136, -0.0983
  p2 = GeoPoint.new "14 11 01 N", "-0.0983"
  p3 = GeoPoint.new 51.5136, "24 10 02 E"

  # a String
  p1 = GeoPoint.new "51.5136, -0.0983"
  p1 = GeoPoint.new "51.5136, 24 10 02 E"
  p3 = GeoPoint.new "51.4778, -0.0015"  
  p1 = GeoPoint.new "51 12 03 N, 24 10 02 E"

  # an Array
  p2 = GeoPoint.new [51.5136, -0.0983]
  p2 = GeoPoint.new [51.5136, "24 10 02 E"]
  p2 = GeoPoint.new [51.5136, {:lon => 27.3}]

  # a Hash
  p4 = GeoPoint.new {:lat => 27.3, :lng => "24 10 02 E"}
  p4 = GeoPoint.new {:latitude => 27.3, :longitude => "24 10 02 E"}  

Utility methods

These are some of the utility methods you can use on a GeoPoint object

  p1 = GeoPoint.new 5.1, -7
  p1.lat          # latitude
  p1.lon          # longitude
  p1.to_lat_lng   # Array representation of [lat, lng]
  p1.to_lng_lat   # Array representation of [lng, lat]
  p1.to_s         # String representation (DMS format)
  p1.to_coords    # calls either #to_lat_lng or #to_lng_lat depending on global :coord_mode setting

Global configuration options

  GeoPoint.coord_mode = :lat_lng
  GeoPoint.coord_mode = :lng_lat
  
  GeoPoint.earth_radius_km  = 6379 
  GeoPoint.earth_radius_km  = 6371 

GeoPoint functionality

A GeoPoint always has the following calculation API available:

  • bearing_to(point)
  • final_bearing_to(point)
  • destination_point(brng, dist)
  • distance_to(point)
  • intersection_point(brng1, p2, brng2)
  • midpoint_to(point)

Rhumb: (see Rhumb_line)

  • rhumb_distance_to(point)
  • rhumb_bearing_to(point)
  • rhumb_destination_point(brng, dist)

See the geo_calc gem for details on how to use this Api

Contributing to geo_point

  • 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.

geo_point's People

Contributors

alexch avatar kristianmandrup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alexch yokesh440

geo_point's Issues

DDMM decimal seconds do not get recognized

I have a batch of coordinates expressed as eg 43° 51' 45.12345" N, 120° 51' 19.333" W. Unfortunately, the decimal seconds result in failed parsing and GeoPoint.new returns nil for lat and lng.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.