Example #1
0
 /**
  * Instantiate a Utm onject from Lat/Long coordinates or a LatLong object.
  * Returns a new Utm object.
  */
 public static function fromLatLong($latitude, $longitude = null)
 {
     // Accept various inputs.
     if (!isset($longitude)) {
         // One parameter only supplied. If this is not already a LatLong object,
         // then convert it into one.
         if (!is_a($latitude, 'Academe\\Proj4Php\\Mgrs\\LatLongInterface')) {
             // If some form of array, then let LatLong work out how to interpret it.
             $latitude = new LatLong($latitude);
         }
         $lat = $latitude->getLatitude();
         $long = $latitude->getLongitude();
     } else {
         // Coordinates supplied as separate values.
         $lat = $latitude;
         $long = $longitude;
     }
     // TODO: validate lat and long ranges, assuming they have been set, and throw exception if necessary.
     // lat: -180 to +180; long: -90 to +90
     /*
     if (...) {
         // Exception here.
         throw new \InvalidArgumentException(
             'error...'
         );
     );
     */
     // Convert to radians.
     $lat_rad = deg2rad($lat);
     $long_rad = deg2rad($long);
     // Calculate the zone number.
     $zone_number = static::calcZoneNumber($lat, $long);
     // +3 puts origin in middle of zone
     $long_origin = ($zone_number - 1) * 6 - 180 + 3;
     $long_origin_rad = deg2rad($long_origin);
     $ecc_prime_squared = static::$ecc_squared / (1 - static::$ecc_squared);
     $N = static::$a / sqrt(1 - static::$ecc_squared * pow(sin($lat_rad), 2));
     $T = pow(tan($lat_rad), 2);
     $C = $ecc_prime_squared * pow(cos($lat_rad), 2);
     $A = cos($lat_rad) * ($long_rad - $long_origin_rad);
     $M = static::$a * ((1 - static::$ecc_squared / 4 - 3 * pow(static::$ecc_squared, 2) / 64 - 5 * pow(static::$ecc_squared, 3) / 256) * $lat_rad - (3 * static::$ecc_squared / 8 + 3 * pow(static::$ecc_squared, 2) / 32 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(2 * $lat_rad) + (15 * pow(static::$ecc_squared, 2) / 256 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(4 * $lat_rad) - 35 * pow(static::$ecc_squared, 3) / 3072 * sin(6 * $lat_rad));
     $utm_easting = static::$k0 * $N * ($A + (1 - $T + $C) * pow($A, 3) / 6.0 + (5 - 18 * pow($T, 3) + 72 * $C - 58 * $ecc_prime_squared) * pow($A, 5) / 120.0) + 500000.0;
     $utm_northing = static::$k0 * ($M + $N * tan($lat_rad) * ($A * $A / 2 + (5 - $T + 9 * $C + 4 * pow($C, 2)) * pow($A, 4) / 24.0 + (61 - 58 * pow($T, 3) + 600 * $C - 330 * $ecc_prime_squared) * pow($A, 6) / 720.0));
     if ($lat < 0.0) {
         // 10,000,000 meter offset for southern hemisphere
         $utm_northing += 10000000.0;
     }
     $northing = round($utm_northing);
     $easting = round($utm_easting);
     $zone_number = $zone_number;
     $zone_letter = static::calcLetterDesignator($lat);
     // Return a new object instatiation.
     return new static($northing, $easting, $zone_number, $zone_letter);
 }
Example #2
0
 public function testGetDestination()
 {
     $latLongObject = new LatLong($this->_xyz);
     $position = $latLongObject->getDestination($this->_angle, $this->_distance);
     $this->assertTrue(is_object($position));
     $this->assertTrue(is_a($position, 'Geodetic\\LatLong'));
 }
Example #3
0
require '../controller/dbsettings.php';
$db = 'data-geo-people';
$sql = "SELECT * FROM `{$db}` WHERE lat='0' ORDER BY RAND() LIMIT 10 ";
echo $sql;
$result = $conn->query($sql);
if ($result) {
    while ($row = $result->fetch_assoc()) {
        $id = $row["id"];
        /*  $city = $row["city"];
        
            $country = $row["country"];
        */
        //now for products
        /*
        $citycountry = $row["city"];
        $splits=explode(',',$citycountry);
        $city=$splits[0];
        $country=$splits[1];
        */
        //now for places
        $city = "";
        //$row["place"];
        $country = $row["city"];
        $latLong = LatLong::findLatLong($city, $country);
        //echo $city.$latLong->lat . "<br>";
        $sql2 = "UPDATE `{$db}` SET lat='" . $latLong->lat . "' , longg='" . $latLong->longg . "' WHERE id='" . $id . "'";
        echo $sql2;
        $result2 = $conn->query($sql2);
    }
}
header('Refresh: 5; URL=updateLatLong.php');
Example #4
0
 /**
  * Get the midpoint for a great circle route between two Latitude/Longitude objects
  *
  * @param     LatLong    $endPoint    The destination point
  * @return    LatLong    The midpoint Lat/Long between this Lat/Long and the $endpoint Lat/Long
  * @throws    Exception
  */
 public function getMidpoint(LatLong $endPoint)
 {
     $deltaLongitude = $endPoint->getLongitude()->getValue(Angle::RADIANS) - $this->longitude->getValue(Angle::RADIANS);
     $xModified = cos($endPoint->getLatitude()->getValue(Angle::RADIANS)) * cos($deltaLongitude);
     $yModified = cos($endPoint->getLatitude()->getValue(Angle::RADIANS)) * sin($deltaLongitude);
     $midpointLatitude = atan2(sin($this->latitude->getValue(Angle::RADIANS)) + sin($endPoint->getLatitude()->getValue(Angle::RADIANS)), sqrt((cos($this->latitude->getValue(Angle::RADIANS)) + $xModified) * (cos($this->latitude->getValue(Angle::RADIANS)) + $xModified) + $yModified * $yModified));
     $midpointLongitude = $this->longitude->getValue(Angle::RADIANS) + atan2($yModified, cos($this->latitude->getValue(Angle::RADIANS)) + $xModified);
     return new LatLong(new LatLong\CoordinateValues(self::cleanLatitude($midpointLatitude), self::cleanLongitude($midpointLongitude), Angle::RADIANS));
 }
Example #5
0
if ($long == "") {
    $long = 0;
}
$color = User::getColor();
//die ($color);
if ($_SESSION["user_id"] == 0) {
    die("Sorry this shouldnt happen - tell me about it...");
}
$correct = Answer::loadCorrect($questionNumber);
//place currently is true or false if they could submit (meaning 1st time)
//die ($questionNumber);
//echo $sql;
//die();
$game = Game::findGame();
if ($game->type == "geo" || $game->type == "places" || $game->type == "pt") {
    $distanceAway = LatLong::findDistance($correct->location, new LatLong($lat, $long));
} else {
    $distanceAway = abs($answer - $correct->value);
}
if ($answer > 100000) {
    $distanceAway = round($distanceAway, -5);
}
//die ($questionNumber);
$questionNumberSite = $game->round;
//if ($questionNumberSite!=$questionNumber)
if ($questionNumberSite < 0) {
    header('Location: waitingScreen.php?message=' . "Submit your answer in time");
}
$place = Answer::addAnswer($_SESSION["user_id"], $questionNumber, $lat, $long, $answer, $distanceAway, $color, $game->type);
//NOW WE FIND THE OVERALL PERCENT PLACE THAT PERCENT DID ON THAT question_id
//Answer::findPercentPlace()
Example #6
0
 $lat1 = $row["lat"];
 $long1 = $row["longg"];
 $color = $row["color"];
 $ans = $row["answer"];
 $game_id = $row["game_id"];
 $questionNum = $row["questionNum"];
 $loc = new LatLong($lat1, $long1);
 $points = $row["points"];
 //echo $questionNum;
 $qID = findQID($game_id, $questionNum);
 if ($ans == -999) {
     //meaning they didnt submit
     $distanceAway = null;
 } else {
     if ($qID->type == "geo") {
         $distanceAway = LatLong::findDistance($qID->location, $loc);
     } else {
         $distanceAway = abs($ans - $qID->answer);
     }
 }
 if ($ans > 100000) {
     $distanceAway = round($distanceAway, -5);
 }
 //echo $qID->type." ".$qID->answer. " ". $distanceAway."<br>";
 if ($distanceAway != "") {
     $sql2 = "UPDATE `answers` SET question_id='" . $qID->type . $qID->id . "', distanceAway='" . $distanceAway . "' WHERE game_id='" . $game_id . "' AND questionNum='" . $questionNum . "' AND color='" . $color . "'";
 } else {
     $sql2 = "UPDATE `answers` SET question_id='" . $qID->type . $qID->id . "' WHERE game_id='" . $game_id . "' AND questionNum='" . $questionNum . "' AND color='" . $color . "'";
 }
 echo $sql2;
 $result2 = $conn->query($sql2);
 /**
  * Get the Radius of Curvature along the Prime Vertical at a specified latitude
  * for this Reference Ellipsoid object
  *
  * The formula used here is from http://www.epsg.org/guides/docs/G7-2.pdf
  *
  * @param     integer|float    $latitude    Angle of Latitude for the Radius of Curvature,
  *                                              positive when to the north of the equator, negative when to the south
  * @param     string           $degrad      Indicating whether the Angle of Latitude is being specified
  *                                              in degrees or radians
  * @param     string           $uom         Unit of Measure for the returned value
  * @return    float            The Radius of Curvature along the Prime Vertical at the specified latitude
  *                                 for this ellipsoid
  * @throws    Exception
  */
 public function getRadiusOfCurvaturePrimeVertical($latitude = null, $degrad = Angle::DEGREES, $uom = Distance::METRES)
 {
     $latitude = LatLong::validateLatitude($latitude, $degrad);
     if ($this->dirty) {
         $this->calculateDerivedParameters();
     }
     $radius = $this->semiMajorAxis->getValue() / pow(1 - $this->firstEccentricitySquared * self::sinSquared($latitude), 0.5);
     return Distance::convertFromMeters($radius, $uom);
 }
Example #8
0
 public static function findDistance($loc1, $loc2)
 {
     return LatLong::distance($loc1->lat, $loc1->longg, $loc2->lat, $loc2->longg, "M");
 }
Example #9
0
 /**
  * Identify whether a specified Latitude/Longitude falls within the bounds of this region
  *
  * @param     LatLong    The Latitude/Longitude object that we wish to test
  * @return    boolean
  */
 public function isInRegion(LatLong $position)
 {
     $latitude = $position->getLatitude()->getValue();
     $longitude = $position->getLongitude()->getValue();
     $perimeterNodeCount = count($this->nodePoints);
     $jIndex = $perimeterNodeCount - 1;
     $oddNodes = false;
     for ($iIndex = 0; $iIndex < $perimeterNodeCount; ++$iIndex) {
         $iLatitude = $this->nodePoints[$iIndex]->getLatitude()->getValue();
         $jLatitude = $this->nodePoints[$jIndex]->getLatitude()->getValue();
         if ($iLatitude < $latitude && $jLatitude >= $latitude || $jLatitude < $latitude && $iLatitude >= $latitude) {
             $iLongitude = $this->nodePoints[$iIndex]->getLongitude()->getValue();
             $jLongitude = $this->nodePoints[$jIndex]->getLongitude()->getValue();
             if ($iLongitude + ($latitude - $iLatitude) / ($jLatitude - $iLatitude) * ($jLongitude - $iLongitude) < $longitude) {
                 $oddNodes = !$oddNodes;
             }
         }
         $jIndex = $iIndex;
     }
     return $oddNodes;
 }
Example #10
0
 public static function addUser($qID, $loc, $ans, $userID, $correct, $points, $color)
 {
     $answer = new self();
     $answer->user_id = $userID;
     $answer->location = $loc;
     $answer->ans = $ans;
     $answer->qID = $qID;
     $answer->color = $color;
     if ($ans == -999) {
         //meaning they didnt submit
         $answer->distanceAway = -999.99;
     } else {
         if (!is_object($correct)) {
             //meaning end of game
             $answer->distanceAway = -999.99;
         } else {
             if (Game::findGame()->type == "geo" || Game::findGame()->type == "pt" || Game::findGame()->type == "places") {
                 $answer->distanceAway = LatLong::findDistance($correct->location, $loc);
             } else {
                 $answer->distanceAway = abs($ans - $correct->value);
             }
         }
     }
     if ($ans > 100000) {
         $answer->distanceAway = round($answer->distanceAway, -5);
     }
     $answer->getUserInfo();
     $answer->updateUser();
     $answer->roundPoints = $points;
     return $answer;
 }