function farm_map_lon_deg_len in farmOS 7
Calculate longitude degree length at a given latitude. Equations are taken from https://en.wikipedia.org/wiki/Geographic_coordinate_system#Expressing_la... See also http://gis.stackexchange.com/questions/75528/length-of-a-degree-where-do...
Parameters
$lat: The latitude to calculate degree length at, in degrees.
Return value
string Returns the length of a degree of longitude at the given latitude as a string, in meters.
2 calls to farm_map_lon_deg_len()
- farm_map_distance in modules/
farm/ farm_map/ farm_map.geo.inc - Calculate the distance between two latitude/longitude points in meters.
- farm_map_polygon_area in modules/
farm/ farm_map/ farm_map.geo.inc - Calculate the area of a Polygon in square meters.
File
- modules/
farm/ farm_map/ farm_map.geo.inc, line 223 - Farm map geometry functions.
Code
function farm_map_lon_deg_len($lat) {
// Load GeoPHP.
geophp_load();
// Set BCMath scale.
farm_map_set_bcscale();
// Convert degrees to radians.
$lat = deg2rad($lat);
// Define coefficients. These are copied from
// http://gis.stackexchange.com/questions/75528/length-of-a-degree-where-do-the-terms-in-this-formula-come-from
$p1 = 111412.87733;
$p2 = 93.50412;
$p3 = 0.11774;
// If BCMath is available, use that. Otherwise, use normal PHP float
// operations.
if (geoPHP::bcmathInstalled()) {
$length = bcsub(bcmul($p1, cos($lat)), bcsub(bcmul($p2, cos(bcmul(3, $lat))), bcmul($p3, cos(bcmul(5, $lat)))));
}
else {
$length = $p1 * cos($lat) - $p2 * cos(3 * $lat) - $p3 * cos(5 * $lat);
}
// Reset BCMath scale.
farm_map_reset_bcscale();
// Return the length.
return (string) $length;
}