示例#1
0
 public function testLatLngSouthernHemisphere()
 {
     $UTMRef = new UTMRef(334786, 6252080, 0, 'H', 56);
     $LatLng = $UTMRef->toLatLng();
     $expected = "(-33.85798, 151.21404)";
     self::assertEquals($expected, $LatLng->__toString());
 }
echo "Six figure string: " . $os6 . "<br />";
$os6x = getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();
?>
    </p>

    <h2>Convert UTM Reference to Latitude/Longitude</h2>

    <p>
      <pre>$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "&lt;br /&gt;";
$ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();</pre>

      <?php 
$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "<br />";
$ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();
?>
    </p>

    <h2>Convert Latitude/Longitude to UTM Reference</h2>

    <p>
      <pre>$ll4 = new LatLng(-60.1167, -111.7833);
echo "Latitude/Longitude: " . $ll4->toString() . "&lt;br /&gt;";
$utm2 = $ll4->toUTMRef();
echo "Converted to UTM Ref: " . $utm2->toString() ;</pre>

      <?php 
示例#3
0
 /**
  * Convert a WGS84 latitude and longitude to an UTM reference
  *
  * Reference values for transformation are taken from OS document
  * "A Guide to Coordinate Systems in Great Britain"
  * @return UTMRef
  */
 public function toUTMRef()
 {
     $this->toWGS84();
     $longitudeZone = (int) (($this->lng + 180) / 6) + 1;
     // Special zone for Norway
     if ($this->lat >= 56 && $this->lat < 64 && $this->lng >= 3 && $this->lng < 12) {
         $longitudeZone = 32;
     } elseif ($this->lat >= 72 && $this->lat < 84) {
         // Special zones for Svalbard
         if ($this->lng >= 0 && $this->lng < 9) {
             $longitudeZone = 31;
         } elseif ($this->lng >= 9 && $this->lng < 21) {
             $longitudeZone = 33;
         } elseif ($this->lng >= 21 && $this->lng < 33) {
             $longitudeZone = 35;
         } elseif ($this->lng >= 33 && $this->lng < 42) {
             $longitudeZone = 37;
         }
     }
     $UTMZone = $this->getUTMLatitudeZoneLetter($this->lat);
     $UTM = new UTMRef(0, 0, 0, $UTMZone, $longitudeZone);
     //dummy to get reference data
     $scale = $UTM->getScaleFactor();
     $N0 = $UTM->getOriginNorthing();
     $E0 = $UTM->getOriginEasting();
     $phi0 = $UTM->getOriginLatitude();
     $lambda0 = $UTM->getOriginLongitude();
     $coords = $this->toTransverseMercatorEastingNorthing($scale, $E0, $N0, $phi0, $lambda0);
     if ($this->lat < 0) {
         $coords['N'] += 10000000;
     }
     return new UTMRef(round($coords['E']), round($coords['N']), $this->h, $UTMZone, $longitudeZone);
 }
示例#4
0
 /**
  * Convert a WGS84 latitude and longitude to an UTM reference
  *
  * Reference values for transformation are taken from OS document
  * "A Guide to Coordinate Systems in Great Britain"
  * @return UTMRef
  */
 public function toUTMRef()
 {
     if ($this->refEll != RefEll::WGS84()) {
         trigger_error('Current co-ordinates are in a non-WGS84 datum', E_USER_WARNING);
     }
     $longitudeZone = (int) (($this->lng + 180) / 6) + 1;
     // Special zone for Norway
     if ($this->lat >= 56 && $this->lat < 64 && $this->lng >= 3 && $this->lng < 12) {
         $longitudeZone = 32;
     }
     // Special zones for Svalbard
     if ($this->lat >= 72 && $this->lat < 84) {
         if ($this->lng >= 0 && $this->lng < 9) {
             $longitudeZone = 31;
         } else {
             if ($this->lng >= 9 && $this->lng < 21) {
                 $longitudeZone = 33;
             } else {
                 if ($this->lng >= 21 && $this->lng < 33) {
                     $longitudeZone = 35;
                 } else {
                     if ($this->lng >= 33 && $this->lng < 42) {
                         $longitudeZone = 37;
                     }
                 }
             }
         }
     }
     $UTMZone = $this->getUTMLatitudeZoneLetter($this->lat);
     $UTM = new UTMRef(0, 0, $UTMZone, $longitudeZone);
     //dummy to get reference data
     $scale = $UTM->getScaleFactor();
     $N0 = $UTM->getOriginNorthing();
     $E0 = $UTM->getOriginEasting();
     $phi0 = $UTM->getOriginLatitude();
     $lambda0 = $UTM->getOriginLongitude();
     $coords = $this->toTransverseMercatorEastingNorthing($scale, $E0, $N0, $phi0, $lambda0);
     if ($this->lat < 0) {
         $coords['N'] += 10000000;
     }
     return new UTMRef($coords['E'], $coords['N'], $UTMZone, $longitudeZone);
 }