REDFEARN - A php version


CODE



<?php 
##################################################
# This work is distributed under the following licence
# http://creativecommons.org/licenses/by/3.0/au/
#
# This is a remix (adapted work) of an Excel spreadsheet provided by "Geoscience Australia".
# The original spreadsheet can be found at -
# http://www.ga.gov.au/geodesy/datums/calcs.jsp 
#
# Geoscience Australia do not endorse this remix in any manner.
#
# ~Remix by B.B.Morgan
# Disclaimer: This is a simple copy of how the excel sheet 
#             calculates things. Therefore there may be errors
#             in how this code performs, or for that matter the
#             original code as I cannot discern if it is correct.
###################################################

function redfearn($SiteName$ZoneNoReal$LatHours$LatMinutes$LatSeconds$LonHours$LonMinutes$LonSeconds$ElliposidDefinition "GRS80"$SemiMajorAxis 6378137.000$InverseFlattening 298.257222101000$TmDefinition "GDA-MGA"$FalseEasting 500000.0000$FalseNorthing 10000000.0000$CentralScaleFactor 0.9996$ZoneWidthDeg 6$LongitudeOfTheCentralMeridianOfZone1Degrees = -177){ 

$Flattening 1/$InverseFlattening;
$SemiMinusMinorAxis $SemiMajorAxis*(1-$Flattening);
$Eccentricity = (2*$Flattening)-($Flattening*$Flattening);
$EEccentricity sqrt($Eccentricity);
$SecondEccentricity $Eccentricity/(1-$Eccentricity);
$ESecondEccentricity sqrt($SecondEccentricity);
$n = ($SemiMajorAxis $SemiMinusMinorAxis)/($SemiMajorAxis $SemiMinusMinorAxis);
$n_x_x_2 $n*$n;
$n_x_x_3 $n*$n_x_x_2;
$n_x_x_4 $n_x_x_2*$n_x_x_2;
$G $SemiMajorAxis *(1-$n)*(1-$n_x_x_2)*(1+(9*$n_x_x_2)/4+(225*$n_x_x_4)/64)*PI()/180;
$LongitudeOfWesternEdgeOfZoneZeroDegrees $LongitudeOfTheCentralMeridianOfZone1Degrees-(1.5*$ZoneWidthDeg);
$CentralMeridianOfZoneZeroDeg $LongitudeOfWesternEdgeOfZoneZeroDegrees+($ZoneWidthDeg/2);
$LatitudeDeg abs($LatHours)+abs($LatMinutes/60)+abs($LatSeconds/3600);
$Zone intval($ZoneNoReal);
if(
$LatHours<0){$LatDecDeg = -$LatitudeDeg;}elseif($LatMinutes<0){$LatDecDeg = -$LatitudeDeg;}elseif($LatSeconds<0){$LatDecDeg = -$LatitudeDeg;}else $LatDecDeg $LatitudeDeg;
$LatitudeRadians = ($LatDecDeg/180)*PI();
$LongitudeDeg abs($LonHours)+abs($LonMinutes/60)+abs($LonSeconds/3600);
if(
$LonHours<0){$LonDecDeg = -$LongitudeDeg;}elseif($LonMinutes<0){$LonDecDeg = -$LongitudeDeg;}elseif($LonSeconds<0){$LonDecDeg = -$LongitudeDeg;}else $LonDecDeg $LongitudeDeg;
$LonRadians = ($LonDecDeg/180)*PI();
$CentralMeridian = ($Zone*$ZoneWidthDeg)+$CentralMeridianOfZoneZeroDeg;
$DiffLongitudeDegrees =  $LonDecDeg $CentralMeridian
$DiffLongitudeHours intval($DiffLongitudeDegrees);
$DiffLongitudeMinutes intval((($LongitudeDeg-$LonHours)*60));
$DiffLongitudeSeconds = (($LongitudeDeg-$LonHours)-($DiffLongitudeMinutes/60))*3600;
$DiffLongitudeRadians =  ($DiffLongitudeDegrees/180)*PI(); 
$SinLatitude sin($LatitudeRadians);
$SinLatitude2 sin(2*$LatitudeRadians);
$SinLatitude4 sin(4*$LatitudeRadians);
$SinLatitude6 sin(6*$LatitudeRadians);
$E2 $Eccentricity;
$E4 $E2*$E2;
$E6 $E2*$E4;
$A0 1-($E2/4)-((3*$E4)/64)-((5*$E6)/256);
$A2 = (3/8)*($E2+($E4/4)+((15*$E6)/128));
$A4 = (15/256)*($E4+((3*$E6)/4));
$A6 = (35*$E6)/3072;
$MeridianDistanceFirstTerm $SemiMajorAxis $A0 $LatitudeRadians;
$MeridianDistanceSecondTerm = -$SemiMajorAxis $A2 $SinLatitude2;
$MeridianDistanceThirdTerm $SemiMajorAxis $A4 $SinLatitude4;
$MeridianDistanceForthTerm = -$SemiMajorAxis $A6 $SinLatitude6;
$SumMeridianDistances $MeridianDistanceFirstTerm $MeridianDistanceSecondTerm $MeridianDistanceThirdTerm $MeridianDistanceForthTerm
$RadiiOfCurvatureROH $SemiMajorAxis*(1-$E2)/pow((1-$E2*$SinLatitude*$SinLatitude),1.5);
$RadiiOfCurvatureNU $SemiMajorAxis pow((1-($E2*$SinLatitude*$SinLatitude)),0.5);
$PowerToCosLatitude1 cos($LatitudeRadians);
$PowerToCosLatitude2 pow($PowerToCosLatitude1 2);
$PowerToCosLatitude3 pow($PowerToCosLatitude1 3);
$PowerToCosLatitude4 pow($PowerToCosLatitude1 4);
$PowerToCosLatitude5 pow($PowerToCosLatitude1 5);
$PowerToCosLatitude6 pow($PowerToCosLatitude1 6);
$PowerToCosLatitude7 pow($PowerToCosLatitude1 7);
$PowerToCosLatitude8 pow($PowerToCosLatitude1 8);
$PowerToDiffLongitude1 $DiffLongitudeRadians;
$PowerToDiffLongitude2 pow($PowerToDiffLongitude1 2);
$PowerToDiffLongitude3 pow($PowerToDiffLongitude1 3);
$PowerToDiffLongitude4 pow($PowerToDiffLongitude1 4);
$PowerToDiffLongitude5 pow($PowerToDiffLongitude1 5);
$PowerToDiffLongitude6 pow($PowerToDiffLongitude1 6);
$PowerToDiffLongitude7 pow($PowerToDiffLongitude1 7);
$PowerToDiffLongitude8 pow($PowerToDiffLongitude1 8);
$TanLatitudeRadians tan($LatitudeRadians);
$PowerToTanLatitude1 $TanLatitudeRadians;
$PowerToTanLatitude2 pow($PowerToTanLatitude1 2);
$PowerToTanLatitude3 pow($PowerToTanLatitude1 3);
$PowerToTanLatitude4 pow($PowerToTanLatitude1 4);
$PowerToTanLatitude5 pow($PowerToTanLatitude1 5);
$PowerToTanLatitude6 pow($PowerToTanLatitude1 6);
$PowerToTanLatitude7 pow($PowerToTanLatitude1 7);
$PowerToTanLatitude8 pow($PowerToTanLatitude1 8);
$Psi $RadiiOfCurvatureNU $RadiiOfCurvatureROH;
$PowerToPsi1 $Psi;
$PowerToPsi2 pow($PowerToPsi1 2);
$PowerToPsi3 pow($PowerToPsi1 3);
$PowerToPsi4 pow($PowerToPsi1 4);
$PowerToPsi5 pow($PowerToPsi1 5);
$PowerToPsi6 pow($PowerToPsi1 6);
$PowerToPsi7 pow($PowerToPsi1 7);
$PowerToPsi8 pow($PowerToPsi1 8);

$EastingFirstTerm $RadiiOfCurvatureNU $PowerToDiffLongitude1 $PowerToCosLatitude1;
$EastingSecondTerm $RadiiOfCurvatureNU $PowerToDiffLongitude3 $PowerToCosLatitude3 * ($PowerToPsi1-$PowerToTanLatitude2)/6;
$EastingThirdTerm $RadiiOfCurvatureNU $PowerToDiffLongitude5 $PowerToCosLatitude5 * ($PowerToPsi3 * (1-$PowerToTanLatitude2)+$PowerToPsi2*(1+8*$PowerToTanLatitude2)-$PowerToPsi1*(2*$PowerToTanLatitude2)+$PowerToTanLatitude4)/120;
$EastingForthTerm $RadiiOfCurvatureNU $PowerToDiffLongitude7 $PowerToCosLatitude7 * (61-479$PowerToTanLatitude2+179*$PowerToTanLatitude4-$PowerToTanLatitude6)/5400;

$SumEasting $EastingFirstTerm $EastingSecondTerm $EastingThirdTerm $EastingForthTerm;
$SumEastingK $CentralScaleFactor $SumEasting;

$Easting $FalseEasting+$SumEastingK;

$NorthingMeridianDistance $SumMeridianDistances;
$NorthingFirstTerm $RadiiOfCurvatureNU*$SinLatitude*$PowerToDiffLongitude2*$PowerToCosLatitude1/2;
$NorthingSecondTerm $RadiiOfCurvatureNU*$SinLatitude*$PowerToDiffLongitude4*$PowerToCosLatitude3*(4*$PowerToPsi2+$PowerToPsi1-$PowerToTanLatitude2)/24;
$NorthingThirdTerm $RadiiOfCurvatureNU*$SinLatitude*$PowerToDiffLongitude6*$PowerToCosLatitude5*(8*$PowerToPsi4*(11-24*$PowerToTanLatitude2)-28*$PowerToPsi3*(1-6*$PowerToTanLatitude2)+$PowerToPsi2*(1-32*$PowerToTanLatitude2)-$PowerToPsi1*(2*$PowerToTanLatitude2)+$PowerToTanLatitude4)/720;
$NorthingForthTerm =  $RadiiOfCurvatureNU*$SinLatitude*$PowerToDiffLongitude8*$PowerToCosLatitude7*(1385-3111*$PowerToTanLatitude2+543*$PowerToTanLatitude4-$PowerToTanLatitude6)/40320;

$SumNorthing $NorthingMeridianDistance $NorthingFirstTerm $NorthingSecondTerm $NorthingThirdTerm $NorthingForthTerm;
$SumNorthingK $CentralScaleFactor $SumNorthing;

$Northing $FalseNorthing+$SumNorthingK;

$GridConvergenceFirstTermRad = -$SinLatitude*$PowerToDiffLongitude1;
$GridConvergenceSecondTermRad = -$SinLatitude*$PowerToDiffLongitude3*$PowerToCosLatitude2*(2*$PowerToPsi2-$PowerToPsi1)/3;
$GridConvergenceThirdTermRad = -$SinLatitude*$PowerToDiffLongitude5*$PowerToCosLatitude4*($PowerToPsi4*(11-24*$PowerToTanLatitude2)-$PowerToPsi3*(11-36*$PowerToTanLatitude2)+2*$PowerToPsi2*(1-7*$PowerToTanLatitude2)+$PowerToPsi1*$PowerToTanLatitude2)/15;
$GridConvergenceForthTermRad $SinLatitude*$PowerToDiffLongitude7*$PowerToCosLatitude6*(17-26*$PowerToTanLatitude2+2*$PowerToTanLatitude4)/315;

$SumGridConvergenceRad =$GridConvergenceFirstTermRad $GridConvergenceSecondTermRad $GridConvergenceThirdTermRad $GridConvergenceForthTermRad;

$GridConvergenceFirstTermDec  = ($GridConvergenceFirstTermRad/PI())*180;
$GridConvergenceSecondTermDec = ($GridConvergenceSecondTermRad/PI())*180;
$GridConvergenceThirdTermDec  = ($GridConvergenceThirdTermRad/PI())*180;
$GridConvergenceForthTermDec  = ($GridConvergenceForthTermRad/PI())*180

$SumGridConvergenceDec =$GridConvergenceFirstTermDec $GridConvergenceSecondTermDec $GridConvergenceThirdTermDec $GridConvergenceForthTermDec;

$GridConvergenceFirstTermHours  intval($GridConvergenceFirstTermDec);
$GridConvergenceSecondTermHours intval($GridConvergenceSecondTermDec);
$GridConvergenceThirdTermHours  intval($GridConvergenceThirdTermDec);
$GridConvergenceForthTermHours  intval($GridConvergenceForthTermDec); 

$GridConvergenceFirstTermMinutes  intval(($GridConvergenceFirstTermDec-$GridConvergenceFirstTermHours)*60 );
$GridConvergenceSecondTermMinutes intval(($GridConvergenceSecondTermDec-$GridConvergenceSecondTermHours)*60);
$GridConvergenceThirdTermMinutes intval(($GridConvergenceThirdTermDec-$GridConvergenceThirdTermHours)*60);
$GridConvergenceForthTermMinutes intval(($GridConvergenceForthTermDec-$GridConvergenceForthTermHours)*60);

$GridConvergenceFirstTermSeconds  = ($GridConvergenceFirstTermDec-$GridConvergenceFirstTermHours-($GridConvergenceFirstTermMinutes/60))*3600;
$GridConvergenceSecondTermSeconds  = ($GridConvergenceSecondTermDec-$GridConvergenceSecondTermHours-($GridConvergenceSecondTermMinutes/60))*3600;
$GridConvergenceThirdTermSeconds  = ($GridConvergenceThirdTermDec-$GridConvergenceThirdTermHours-($GridConvergenceThirdTermMinutes/60))*3600;
$GridConvergenceForthTermSeconds  = ($GridConvergenceForthTermDec-$GridConvergenceForthTermHours-($GridConvergenceForthTermMinutes/60))*3600;

$SumGridConvergenceHours $GridConvergenceFirstTermHours $GridConvergenceSecondTermHours $GridConvergenceThirdTermHours $GridConvergenceForthTermHours
$SumGridConvergenceMinutes $GridConvergenceFirstTermMinutes $GridConvergenceSecondTermMinutes $GridConvergenceThirdTermMinutes $GridConvergenceForthTermMinutes;
$SumGridConvergenceSeconds $GridConvergenceFirstTermSeconds $GridConvergenceSecondTermSeconds $GridConvergenceThirdTermSeconds $GridConvergenceForthTermSeconds;


$Point["Easting"] = $Easting;
$Point["Northing"] = $Northing;
$Point["GridConvergence"] = "$SumGridConvergenceHours&deg; $SumGridConvergenceMinutes&#39; $SumGridConvergenceSeconds&#34;";


return 
$Point;
};

# Calling the function
$NewPoint redfearn($SiteName "BUNINYONG"$ZoneNoReal 54.988$LatHours = -37,$LatMinutes 39,$LatSeconds 10.1561,$LonHours 143,$LonMinutes 55,$LonSeconds 35.38390);

# Showing the results
echo "<hr /><h2>RESULTS</h2><hr />";
print_r($NewPoint);

?>

RESULTS


Array ( [Easting] => 758173.79728246 [Northing] => 5828674.3400593 [GridConvergence] => 1° 47' 19.360411513365" )