Created
April 5, 2017 10:29
-
-
Save alexbfree/6fb16758814473a824040c5119bfb0aa to your computer and use it in GitHub Desktop.
script to decode a polyline (monkseaton to south shields) and check for a station (palmersville) on that line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let polyline = require('@mapbox/polyline'); | |
let points = polyline.decode('si}nI~x{G[vAoAu@_ChKs@pDg@jDW~CMtBIrD?tBJzDp@|GVbBv@bEzGbZrFzU~AfHxApGlAxGhAxH|@fIj@vGXtFX|HVnMjBteAZxPE@TfKZ|HdAxMdBdR\\lCt@hDjA~CfBrCfAjBv@~Az@~B`AvCv@~B`GlQ|EtN|CvJzHhUrErNfJpX~AzEjBpEfBtEL^DGtD`LpBbGzAxDx@`Br@fAtEdHp@nA~@`Cz@`Dp@xDRxBPzBj@bEbAzEpBlH`CjK~BzKxEzTbDfOdCbMxCvN~@fEh@|ChAnFxAtFfD~Kr@~Bz@jDdBrHrAxI`AnJd@~HPdFL`KChGSvImAlUwAzWo@bLIfC?fA@fANlE^hDn@lDx@vCbA`CtAzBrAzAn@h@dAj@TJhA\\|CfA`J`DdEpArHfCrFlB`Bl@@IrEvAtCl@xCRnBAlBUpAQhAYjBo@nB_A|ByAtBgBtDeDpDsClCaBtD_BbA_@vBk@~KyBpGsAtFmAx@Gd@Ah@B|B`@|A\\~@p@|@fAzAbCpAdCfBtDbE`LfDhI~@pB|A`Cn@r@^Z|@\\hA@dBOxEw@hGu@f@AjANhBp@vAt@rHpEhI~Er@h@t@`@t@XbANfCZ~@Cn@UbAy@xAuBxBiDnLuQZu@\\eBnHul@FDxI}r@pAmLbAiKj@iDxAoFjFaPp@mCh@wCjB_LpBoMbE_XZwBjAeGz@cEn@yDdAgHQKFa@bCoPt@mGf@oFn@_KZ_I\\gY?oCMoD_@yHOqB{@gUwA}_@c@}Pc@gM]uWOcHIcB[}Bq@cDi@wA}@aB}@eAo@i@_Ac@y@SgAKmBGiBUaEy@{UkE_KiBeJiBsCm@_D_@cGkA}Cy@wB{@oCsAyBmAwCwBgC}BwD_EyBkC_CiDiAgBgAiBaD}FuAuCaBsDm@wAsBuFmAyD_B{Fk@cCgAkFwD_S{DySy@sG]kESeEI{E?mEHkDHkDPkCj@{Fl@}DhA_GbAwD~@sCpDyKr@oC`@qBf@iDv@iIhDub@hBcUrCc^tAwP`AqK^kDn@}Dh@iDh@oDtEgYdNg{@x@mFRmCBsBGwBUgCO}@{@_Dy@eBcBoBaOwKeCgBiBsAo@q@sG{GyCaDyBiB}FwEkEoDwDaD}EqCuAgAeAmAgAgBcBuDq@wAgA_BwAsA}Aq@eASaAC{BEcADgBAgBRsA^oCbAeCRaB@qLLgF^cDJoESyBAyCTwAb@oAj@OHAE'); | |
let palmersville_2_lat = 55.023781; | |
let palmersville_2_lng = -1.541083; | |
let palmersville_1_lat = 55.023728; | |
let palmersville_1_lng = -1.54102; | |
let distance_from_palmersville_p1 = []; | |
let distance_from_palmersville_p2 = []; | |
for (var i = 0; i < points.length; i++) { | |
point = points[i]; | |
let lat = point[0]; | |
let lng = point[1]; | |
distance_from_palmersville_p1[i] = Number(Math.hypot(lat - palmersville_1_lat,lng-palmersville_1_lng)); | |
//console.log('at '+i+' distamce to p1 was '+distance_from_palmersville_p1[i]); | |
distance_from_palmersville_p2[i] = Number(Math.hypot(lat - palmersville_2_lat,lng-palmersville_2_lng)); | |
//console.log('at '+i+' distamce to p2 was '+distance_from_palmersville_p2[i]); | |
if (lat==palmersville_1_lat && lng==palmersville_1_lng) { | |
console.log("found palmersville platform 1 as position no. "+i); | |
} | |
if (lat==palmersville_2_lat && lng==palmersville_2_lng) { | |
console.log("found palmersville platform 2 as position no. "+i); | |
} | |
} | |
let min_dist_from_palmersville_p1 = Math.min(...distance_from_palmersville_p1); | |
console.log('min dist to palmersville p1 was '+min_dist_from_palmersville_p1); | |
let index_of_min_dist_from_palmersville_p1 = distance_from_palmersville_p1.indexOf(min_dist_from_palmersville_p1); | |
let min_dist_from_palmersville_p2 = Math.min(...distance_from_palmersville_p2); | |
console.log('min dist to palmersville p2 was '+min_dist_from_palmersville_p2); | |
let index_of_min_dist_from_palmersville_p2 = distance_from_palmersville_p2.indexOf(min_dist_from_palmersville_p2); | |
console.log('the closest point to palmersville platform 1 was the '+index_of_min_dist_from_palmersville_p1+'th position which is '+points[index_of_min_dist_from_palmersville_p1]); | |
console.log('the closest point to palmersville platform 2 was the '+index_of_min_dist_from_palmersville_p2+'th position which is '+points[index_of_min_dist_from_palmersville_p2]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment