Giter VIP home page Giter VIP logo

geocalc's Introduction

Geocalc

Build Status Hex.pm

Documentation: http://hexdocs.pm/geocalc

Calculate distance, bearing and more between latitude/longitude points

All the formulas are adapted from http://www.movable-type.co.uk/scripts/latlong.html

Installation

First, add Geocalc to your mix.exs dependencies:

def deps do
  [{:geocalc, "~> 0.5"}]
end

Then, update your dependencies:

$ mix deps.get

Now, list the :geocalc application as your application dependency:

def application do
  [applications: [:geocalc]]
end

Usage

Calculate distance (in meters) between 2 points

Geocalc.distance_between([50.0663889, -5.7147222], [58.6438889, -3.07])
# => 968853.5464535094

Get destination point given distance (meters) from start and end point

Geocalc.destination_point([50.0663889, -5.7147222], [58.6438889, -3.07], 100_000)
# => {:ok, [50.95412546615634, -5.488452905258299]}

Get destination point given distance (meters) and bearing from start point

Geocalc.destination_point([50.0663889, -5.7147222], 2.123, 100_000)
# => {:ok, [49.58859917965055, -4.533613856982982]}

Calculate bearing from start and end points

Geocalc.bearing([50.0663889, -5.7147222], [58.6438889, -3.07])
# => 0.1591708517503001

Get intersection point given start points and bearings

Geocalc.intersection_point([50.0663889, -5.7147222], 2.123, [55.0663889, -15.7147222], 2.123)
# => {:ok, [48.04228582473962, -1.0347033632388496]}

Geocalc.intersection_point([50.0663889, -5.7147222], 2.123, [50.0663889, -5.7147222], 2.123)
# => {:error, "No intersection point found"}

Get bounding box from a point and radius

berlin = [52.5075419, 13.4251364]
radius = 10_000
Geocalc.bounding_box(berlin, radius)
# => [[52.417520954378574, 13.277235453275123], [52.59756284562143, 13.573037346724874]]

Get geographical center point

berlin = [52.5075419, 13.4251364]
london = [51.5286416, -0.1015987]
rome = [41.9102415, 12.3959161]
Geocalc.geographic_center([berlin, london, rome])
# => [48.810406537400254, 8.785092188535195]

Convert degrees to radians

Geocalc.degrees_to_radians(245)
# => -2.007128639793479

Convert radians to degrees

Geocalc.radians_to_degrees(1.234)
# => 70.70299191914359

Geocalc.Point protocol

Everything which implements Geocalc.Point protocol can be passed as a point argument for any function in this library. We already have implementations for List, Tuple and Map. You can define your own implementations if you need, everything we need to know to do calculations are latitude and longitude.

geocalc's People

Contributors

jeffdeville avatar syamilmj avatar yltsrc avatar

Watchers

 avatar

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.