<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270977#M81572</link>
    <description>&lt;P&gt;Here's a handy macro I just created base on this answer. I used the multiplier for miles instead of km. Define as haversine(4), takes args lat1,lon1,lat2,lon2 and creates a "miles" field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval rlat1 = pi()*$lat1$/180, rlat2=pi()*$lat2$/180, rlat = pi()*($lat2$-$lat1$)/180, rlon = pi()*($lon2$-$lon1$)/180 
| eval a = sin(rlat/2) * sin(rlat/2) + cos(rlat1) * cos(rlat2) * sin(rlon/2) * sin(rlon/2) 
| eval c = 2 * atan2(sqrt(a), sqrt(1-a)) 
| eval miles = 3963 * c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here it is included in the use case that brought me here.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=oktaim2:log
| streamstats global=f window=2 current=t earliest(client.geographicalContext.geolocation.lon) AS lon1 latest(client.geographicalContext.geolocation.lon) AS lon2 earliest(client.geographicalContext.geolocation.lat) AS lat1 latest(client.geographicalContext.geolocation.lat) AS lat2 earliest(client.geographicalContext.city) AS src_city latest(client.geographicalContext.city) AS dest_city earliest(client.geographicalContext.state) AS src_state latest(client.geographicalContext.state) AS dest_state earliest(_time) AS departed_time latest(_time) AS arrived_time BY user 
| where lat1!=lat2 AND lon1!=lon2 
| `haversine(lat1,lon1,lat2,lon2)` 
| eval hours=(arrived_time-departed_time)/60/60 
| eval avg_mph=miles/hours 
| where avg_mph&amp;gt;500 AND miles&amp;gt;100 
| eval src_locale=src_city . ", " . src_state, dest_locale=dest_city . ", " . dest_state 
| table _time lat1 lon1 lat2 lon2 src_locale dest_locale miles hours avg_mph user 
| sort _time desc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Jun 2019 20:37:01 GMT</pubDate>
    <dc:creator>jspears</dc:creator>
    <dc:date>2019-06-28T20:37:01Z</dc:date>
    <item>
      <title>Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270973#M81568</link>
      <description>&lt;P&gt;I need  tocalculate distances between points with GEOIP using latitude and longitude directly in a search with trigonometric functions, Can I use these functions in Splunk 6.1.5?&lt;/P&gt;

&lt;P&gt;Example: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval cal_a = (sen_lati * sen_lati) + cos(GEO_1_LAT_NUM) * cos(GEO_2_LAT_NUM) * (sen_long* sen_long)
| eval cal_c = 2 * (atan2(sqrt(cal_a),sqrt(1-(cal_a)))) 
| eval distancia = round(cal_c * r_tierra)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Greetings!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 13:05:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270973#M81568</guid>
      <dc:creator>gonzalovasquez</dc:creator>
      <dc:date>2015-10-13T13:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270974#M81569</link>
      <description>&lt;P&gt;You can use following app to calculate distance between two points&lt;/P&gt;

&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/936/#/documentation"&gt;https://splunkbase.splunk.com/app/936/#/documentation&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For an alternate solution, see the answers from @Sideview from this post&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/90694/find-the-distance-between-two-or-more-geolocation-coordinates.html"&gt;https://answers.splunk.com/answers/90694/find-the-distance-between-two-or-more-geolocation-coordinates.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 16:06:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270974#M81569</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-10-13T16:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270975#M81570</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;fast forward into the future, we can do the &lt;EM&gt;great circle formula&lt;/EM&gt; in Splunk now. &lt;BR /&gt;
This example will provide the expected result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval lat1=1, lon1=1, lat2=2, lon2=2 
| eval rlat1 = pi()*lat1/180, rlat2=pi()*lat2/180, rlat = pi()*(lat2-lat1)/180, rlon= pi()*(lon2-lon1)/180
| eval a = sin(rlat/2) * sin(rlat/2) + cos(rlat1) * cos(rlat2) * sin(rlon/2) * sin(rlon/2) 
| eval c = 2 * atan2(sqrt(a), sqrt(1-a)) 
| eval distance = 6371 * c
| table lat1 lon1 lat2 lon2 distance
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;distance&lt;/CODE&gt; will be the distance in &lt;CODE&gt;km&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 21:14:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270975#M81570</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2017-09-04T21:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270976#M81571</link>
      <description>&lt;P&gt;Thanks a lot for this, it worked fine for me! &lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 20:38:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270976#M81571</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-09T20:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating distances between points with GEOIP using latitude and longitude, can I use Trigonometric functions directly in a search in Splunk 6.1.5</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270977#M81572</link>
      <description>&lt;P&gt;Here's a handy macro I just created base on this answer. I used the multiplier for miles instead of km. Define as haversine(4), takes args lat1,lon1,lat2,lon2 and creates a "miles" field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval rlat1 = pi()*$lat1$/180, rlat2=pi()*$lat2$/180, rlat = pi()*($lat2$-$lat1$)/180, rlon = pi()*($lon2$-$lon1$)/180 
| eval a = sin(rlat/2) * sin(rlat/2) + cos(rlat1) * cos(rlat2) * sin(rlon/2) * sin(rlon/2) 
| eval c = 2 * atan2(sqrt(a), sqrt(1-a)) 
| eval miles = 3963 * c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here it is included in the use case that brought me here.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=oktaim2:log
| streamstats global=f window=2 current=t earliest(client.geographicalContext.geolocation.lon) AS lon1 latest(client.geographicalContext.geolocation.lon) AS lon2 earliest(client.geographicalContext.geolocation.lat) AS lat1 latest(client.geographicalContext.geolocation.lat) AS lat2 earliest(client.geographicalContext.city) AS src_city latest(client.geographicalContext.city) AS dest_city earliest(client.geographicalContext.state) AS src_state latest(client.geographicalContext.state) AS dest_state earliest(_time) AS departed_time latest(_time) AS arrived_time BY user 
| where lat1!=lat2 AND lon1!=lon2 
| `haversine(lat1,lon1,lat2,lon2)` 
| eval hours=(arrived_time-departed_time)/60/60 
| eval avg_mph=miles/hours 
| where avg_mph&amp;gt;500 AND miles&amp;gt;100 
| eval src_locale=src_city . ", " . src_state, dest_locale=dest_city . ", " . dest_state 
| table _time lat1 lon1 lat2 lon2 src_locale dest_locale miles hours avg_mph user 
| sort _time desc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 20:37:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-distances-between-points-with-GEOIP-using-latitude/m-p/270977#M81572</guid>
      <dc:creator>jspears</dc:creator>
      <dc:date>2019-06-28T20:37:01Z</dc:date>
    </item>
  </channel>
</rss>

