示例#1
0
 /**
  * Get the bearing from this Point to another.
  *
  * @param Point $point2
  *
  * @return float bearing
  */
 public function initialBearingTo(Point $point2)
 {
     if (function_exists('initial_bearing') && Location::$useSpatialExtension) {
         return initial_bearing($this->jsonSerialize(), $point2->jsonSerialize());
     } else {
         $y = sin(deg2rad($point2->getLongitude() - $this->getLongitude())) * cos($point2->latitudeToRad());
         $x = cos($this->latitudeToRad()) * sin($point2->latitudeToRad()) - sin($this->latitudeToRad()) * cos($point2->latitudeToRad()) * cos(deg2rad($point2->getLongitude() - $this->getLongitude()));
         $result = atan2($y, $x);
         return fmod(rad2deg($result) + 360, 360);
     }
 }
示例#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;
 }