无法找到scala
代码以查找距特定坐标41.7523,12.8629
1英里远的坐标列表。
如何在给定坐标(火花标量)上进行地理围栏
答案 0 :(得分:0)
使用此功能,我们可以在nearby point randomly
中获得一个one mile radius
:
def getPoints(xc:Double,yc:Double,radiusInMiles:Int)={
val ran = new scala.util.Random()
val conv = 1609.344
//Here, there are about 111,300 meters in a degree
val radiusIndeg = radiusInMiles*conv / 111300f;
val u = ran.nextDouble()
val v = ran.nextDouble()
val w = radiusIndeg*Math.sqrt(u)
val t = 2*Math.PI*v
val x = w*Math.cos(t)
val y = w*Math.sin(t)
val newX = x/Math.cos(Math.toRadians(yc))
val fLong = newX+xc
val fLat = y+yc
(fLong,fLat)
}
通过在for循环中反复调用上述函数,我们可以在1英里内获得所需数量的随机点:
for(i<-1 to 30) yield getPoints(41.7523,12.8629,1)
要随机获取30个附近的点,
In Scala REPL:
scala> for(i<-1 to 30) yield getPoints(41.7523,12.8629,1)
res25: scala.collection.immutable.IndexedSeq[(Double, Double)] = Vector((41.74982541032955,12.86481315224305), (41.754168266
959056,12.870364411375881), (41.75544877222746,12.85451037482713), (41.7612335738966,12.856539452781801), (41.76358834447362
,12.861061408964183), (41.763040037484664,12.867369860689339), (41.75110057115767,12.873299266989251), (41.74658541773817,12
.865223104625423), (41.74925109768552,12.868277572490877), (41.76504777008776,12.86109583406441), (41.75732730141462,12.8722
5307703036), (41.75762735062798,12.860633801016085), (41.75003276741254,12.856383089176347), (41.760707286583,12.85341268512
5267), (41.748073299368386,12.858209316913472), (41.76018412949083,12.866118423321987), (41.74213603200559,12.87308644848186
), (41.761324688000265,12.86506896052553), (41.749976...
scala> res25.foreach(println)
(41.74982541032955,12.86481315224305)
(41.754168266959056,12.870364411375881)
(41.75544877222746,12.85451037482713)
(41.7612335738966,12.856539452781801)
(41.76358834447362,12.861061408964183)
(41.763040037484664,12.867369860689339)
(41.75110057115767,12.873299266989251)
(41.74658541773817,12.865223104625423)
(41.74925109768552,12.868277572490877)
(41.76504777008776,12.86109583406441)
(41.75732730141462,12.87225307703036)
(41.75762735062798,12.860633801016085)
(41.75003276741254,12.856383089176347)
(41.760707286583,12.853412685125267)
(41.748073299368386,12.858209316913472)
(41.76018412949083,12.866118423321987)
(41.74213603200559,12.87308644848186)
(41.761324688000265,12.86506896052553)
(41.74997668526327,12.86038167090363)
(41.75228048449065,12.872686927175733)
(41.75972428137232,12.859596070561539)
(41.7562836928502,12.86187286720154)
(41.75715996439461,12.861374766455278)
(41.760604332388,12.867977103427238)
(41.74018421174905,12.865172431590485)
(41.74059829855585,12.86438943748021)
(41.7593627526156,12.873744103200057)
(41.747241804657264,12.8542871167178)
(41.76014663643563,12.858456116302811)
(41.740826160697715,12.867433800624394)
scala>