{"id":63,"date":"2021-03-25T12:09:32","date_gmt":"2021-03-25T19:09:32","guid":{"rendered":"https:\/\/www.lunarip.com\/?p=63"},"modified":"2021-03-27T16:16:53","modified_gmt":"2021-03-27T23:16:53","slug":"the-distance-between-2-gps-points-calculation","status":"publish","type":"post","link":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/","title":{"rendered":"Calculating the distance between 2 GPS points"},"content":{"rendered":"\n

With the proliferation of GPS tagging in data sets, a useful calculation to that allows to derive the distance between two points is possible using the Haversine formula. The law of havershines is a more general formula within spherical trigonometry which relates to sides and angles or spherical triangles. On the surface of a sphere the ‘straight line’ connecting two points is actually the arc of a curve on the sphere surface. This curve arc is a arc along a great circle on the sphere and is mathematically called the spherical distance. <\/p>\n\n\n\n

\"\"<\/figure><\/div>\n\n\n\n

In the haversine calculation, the radius of the earth varies around 6356.752 km to 6378.137 km so choosing a value will result in a error that can not be less than 0.5%.<\/p>\n\n\n\n

From wikipedia<\/a>, the calculation is defined as: <\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

so using this formula, the distance of the great circle arc between two points on earths surface in python is:<\/p>\n\n\n\n

from math import asin, cos, radians, sin, sqrt\ndef arclen(lat_a,lon_a,lat_b,lon_b):\n  r = 6370 #note this is for KM distance\n  a1,a2, = (radians(lat_a),radians(lon_a)) \n  b1,b2 = (radians(lat_b),radians(lon_b))\n  delta_lat = b1-a1\n  delta_lon = b2-a2\n  n = abs(sin(delta_lat\/2) **2 \n          + cos(a1)*cos(a2)*(sin(delta_lon\/2) **2))\n  if n >1:\n    n = 1\n  return 2*r*asin(sqrt(n))\n<\/code><\/pre>\n\n\n\n

<\/p>\n\n\n\n

A Jupiter notebook with an more extensive example is available<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"

With the proliferation of GPS tagging in data sets, a useful calculation to that allows to derive the distance between two points is possible using the Haversine formula. The law of havershines is a more general formula within spherical trigonometry which relates to sides and angles or spherical triangles. On the surface of a sphere […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[12,13],"tags":[],"yoast_head":"\nCalculating the distance between 2 GPS points - lunarip<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Calculating the distance between 2 GPS points - lunarip\" \/>\n<meta property=\"og:description\" content=\"With the proliferation of GPS tagging in data sets, a useful calculation to that allows to derive the distance between two points is possible using the Haversine formula. The law of havershines is a more general formula within spherical trigonometry which relates to sides and angles or spherical triangles. On the surface of a sphere […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\" \/>\n<meta property=\"og:site_name\" content=\"lunarip\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-25T19:09:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-27T23:16:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/sphericalTriangle.png\" \/>\n<meta name=\"author\" content=\"kevin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kevin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\"},\"author\":{\"name\":\"kevin\",\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b\"},\"headline\":\"Calculating the distance between 2 GPS points\",\"datePublished\":\"2021-03-25T19:09:32+00:00\",\"dateModified\":\"2021-03-27T23:16:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\"},\"wordCount\":166,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b\"},\"articleSection\":[\"Code\",\"Data Analysis\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\",\"url\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\",\"name\":\"Calculating the distance between 2 GPS points - lunarip\",\"isPartOf\":{\"@id\":\"https:\/\/www.lunarip.com\/#website\"},\"datePublished\":\"2021-03-25T19:09:32+00:00\",\"dateModified\":\"2021-03-27T23:16:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.lunarip.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Calculating the distance between 2 GPS points\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.lunarip.com\/#website\",\"url\":\"https:\/\/www.lunarip.com\/\",\"name\":\"lunarip\",\"description\":\"min(e|d) tailings of a neural net running on a 100w carbon system\",\"publisher\":{\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.lunarip.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b\",\"name\":\"kevin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/Sun_and_Moon_Nuremberg_chroniclex4.png\",\"contentUrl\":\"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/Sun_and_Moon_Nuremberg_chroniclex4.png\",\"width\":970,\"height\":238,\"caption\":\"kevin\"},\"logo\":{\"@id\":\"https:\/\/www.lunarip.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.lunarip.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Calculating the distance between 2 GPS points - lunarip","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/","og_locale":"en_US","og_type":"article","og_title":"Calculating the distance between 2 GPS points - lunarip","og_description":"With the proliferation of GPS tagging in data sets, a useful calculation to that allows to derive the distance between two points is possible using the Haversine formula. The law of havershines is a more general formula within spherical trigonometry which relates to sides and angles or spherical triangles. On the surface of a sphere […]","og_url":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/","og_site_name":"lunarip","article_published_time":"2021-03-25T19:09:32+00:00","article_modified_time":"2021-03-27T23:16:53+00:00","og_image":[{"url":"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/sphericalTriangle.png"}],"author":"kevin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kevin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#article","isPartOf":{"@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/"},"author":{"name":"kevin","@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b"},"headline":"Calculating the distance between 2 GPS points","datePublished":"2021-03-25T19:09:32+00:00","dateModified":"2021-03-27T23:16:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/"},"wordCount":166,"commentCount":0,"publisher":{"@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b"},"articleSection":["Code","Data Analysis"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/","url":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/","name":"Calculating the distance between 2 GPS points - lunarip","isPartOf":{"@id":"https:\/\/www.lunarip.com\/#website"},"datePublished":"2021-03-25T19:09:32+00:00","dateModified":"2021-03-27T23:16:53+00:00","breadcrumb":{"@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.lunarip.com\/index.php\/the-distance-between-2-gps-points-calculation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lunarip.com\/"},{"@type":"ListItem","position":2,"name":"Calculating the distance between 2 GPS points"}]},{"@type":"WebSite","@id":"https:\/\/www.lunarip.com\/#website","url":"https:\/\/www.lunarip.com\/","name":"lunarip","description":"min(e|d) tailings of a neural net running on a 100w carbon system","publisher":{"@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lunarip.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/045a7b3f30cfedf6967672ed5c91bb5b","name":"kevin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/image\/","url":"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/Sun_and_Moon_Nuremberg_chroniclex4.png","contentUrl":"https:\/\/www.lunarip.com\/wp-content\/uploads\/2021\/03\/Sun_and_Moon_Nuremberg_chroniclex4.png","width":970,"height":238,"caption":"kevin"},"logo":{"@id":"https:\/\/www.lunarip.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.lunarip.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":5,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lunarip.com\/index.php\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}