{
  "id": 5467,
  "title": "R macro to visualize test flights (and great circle paths)",
  "url": "/competitions/flight2-milestone/discussion/5467",
  "author_name": "",
  "post_date": "2013-08-20T15:47:43.123Z",
  "votes": 2,
  "comment_count": 1,
  "views": 1316,
  "content": "<p>Below R-macro draws planes&nbsp;corresponding to test flights and all airports. It also draw&nbsp;s great circle path from current plane location to target airport. <br>Remark: currently it draws just first 50 test flights. Change parameter&nbsp;flightsToDraw if/when needed:</p>\n<p><code># R-macro to plot planes and (all) airports corresponding to <br># test flights. Draws great circle path from current plane <br># location to&nbsp;target airport.<br></code><code><br>#</code><code> Required libraries<br>library(maps) <br>library(geosphere)</code></p>\n<p><code># Load in data sets<br>setwd(&quot;d:\\\\kaggle\\\\ge&quot;)<br>airports &lt;- read.csv(&quot;airports.csv&quot;, header=TRUE)<br>testFlights &lt;- read.csv(&quot;testFlights.csv&quot;, header=TRUE)</code></p>\n<p><code># Calculate bounding box for test flights' longitudes <br></code><code># and latitudes<br>xlim &lt;- c(min(testFlights$CurrentLongitude),max(testFlights$CurrentLongitude))<br>ylim &lt;- c(min(testFlights$CurrentLatitude),max(testFlights$CurrentLatitude))</code></p>\n<p><code># Draw map using the bounding box<br>map(&quot;world&quot;, col=&quot;#ffffff&quot;, fill=TRUE, bg=&quot;white&quot;, lwd=0.05, xlim=xlim, ylim=ylim)</code></p>\n<p><code># Plot desired number of test flights<br>flightsToDraw &lt;- 50 # max value is nrow(testFlights) <br># </code><code>but drawing becomes too messy<br><br></code><code>for(i in 1:flightsToDraw){<br>&nbsp; targetLongitude &lt;- airports$longitude_degrees[airports$airport_icao_code==testFlights$ArrivalAirport[i]]<br>&nbsp; targetLatitude &lt;- airports$latitude_degrees[airports$airport_icao_code==testFlights$ArrivalAirport[i]]<br><br>&nbsp;</code><code>inter &lt;- gcIntermediate(c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]), <br>&nbsp; c(targetLongitude, targetLatitude), n=50,&nbsp; addStartEnd=TRUE) <br>&nbsp; lines(inter,lty=2, col=&quot;#CC0000&quot;) <br>}</code></p>\n<p><code># Plot planes <br>for(i in 1:flightsToDraw){<br>&nbsp; inter &lt;- gcIntermediate(c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]),<br> c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]), n=1, addStartEnd=TRUE) <br>&nbsp; lines(inter, col=&quot;#0000FF&quot;,lwd=5) <br>}</code></p>\n<p><code># Plot target airports<br>for(i in 1:nrow(airports)){<br>&nbsp; inter &lt;- gcIntermediate(c(airports$longitude_degrees[i],airports$latitude_degrees[i]),<br> c(airports$longitude_degrees[i],airports$latitude_degrees[i]), n=1,addStartEnd=TRUE) <br>&nbsp; lines(inter, col=&quot;#00FF00&quot;,lwd=5) <br>}</code></p>\n<p><code># Plot legend<br>legend(xlim[1] + (xlim[2]-xlim[1])*0.75,ylim[1] + (ylim[2]-ylim[1])*0.9, <br>&nbsp; legend=c(&quot;Plane&quot;,&quot;Target airport&quot;),text.col=c(&quot;#0000FF&quot;, &quot;#00FF00&quot;),ncol=1)</code></p>",
  "messages": [
    {
      "id": "29065",
      "postDate": "08/20/2013 15:47:43",
      "content": "<p>Below R-macro draws planes&nbsp;corresponding to test flights and all airports. It also draw&nbsp;s great circle path from current plane location to target airport. <br>Remark: currently it draws just first 50 test flights. Change parameter&nbsp;flightsToDraw if/when needed:</p>\n<p><code># R-macro to plot planes and (all) airports corresponding to <br># test flights. Draws great circle path from current plane <br># location to&nbsp;target airport.<br></code><code><br>#</code><code> Required libraries<br>library(maps) <br>library(geosphere)</code></p>\n<p><code># Load in data sets<br>setwd(&quot;d:\\\\kaggle\\\\ge&quot;)<br>airports &lt;- read.csv(&quot;airports.csv&quot;, header=TRUE)<br>testFlights &lt;- read.csv(&quot;testFlights.csv&quot;, header=TRUE)</code></p>\n<p><code># Calculate bounding box for test flights' longitudes <br></code><code># and latitudes<br>xlim &lt;- c(min(testFlights$CurrentLongitude),max(testFlights$CurrentLongitude))<br>ylim &lt;- c(min(testFlights$CurrentLatitude),max(testFlights$CurrentLatitude))</code></p>\n<p><code># Draw map using the bounding box<br>map(&quot;world&quot;, col=&quot;#ffffff&quot;, fill=TRUE, bg=&quot;white&quot;, lwd=0.05, xlim=xlim, ylim=ylim)</code></p>\n<p><code># Plot desired number of test flights<br>flightsToDraw &lt;- 50 # max value is nrow(testFlights) <br># </code><code>but drawing becomes too messy<br><br></code><code>for(i in 1:flightsToDraw){<br>&nbsp; targetLongitude &lt;- airports$longitude_degrees[airports$airport_icao_code==testFlights$ArrivalAirport[i]]<br>&nbsp; targetLatitude &lt;- airports$latitude_degrees[airports$airport_icao_code==testFlights$ArrivalAirport[i]]<br><br>&nbsp;</code><code>inter &lt;- gcIntermediate(c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]), <br>&nbsp; c(targetLongitude, targetLatitude), n=50,&nbsp; addStartEnd=TRUE) <br>&nbsp; lines(inter,lty=2, col=&quot;#CC0000&quot;) <br>}</code></p>\n<p><code># Plot planes <br>for(i in 1:flightsToDraw){<br>&nbsp; inter &lt;- gcIntermediate(c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]),<br> c(testFlights$CurrentLongitude[i],testFlights$CurrentLatitude[i]), n=1, addStartEnd=TRUE) <br>&nbsp; lines(inter, col=&quot;#0000FF&quot;,lwd=5) <br>}</code></p>\n<p><code># Plot target airports<br>for(i in 1:nrow(airports)){<br>&nbsp; inter &lt;- gcIntermediate(c(airports$longitude_degrees[i],airports$latitude_degrees[i]),<br> c(airports$longitude_degrees[i],airports$latitude_degrees[i]), n=1,addStartEnd=TRUE) <br>&nbsp; lines(inter, col=&quot;#00FF00&quot;,lwd=5) <br>}</code></p>\n<p><code># Plot legend<br>legend(xlim[1] + (xlim[2]-xlim[1])*0.75,ylim[1] + (ylim[2]-ylim[1])*0.9, <br>&nbsp; legend=c(&quot;Plane&quot;,&quot;Target airport&quot;),text.col=c(&quot;#0000FF&quot;, &quot;#00FF00&quot;),ncol=1)</code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29068",
      "postDate": "08/20/2013 16:35:14",
      "content": "<p>I have not checked if licenses of packages&nbsp;maps or geosphere are according to the competition rules (5 allowed&nbsp;licenses) - my guess is that they are not. So prepare to program (mostly gcIntermediate function) by&nbsp;yourself in case if you use above functionality&nbsp;as part of path estimations in your competition submissions.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 29068,
      "author_name": "sfin2015",
      "author_url": "",
      "post_date": "08/20/2013 16:35:14",
      "content": "<p>I have not checked if licenses of packages&nbsp;maps or geosphere are according to the competition rules (5 allowed&nbsp;licenses) - my guess is that they are not. So prepare to program (mostly gcIntermediate function) by&nbsp;yourself in case if you use above functionality&nbsp;as part of path estimations in your competition submissions.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "29065": "",
    "29068": ""
  },
  "source": "meta"
}