Skip to content
forked from dvdoug/PHPCoord

Conversion of phpcoord project for PHP5.3/PSR-0

Notifications You must be signed in to change notification settings

caffme/PHPCoord

 
 

Repository files navigation

PHPCoord

Conversion/modernisation/enhancement of phpcoord for PHP5.3+/PSR-4. Based on v2.3 of original project.

Build Status

The original code by Jonathan Stott can be found at http://www.jstott.me.uk/phpcoord/ Backwards compatibility has been maintained with class/function/member naming.

PHPCoord is a set of PHP functions for handling various co-ordinate systems and converting between them. Currently, OSGB (Ordnance Survey of Great Britain) grid references, UTM (Universal Transverse Mercator) references and latitude/longitude are supported.

Conversions between latitudes/longitudes in WGS84 (GPS), OSGB36, ED50 and NAD27 datums are built-in, and helper functions exist to ease conversion between other datums.

A function is also provided to find the surface distance between two points of latitude and longitude.

Please note that the OSGB conversion functions use the British datum (OSGB36), which is not the same as used by e.g. GPS (WGS84). Conversion functions are provided and should be used if <200m accuracy is important.

Output of calculations have been changed from the original code in the following two ways:

  • When converting latitude and longitude between WGS84 and OSGB36 or vice-versa, a wrong constant for the y translation has been corrected (was off by 1 metre)
  • Eastings and northings are rounded to 1m, and lat/long to 5dp (approx 1m) to avoid any misconceptions that precision is the same thing as accuracy
  • When calculating surface distances, a more accurate mean radius is now used rather than that derived from historical definitions of a nautical mile
  • Corrected calculation of OS 6-figure grid references (rounding instead of truncating meant the grid square was sometimes off by 1)
  • You must specify the reference ellipsoid when creating a LatLng object to avoid guesses as to what was actually meant.
  • Corrected issue with Helmert transform where the resulting co-ordinate could be placed into the wrong quadrant

Usage

$OSRef = new OSRef(500000, 200000); //Easting, Northing
$LatLng = $OSRef->toLatLng();
$LatLng->OSGB36ToWGS84(); //optional, see note above

$lat =  $LatLng->lat;
$long = $LatLng->lng;


$LatLng = new LatLng(50.12345, 1.23456, RefEll::WGS84()); //Latitude, Long
$OSRef = $LatLng->toOSRef(); 

$easting = $OSRef->easting;
$northing = $OSRef->northing;

Requirements

  • PHP 5.3 or higher

License

The original PHPcoord is GPL-licensed, and this version inherits that. Terms can be found at http://www.gnu.org/licenses/gpl.html

About

Conversion of phpcoord project for PHP5.3/PSR-0

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%