Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

534 lines
25 KiB

5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. /*------------------------------------------------------------------------------
  3. ** File: gPoint.php
  4. ** Description: PHP class to convert Latitude & Longitude coordinates into
  5. ** UTM & Lambert Conic Conformal Northing/Easting coordinates.
  6. ** Version: 1.3
  7. ** Author: Brenor Brophy
  8. ** Email: brenor dot brophy at gmail dot com
  9. ** Homepage: brenorbrophy.com
  10. **------------------------------------------------------------------------------
  11. ** COPYRIGHT (c) 2005, 2006, 2007, 2008 BRENOR BROPHY
  12. **
  13. ** The source code included in this package is free software; you can
  14. ** redistribute it and/or modify it under the terms of the GNU General Public
  15. ** License as published by the Free Software Foundation. This license can be
  16. ** read at:
  17. **
  18. ** http://www.opensource.org/licenses/gpl-license.php
  19. **
  20. ** This program is distributed in the hope that it will be useful, but WITHOUT
  21. ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. ** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23. **------------------------------------------------------------------------------
  24. **
  25. ** Code for datum and UTM conversion was converted from C++ code written by
  26. ** Chuck Gantz (chuck dot gantz at globalstar dot com) from
  27. ** http://www.gpsy.com/gpsinfo/geotoutm/ This URL has many other references to
  28. ** useful information concerning conversion of coordinates.
  29. **
  30. ** Rev History
  31. ** -----------------------------------------------------------------------------
  32. ** 1.0 08/25/2005 Initial Release
  33. ** 1.1 05/15/2006 Added software license language to header comments
  34. ** Fixed an error in the convertTMtoLL() method. The latitude
  35. ** calculation had a bunch of variables without $ symbols.
  36. ** Fixed an error in convertLLtoTM() method, The $this-> was
  37. ** missing in front of a couple of variables. Thanks to Bob
  38. ** Robins of Maryland for catching the bugs.
  39. ** 1.2 05/18/2007 Added default of NULL to $LongOrigin arguement in convertTMtoLL()
  40. ** and convertLLtoTM() to eliminate warning messages when the
  41. ** methods are called without a value for $LongOrigin.
  42. ** 1.3 02/21/2008 Fixed a bug in the distanceFrom method, where the input parameters
  43. ** were not being converted to radians prior to calculating the
  44. ** distance. Thanks to Enrico Benco for finding pointing it out.
  45. */
  46. define ("meter2nm", (1/1852));
  47. define ("nm2meter", 1852);
  48. /*------------------------------------------------------------------------------
  49. ** class gPoint ... for Geographic Point
  50. **
  51. ** This class encapsulates the methods for representing a geographic point on the
  52. ** earth in three different coordinate systema. Lat/Long, UTM and Lambert Conic
  53. ** Conformal.
  54. */
  55. class gPoint
  56. {
  57. /* Reference ellipsoids derived from Peter H. Dana's website-
  58. ** http://www.colorado.edu/geography/gcraft/notes/datum/datum_f.html
  59. ** email: pdana@pdana.com, web page: www.pdana.com
  60. **
  61. ** Source:
  62. ** Defense Mapping Agency. 1987b. DMA Technical Report: Supplement to Department
  63. ** of Defense World Geodetic System 1984 Technical Report. Part I and II.
  64. ** Washington, DC: Defense Mapping Agency
  65. */
  66. var $ellipsoid = array(//Ellipsoid name, Equatorial Radius, square of eccentricity
  67. "Airy" =>array (6377563, 0.00667054),
  68. "Australian National" =>array (6378160, 0.006694542),
  69. "Bessel 1841" =>array (6377397, 0.006674372),
  70. "Bessel 1841 Nambia" =>array (6377484, 0.006674372),
  71. "Clarke 1866" =>array (6378206, 0.006768658),
  72. "Clarke 1880" =>array (6378249, 0.006803511),
  73. "Everest" =>array (6377276, 0.006637847),
  74. "Fischer 1960 Mercury" =>array (6378166, 0.006693422),
  75. "Fischer 1968" =>array (6378150, 0.006693422),
  76. "GRS 1967" =>array (6378160, 0.006694605),
  77. "GRS 1980" =>array (6378137, 0.00669438),
  78. "Helmert 1906" =>array (6378200, 0.006693422),
  79. "Hough" =>array (6378270, 0.00672267),
  80. "International" =>array (6378388, 0.00672267),
  81. "Krassovsky" =>array (6378245, 0.006693422),
  82. "Modified Airy" =>array (6377340, 0.00667054),
  83. "Modified Everest" =>array (6377304, 0.006637847),
  84. "Modified Fischer 1960" =>array (6378155, 0.006693422),
  85. "South American 1969" =>array (6378160, 0.006694542),
  86. "WGS 60" =>array (6378165, 0.006693422),
  87. "WGS 66" =>array (6378145, 0.006694542),
  88. "WGS 72" =>array (6378135, 0.006694318),
  89. "WGS 84" =>array (6378137, 0.00669438));
  90. // Properties
  91. var $a; // Equatorial Radius
  92. var $e2; // Square of eccentricity
  93. var $datum; // Selected datum
  94. var $Xp, $Yp; // X,Y pixel location
  95. var $lat, $long; // Latitude & Longitude of the point
  96. var $utmNorthing, $utmEasting, $utmZone; // UTM Coordinates of the point
  97. var $lccNorthing, $lccEasting; // Lambert coordinates of the point
  98. var $falseNorthing, $falseEasting; // Origin coordinates for Lambert Projection
  99. var $latOfOrigin; // For Lambert Projection
  100. var $longOfOrigin; // For Lambert Projection
  101. var $firstStdParallel; // For lambert Projection
  102. var $secondStdParallel; // For lambert Projection
  103. // constructor
  104. function gPoint($datum='WGS 84') // Default datum is WGS 84
  105. {
  106. $this->a = $this->ellipsoid[$datum][0]; // Set datum Equatorial Radius
  107. $this->e2 = $this->ellipsoid[$datum][1]; // Set datum Square of eccentricity
  108. $this->datum = $datum; // Save the datum
  109. }
  110. //
  111. // Set/Get X & Y pixel of the point (used if it is being drawn on an image)
  112. //
  113. function setXY($x, $y)
  114. {
  115. $this->Xp = $x; $this->Yp = $y;
  116. }
  117. function Xp() { return $this->Xp; }
  118. function Yp() { return $this->Yp; }
  119. //
  120. // Set/Get/Output Longitude & Latitude of the point
  121. //
  122. function setLongLat($long, $lat)
  123. {
  124. $this->long = $long; $this->lat = $lat;
  125. }
  126. function Lat() { return $this->lat; }
  127. function Long() { return $this->long; }
  128. function printLatLong() { printf("Latitude: %1.5f Longitude: %1.5f",$this->lat, $this->long); }
  129. //
  130. // Set/Get/Output Universal Transverse Mercator Coordinates
  131. //
  132. function setUTM($easting, $northing, $zone='') // Zone is optional
  133. {
  134. $this->utmNorthing = $northing;
  135. $this->utmEasting = $easting;
  136. $this->utmZone = $zone;
  137. }
  138. function N() { return $this->utmNorthing; }
  139. function E() { return $this->utmEasting; }
  140. function Z() { return $this->utmZone; }
  141. function printUTM() { print( "Northing: ".(int)$this->utmNorthing.", Easting: ".(int)$this->utmEasting.", Zone: ".$this->utmZone); }
  142. //
  143. // Set/Get/Output Lambert Conic Conformal Coordinates
  144. //
  145. function setLambert($easting, $northing)
  146. {
  147. $this->lccNorthing = $northing;
  148. $this->lccEasting = $easting;
  149. }
  150. function lccN() { return $this->lccNorthing; }
  151. function lccE() { return $this->lccEasting; }
  152. function printLambert() { print( "Northing: ".(int)$this->lccNorthing.", Easting: ".(int)$this->lccEasting); }
  153. //------------------------------------------------------------------------------
  154. //
  155. // Convert Longitude/Latitude to UTM
  156. //
  157. // Equations from USGS Bulletin 1532
  158. // East Longitudes are positive, West longitudes are negative.
  159. // North latitudes are positive, South latitudes are negative
  160. // Lat and Long are in decimal degrees
  161. // Written by Chuck Gantz- chuck dot gantz at globalstar dot com, converted to PHP by
  162. // Brenor Brophy, brenor dot brophy at gmail dot com
  163. //
  164. // UTM coordinates are useful when dealing with paper maps. Basically the
  165. // map will can cover a single UTM zone which is 6 degrees on longitude.
  166. // So you really don't care about an object crossing two zones. You just get a
  167. // second map of the other zone. However, if you happen to live in a place that
  168. // straddles two zones (For example the Santa Babara area in CA straddles zone 10
  169. // and zone 11) Then it can become a real pain having to have two maps all the time.
  170. // So relatively small parts of the world (like say California) create their own
  171. // version of UTM coordinates that are adjusted to conver the whole area of interest
  172. // on a single map. These are called state grids. The projection system is the
  173. // usually same as UTM (i.e. Transverse Mercator), but the central meridian
  174. // aka Longitude of Origin is selected to suit the logitude of the area being
  175. // mapped (like being moved to the central meridian of the area) and the grid
  176. // may cover more than the 6 degrees of lingitude found on a UTM map. Areas
  177. // that are wide rather than long - think Montana as an example. May still
  178. // have to have a couple of maps to cover the whole state because TM projection
  179. // looses accuracy as you move further away from the Longitude of Origin, 15 degrees
  180. // is usually the limit.
  181. //
  182. // Now, in the case where we want to generate electronic maps that may be
  183. // placed pretty much anywhere on the globe we really don't to deal with the
  184. // issue of UTM zones in our coordinate system. We would really just like a
  185. // grid that is fully contigious over the area of the map we are drawing. Similiar
  186. // to the state grid, but local to the area we are interested in. I call this
  187. // Local Transverse Mercator and I have modified the function below to also
  188. // make this conversion. If you pass a Longitude value to the function as $LongOrigin
  189. // then that is the Longitude of Origin that will be used for the projection.
  190. // Easting coordinates will be returned (in meters) relative to that line of
  191. // longitude - So an Easting coordinate for a point located East of the longitude
  192. // of origin will be a positive value in meters, an Easting coordinate for a point
  193. // West of the longitude of Origin will have a negative value in meters. Northings
  194. // will always be returned in meters from the equator same as the UTM system. The
  195. // UTMZone value will be valid for Long/Lat given - thought it is not meaningful
  196. // in the context of Local TM. If a NULL value is passed for $LongOrigin
  197. // then the standard UTM coordinates are calculated.
  198. //
  199. function convertLLtoTM($LongOrigin = NULL)
  200. {
  201. $k0 = 0.9996;
  202. $falseEasting = 0.0;
  203. //Make sure the longitude is between -180.00 .. 179.9
  204. $LongTemp = ($this->long+180)-(integer)(($this->long+180)/360)*360-180; // -180.00 .. 179.9;
  205. $LatRad = deg2rad($this->lat);
  206. $LongRad = deg2rad($LongTemp);
  207. if (!$LongOrigin)
  208. { // Do a standard UTM conversion - so findout what zone the point is in
  209. $ZoneNumber = (integer)(($LongTemp + 180)/6) + 1;
  210. // Special zone for South Norway
  211. if( $this->lat >= 56.0 && $this->lat < 64.0 && $LongTemp >= 3.0 && $LongTemp < 12.0 ) // Fixed 1.1
  212. $ZoneNumber = 32;
  213. // Special zones for Svalbard
  214. if( $this->lat >= 72.0 && $this->lat < 84.0 )
  215. {
  216. if( $LongTemp >= 0.0 && $LongTemp < 9.0 ) $ZoneNumber = 31;
  217. else if( $LongTemp >= 9.0 && $LongTemp < 21.0 ) $ZoneNumber = 33;
  218. else if( $LongTemp >= 21.0 && $LongTemp < 33.0 ) $ZoneNumber = 35;
  219. else if( $LongTemp >= 33.0 && $LongTemp < 42.0 ) $ZoneNumber = 37;
  220. }
  221. $LongOrigin = ($ZoneNumber - 1)*6 - 180 + 3; //+3 puts origin in middle of zone
  222. //compute the UTM Zone from the latitude and longitude
  223. $this->utmZone = sprintf("%d%s", $ZoneNumber, $this->UTMLetterDesignator());
  224. // We also need to set the false Easting value adjust the UTM easting coordinate
  225. $falseEasting = 500000.0;
  226. }
  227. $LongOriginRad = deg2rad($LongOrigin);
  228. $eccPrimeSquared = ($this->e2)/(1-$this->e2);
  229. $N = $this->a/sqrt(1-$this->e2*sin($LatRad)*sin($LatRad));
  230. $T = tan($LatRad)*tan($LatRad);
  231. $C = $eccPrimeSquared*cos($LatRad)*cos($LatRad);
  232. $A = cos($LatRad)*($LongRad-$LongOriginRad);
  233. $M = $this->a*((1 - $this->e2/4 - 3*$this->e2*$this->e2/64 - 5*$this->e2*$this->e2*$this->e2/256)*$LatRad
  234. - (3*$this->e2/8 + 3*$this->e2*$this->e2/32 + 45*$this->e2*$this->e2*$this->e2/1024)*sin(2*$LatRad)
  235. + (15*$this->e2*$this->e2/256 + 45*$this->e2*$this->e2*$this->e2/1024)*sin(4*$LatRad)
  236. - (35*$this->e2*$this->e2*$this->e2/3072)*sin(6*$LatRad));
  237. $this->utmEasting = ($k0*$N*($A+(1-$T+$C)*$A*$A*$A/6
  238. + (5-18*$T+$T*$T+72*$C-58*$eccPrimeSquared)*$A*$A*$A*$A*$A/120)
  239. + $falseEasting);
  240. $this->utmNorthing = ($k0*($M+$N*tan($LatRad)*($A*$A/2+(5-$T+9*$C+4*$C*$C)*$A*$A*$A*$A/24
  241. + (61-58*$T+$T*$T+600*$C-330*$eccPrimeSquared)*$A*$A*$A*$A*$A*$A/720)));
  242. if($this->lat < 0)
  243. $this->utmNorthing += 10000000.0; //10000000 meter offset for southern hemisphere
  244. }
  245. //
  246. // This routine determines the correct UTM letter designator for the given latitude
  247. // returns 'Z' if latitude is outside the UTM limits of 84N to 80S
  248. // Written by Chuck Gantz- chuck dot gantz at globalstar dot com, converted to PHP by
  249. // Brenor Brophy, brenor dot brophy at gmail dot com
  250. //
  251. function UTMLetterDesignator()
  252. {
  253. if((84 >= $this->lat) && ($this->lat >= 72)) $LetterDesignator = 'X';
  254. else if((72 > $this->lat) && ($this->lat >= 64)) $LetterDesignator = 'W';
  255. else if((64 > $this->lat) && ($this->lat >= 56)) $LetterDesignator = 'V';
  256. else if((56 > $this->lat) && ($this->lat >= 48)) $LetterDesignator = 'U';
  257. else if((48 > $this->lat) && ($this->lat >= 40)) $LetterDesignator = 'T';
  258. else if((40 > $this->lat) && ($this->lat >= 32)) $LetterDesignator = 'S';
  259. else if((32 > $this->lat) && ($this->lat >= 24)) $LetterDesignator = 'R';
  260. else if((24 > $this->lat) && ($this->lat >= 16)) $LetterDesignator = 'Q';
  261. else if((16 > $this->lat) && ($this->lat >= 8)) $LetterDesignator = 'P';
  262. else if(( 8 > $this->lat) && ($this->lat >= 0)) $LetterDesignator = 'N';
  263. else if(( 0 > $this->lat) && ($this->lat >= -8)) $LetterDesignator = 'M';
  264. else if((-8 > $this->lat) && ($this->lat >= -16)) $LetterDesignator = 'L';
  265. else if((-16 > $this->lat) && ($this->lat >= -24)) $LetterDesignator = 'K';
  266. else if((-24 > $this->lat) && ($this->lat >= -32)) $LetterDesignator = 'J';
  267. else if((-32 > $this->lat) && ($this->lat >= -40)) $LetterDesignator = 'H';
  268. else if((-40 > $this->lat) && ($this->lat >= -48)) $LetterDesignator = 'G';
  269. else if((-48 > $this->lat) && ($this->lat >= -56)) $LetterDesignator = 'F';
  270. else if((-56 > $this->lat) && ($this->lat >= -64)) $LetterDesignator = 'E';
  271. else if((-64 > $this->lat) && ($this->lat >= -72)) $LetterDesignator = 'D';
  272. else if((-72 > $this->lat) && ($this->lat >= -80)) $LetterDesignator = 'C';
  273. else $LetterDesignator = 'Z'; //This is here as an error flag to show that the Latitude is outside the UTM limits
  274. return($LetterDesignator);
  275. }
  276. //------------------------------------------------------------------------------
  277. //
  278. // Convert UTM to Longitude/Latitude
  279. //
  280. // Equations from USGS Bulletin 1532
  281. // East Longitudes are positive, West longitudes are negative.
  282. // North latitudes are positive, South latitudes are negative
  283. // Lat and Long are in decimal degrees.
  284. // Written by Chuck Gantz- chuck dot gantz at globalstar dot com, converted to PHP by
  285. // Brenor Brophy, brenor dot brophy at gmail dot com
  286. //
  287. // If a value is passed for $LongOrigin then the function assumes that
  288. // a Local (to the Longitude of Origin passed in) Transverse Mercator
  289. // coordinates is to be converted - not a UTM coordinate. This is the
  290. // complementary function to the previous one. The function cannot
  291. // tell if a set of Northing/Easting coordinates are in the North
  292. // or South hemesphere - they just give distance from the equator not
  293. // direction - so only northern hemesphere lat/long coordinates are returned.
  294. // If you live south of the equator there is a note later in the code
  295. // explaining how to have it just return southern hemesphere lat/longs.
  296. //
  297. function convertTMtoLL($LongOrigin = NULL)
  298. {
  299. $k0 = 0.9996;
  300. $e1 = (1-sqrt(1-$this->e2))/(1+sqrt(1-$this->e2));
  301. $falseEasting = 0.0;
  302. $y = $this->utmNorthing;
  303. if (!$LongOrigin)
  304. { // It is a UTM coordinate we want to convert
  305. sscanf($this->utmZone,"%d%s",$ZoneNumber,$ZoneLetter);
  306. if($ZoneLetter >= 'N')
  307. $NorthernHemisphere = 1;//point is in northern hemisphere
  308. else
  309. {
  310. $NorthernHemisphere = 0;//point is in southern hemisphere
  311. $y -= 10000000.0;//remove 10,000,000 meter offset used for southern hemisphere
  312. }
  313. $LongOrigin = ($ZoneNumber - 1)*6 - 180 + 3; //+3 puts origin in middle of zone
  314. $falseEasting = 500000.0;
  315. }
  316. // $y -= 10000000.0; // Uncomment line to make LOCAL coordinates return southern hemesphere Lat/Long
  317. $x = $this->utmEasting - $falseEasting; //remove 500,000 meter offset for longitude
  318. $eccPrimeSquared = ($this->e2)/(1-$this->e2);
  319. $M = $y / $k0;
  320. $mu = $M/($this->a*(1-$this->e2/4-3*$this->e2*$this->e2/64-5*$this->e2*$this->e2*$this->e2/256));
  321. $phi1Rad = $mu + (3*$e1/2-27*$e1*$e1*$e1/32)*sin(2*$mu)
  322. + (21*$e1*$e1/16-55*$e1*$e1*$e1*$e1/32)*sin(4*$mu)
  323. +(151*$e1*$e1*$e1/96)*sin(6*$mu);
  324. $phi1 = rad2deg($phi1Rad);
  325. $N1 = $this->a/sqrt(1-$this->e2*sin($phi1Rad)*sin($phi1Rad));
  326. $T1 = tan($phi1Rad)*tan($phi1Rad);
  327. $C1 = $eccPrimeSquared*cos($phi1Rad)*cos($phi1Rad);
  328. $R1 = $this->a*(1-$this->e2)/pow(1-$this->e2*sin($phi1Rad)*sin($phi1Rad), 1.5);
  329. $D = $x/($N1*$k0);
  330. $tlat = $phi1Rad - ($N1*tan($phi1Rad)/$R1)*($D*$D/2-(5+3*$T1+10*$C1-4*$C1*$C1-9*$eccPrimeSquared)*$D*$D*$D*$D/24
  331. +(61+90*$T1+298*$C1+45*$T1*$T1-252*$eccPrimeSquared-3*$C1*$C1)*$D*$D*$D*$D*$D*$D/720); // fixed in 1.1
  332. $this->lat = rad2deg($tlat);
  333. $tlong = ($D-(1+2*$T1+$C1)*$D*$D*$D/6+(5-2*$C1+28*$T1-3*$C1*$C1+8*$eccPrimeSquared+24*$T1*$T1)
  334. *$D*$D*$D*$D*$D/120)/cos($phi1Rad);
  335. $this->long = $LongOrigin + rad2deg($tlong);
  336. }
  337. //------------------------------------------------------------------------------
  338. // Configure a Lambert Conic Conformal Projection
  339. //
  340. // falseEasting & falseNorthing are just an offset in meters added to the final
  341. // coordinate calculated.
  342. //
  343. // longOfOrigin & LatOfOrigin are the "center" latitiude and longitude of the
  344. // area being projected. All coordinates will be calculated in meters relative
  345. // to this point on the earth.
  346. //
  347. // firstStdParallel & secondStdParallel are the two lines of longitude (that
  348. // is they run east-west) that define where the "cone" intersects the earth.
  349. // Simply put they should bracket the area being projected.
  350. //
  351. // google is your friend to find out more
  352. //
  353. function configLambertProjection ($falseEasting, $falseNorthing,
  354. $longOfOrigin, $latOfOrigin,
  355. $firstStdParallel, $secondStdParallel)
  356. {
  357. $this->falseEasting = $falseEasting;
  358. $this->falseNorthing = $falseNorthing;
  359. $this->longOfOrigin = $longOfOrigin;
  360. $this->latOfOrigin = $latOfOrigin;
  361. $this->firstStdParallel = $firstStdParallel;
  362. $this->secondStdParallel = $secondStdParallel;
  363. }
  364. //------------------------------------------------------------------------------
  365. //
  366. // Convert Longitude/Latitude to Lambert Conic Easting/Northing
  367. //
  368. // This routine will convert a Latitude/Longitude coordinate to an Northing/
  369. // Easting coordinate on a Lambert Conic Projection. The configLambertProjection()
  370. // function should have been called prior to this one to setup the specific
  371. // parameters for the projection. The Northing/Easting parameters calculated are
  372. // in meters (because the datum used is in meters) and are relative to the
  373. // falseNorthing/falseEasting coordinate. Which in turn is relative to the
  374. // Lat/Long of origin The formula were obtained from URL:
  375. // http://www.ihsenergy.com/epsg/guid7_2.html.
  376. // Code was written by Brenor Brophy, brenor dot brophy at gmail dot com
  377. //
  378. function convertLLtoLCC()
  379. {
  380. $e = sqrt($this->e2);
  381. $phi = deg2rad($this->lat); // Latitude to convert
  382. $phi1 = deg2rad($this->firstStdParallel); // Latitude of 1st std parallel
  383. $phi2 = deg2rad($this->secondStdParallel); // Latitude of 2nd std parallel
  384. $lamda = deg2rad($this->long); // Lonitude to convert
  385. $phio = deg2rad($this->latOfOrigin); // Latitude of Origin
  386. $lamdao = deg2rad($this->longOfOrigin); // Longitude of Origin
  387. $m1 = cos($phi1) / sqrt(( 1 - $this->e2*sin($phi1)*sin($phi1)));
  388. $m2 = cos($phi2) / sqrt(( 1 - $this->e2*sin($phi2)*sin($phi2)));
  389. $t1 = tan((pi()/4)-($phi1/2)) / pow(( ( 1 - $e*sin($phi1) ) / ( 1 + $e*sin($phi1) )),$e/2);
  390. $t2 = tan((pi()/4)-($phi2/2)) / pow(( ( 1 - $e*sin($phi2) ) / ( 1 + $e*sin($phi2) )),$e/2);
  391. $to = tan((pi()/4)-($phio/2)) / pow(( ( 1 - $e*sin($phio) ) / ( 1 + $e*sin($phio) )),$e/2);
  392. $t = tan((pi()/4)-($phi /2)) / pow(( ( 1 - $e*sin($phi ) ) / ( 1 + $e*sin($phi ) )),$e/2);
  393. $n = (log($m1)-log($m2)) / (log($t1)-log($t2));
  394. $F = $m1/($n*pow($t1,$n));
  395. $rf = $this->a*$F*pow($to,$n);
  396. $r = $this->a*$F*pow($t,$n);
  397. $theta = $n*($lamda - $lamdao);
  398. $this->lccEasting = $this->falseEasting + $r*sin($theta);
  399. $this->lccNorthing = $this->falseNorthing + $rf - $r*cos($theta);
  400. }
  401. //------------------------------------------------------------------------------
  402. //
  403. // Convert Easting/Northing on a Lambert Conic projection to Longitude/Latitude
  404. //
  405. // This routine will convert a Lambert Northing/Easting coordinate to an
  406. // Latitude/Longitude coordinate. The configLambertProjection() function should
  407. // have been called prior to this one to setup the specific parameters for the
  408. // projection. The Northing/Easting parameters are in meters (because the datum
  409. // used is in meters) and are relative to the falseNorthing/falseEasting
  410. // coordinate. Which in turn is relative to the Lat/Long of origin The formula
  411. // were obtained from URL http://www.ihsenergy.com/epsg/guid7_2.html. Code
  412. // was written by Brenor Brophy, brenor dot brophy at gmail dot com
  413. //
  414. function convertLCCtoLL()
  415. {
  416. $e = sqrt($this->e2);
  417. $phi1 = deg2rad($this->firstStdParallel); // Latitude of 1st std parallel
  418. $phi2 = deg2rad($this->secondStdParallel); // Latitude of 2nd std parallel
  419. $phio = deg2rad($this->latOfOrigin); // Latitude of Origin
  420. $lamdao = deg2rad($this->longOfOrigin); // Longitude of Origin
  421. $E = $this->lccEasting;
  422. $N = $this->lccNorthing;
  423. $Ef = $this->falseEasting;
  424. $Nf = $this->falseNorthing;
  425. $m1 = cos($phi1) / sqrt(( 1 - $this->e2*sin($phi1)*sin($phi1)));
  426. $m2 = cos($phi2) / sqrt(( 1 - $this->e2*sin($phi2)*sin($phi2)));
  427. $t1 = tan((pi()/4)-($phi1/2)) / pow(( ( 1 - $e*sin($phi1) ) / ( 1 + $e*sin($phi1) )),$e/2);
  428. $t2 = tan((pi()/4)-($phi2/2)) / pow(( ( 1 - $e*sin($phi2) ) / ( 1 + $e*sin($phi2) )),$e/2);
  429. $to = tan((pi()/4)-($phio/2)) / pow(( ( 1 - $e*sin($phio) ) / ( 1 + $e*sin($phio) )),$e/2);
  430. $n = (log($m1)-log($m2)) / (log($t1)-log($t2));
  431. $F = $m1/($n*pow($t1,$n));
  432. $rf = $this->a*$F*pow($to,$n);
  433. $r_ = sqrt( pow(($E-$Ef),2) + pow(($rf-($N-$Nf)),2) );
  434. $t_ = pow($r_/($this->a*$F),(1/$n));
  435. $theta_ = atan(($E-$Ef)/($rf-($N-$Nf)));
  436. $lamda = $theta_/$n + $lamdao;
  437. $phi0 = (pi()/2) - 2*atan($t_);
  438. $phi1 = (pi()/2) - 2*atan($t_*pow(((1-$e*sin($phi0))/(1+$e*sin($phi0))),$e/2));
  439. $phi2 = (pi()/2) - 2*atan($t_*pow(((1-$e*sin($phi1))/(1+$e*sin($phi1))),$e/2));
  440. $phi = (pi()/2) - 2*atan($t_*pow(((1-$e*sin($phi2))/(1+$e*sin($phi2))),$e/2));
  441. $this->lat = rad2deg($phi);
  442. $this->long = rad2deg($lamda);
  443. }
  444. //------------------------------------------------------------------------------
  445. // This is a useful function that returns the Great Circle distance from the
  446. // gPoint to another Long/Lat coordinate
  447. //
  448. // Result is returned as meters
  449. //
  450. function distanceFrom($lon1, $lat1)
  451. {
  452. $lon1 = deg2rad($lon1); $lat1 = deg2rad($lat1); // Added in 1.3
  453. $lon2 = deg2rad($this->Long()); $lat2 = deg2rad($this->Lat());
  454. $theta = $lon2 - $lon1;
  455. $dist = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($theta));
  456. // Alternative formula supposed to be more accurate for short distances
  457. // $dist = 2*asin(sqrt( pow(sin(($lat1-$lat2)/2),2) + cos($lat1)*cos($lat2)*pow(sin(($lon1-$lon2)/2),2)));
  458. return ( $dist * 6366710 ); // from http://williams.best.vwh.net/avform.htm#GCF
  459. }
  460. //------------------------------------------------------------------------------
  461. // This function also calculates the distance between two points. In this case
  462. // it just uses Pythagoras's theorm using TM coordinates.
  463. //
  464. function distanceFromTM(&$pt)
  465. {
  466. $E1 = $pt->E(); $N1 = $pt->N();
  467. $E2 = $this->E(); $N2 = $this->N();
  468. $dist = sqrt(pow(($E1-$E2),2)+pow(($N1-$N2),2));
  469. return $dist;
  470. }
  471. //------------------------------------------------------------------------------
  472. // This function geo-references a geoPoint to a given map. This means that it
  473. // calculates the x,y pixel coordinate that coresponds to the Lat/Long value of
  474. // the geoPoint. The calculation is done using the Transverse Mercator(TM)
  475. // coordinates of the gPoint with respect to the TM coordinates of the center
  476. // point of the map. So this only makes sense if you are using Local TM
  477. // projection.
  478. //
  479. // $rX & $rY are the pixel coordinates that corespond to the Northing/Easting
  480. // ($rE/$rN) coordinate it is to this coordinate that the point will be
  481. // geo-referenced. The $LongOrigin is needed to make sure the Easting/Northing
  482. // coordinates of the point are correctly converted.
  483. //
  484. function gRef($rX, $rY, $rE, $rN, $Scale, $LongOrigin)
  485. {
  486. $this->convertLLtoTM($LongOrigin);
  487. $x = (($this->E() - $rE) / $Scale) // The easting in meters times the scale to get pixels
  488. // is relative to the center of the image so adjust to
  489. + ($rX); // the left coordinate.
  490. $y = $rY - // Adjust to bottom coordinate.
  491. (($rN - $this->N()) / $Scale); // The northing in meters
  492. // relative to the equator. Subtract center point northing
  493. // to get relative to image center and convert meters to pixels
  494. $this->setXY((int)$x,(int)$y); // Save the geo-referenced result.
  495. }
  496. } // end of class gPoint
  497. ?>