示例#1
0
 public function testRelativePoint()
 {
     $newPoint = $this->point->getRelativePoint(2.783, 98.50833, 'km');
     $this->assertEquals(53.48204, round($newPoint->lat, 5));
     $this->assertEquals(-2.23194, round($newPoint->lon, 5));
 }
示例#2
0
 /**
  * @param Point $point the centre of the bounding box
  * @param number $radius minimum radius from $point
  * @param string $unit unit of the radius (default is kilometres)
  *
  * @return Polygon the BBox
  */
 public static function getBBoxByRadius(Point $point, $radius, $unit = 'km')
 {
     $north = $point->getRelativePoint($radius, 0, $unit);
     $south = $point->getRelativePoint($radius, 180, $unit);
     $limits['n'] = $north->getLatitude();
     $limits['s'] = $south->getLatitude();
     $radDist = $radius / Location::getEllipsoid()->radius($unit);
     //   $minLat  = deg2rad( $limits['s'] );
     //   $maxLat  = deg2rad( $limits['n'] );
     $radLon = $point->longitudeToRad();
     //if ($minLat > deg2rad(-90) && $maxLat < deg2rad(90)) {
     $deltaLon = asin(sin($radDist) / cos($point->latitudeToRad()));
     $minLon = $radLon - $deltaLon;
     if ($minLon < deg2rad(-180)) {
         $minLon += 2 * pi();
     }
     $maxLon = $radLon + $deltaLon;
     if ($maxLon > deg2rad(180)) {
         $maxLon -= 2 * pi();
     }
     //}
     $limits['w'] = rad2deg($minLon);
     $limits['e'] = rad2deg($maxLon);
     $nw = new Point($limits['n'], $limits['w']);
     $ne = new Point($limits['n'], $limits['e']);
     $sw = new Point($limits['s'], $limits['w']);
     $se = new Point($limits['s'], $limits['e']);
     $polygon = new Polygon([[$nw, $ne, $se, $sw]]);
     return $polygon;
 }