GeoCoordinate Class Reference
[GeoCalc]
Class repersenting a coordinate. More...
Public Member Functions |
|
__construct ($lat, $lon) | |
Contructor. |
|
bounding_box ($ns_radius, $we_radius) | |
Compute bounding box. |
|
center_of ($other) | |
FInd center between two coordinates.
|
|
distance_to ($other) | |
Calculates distance between this and other
points. |
|
is_valid () | |
Returns true, if this coordinate is valid.
|
|
is_within ($coord1, $coord2) | |
lat_to_string ($precision=4, $system=false) | |
Renders this Coordinate's Latitude to
string. |
|
lon_to_string ($precision=4, $system=false) | |
Renders this Coordinate's Longitude to
string. |
|
to_string ($divider= ', ', $precision=4, $system=false) | |
Renders this Coordinate in the form
Latitude(divider)Longitude. |
|
Static Public Member Functions |
|
static | boundig_box_of ($arr_coordinates) |
Calculate a bounding box that contains all
of coordinates passed. |
|
Public Attributes |
|
$lat | |
$lon |
Detailed Description
Class repersenting a coordinate.
Definition at line 10 of file geocoordinate.cls.php.
Constructor & Destructor Documentation
GeoCoordinate::__construct | ( | $ | lat, | |
$ | lon | |||
) |
Contructor.
- Parameters:
-
double $lat Latitude double $lon Longitude
Definition at line 28 of file geocoordinate.cls.php.
Member Function Documentation
static GeoCoordinate::boundig_box_of | ( | $ | arr_coordinates | ) | [static] |
Calculate a bounding box that contains all of coordinates passed.
- Parameters:
-
$arr_coordinates
- Returns:
- array Array with two elements 'min' and 'max', containing a GeoCoordinate instance
Definition at line 160 of file geocoordinate.cls.php.
00160 { 00161 $arr_data = array(); 00162 /* @var $coord GeoCoordinate */ 00163 foreach($arr_coordinates as $coord) { 00164 if ($coord->is_valid()) { 00165 $arr_data[] = array('lat' => $coord->lat, 'lon' => $coord->lon); 00166 } 00167 } 00168 $arr = GeoCalculator::bounding_box_of($arr_data); 00169 return $arr ? array( 00170 'min' => new GeoCoordinate($arr['lat']['min'], $arr['lon']['min']), 00171 'max' => new GeoCoordinate($arr['lat']['max'], $arr['lon']['max']) 00172 ) : false; 00173 }
GeoCoordinate::bounding_box | ( | $ | ns_radius, | |
$ | we_radius | |||
) |
Compute bounding box.
- Parameters:
-
float $ns_radius Radius of bound box in north to south direction float $we_radius Radius of bound box in west to east direction
- Returns:
- array Array with two elements 'min' and 'max', containing a GeoCoordinate instance
- Attention:
- The bounding box is a rectangle, so the distance to elements located within the corners of that rectangle may be larger than the radius passed.
Definition at line 144 of file geocoordinate.cls.php.
00144 { 00145 $arr = GeoCalculator::bounding_box($this->lat, $this->lon, $ns_radius, $we_radius); 00146 00147 return array( 00148 'min' => new GeoCoordinate($arr['lat']['min'], $arr['lon']['min']), 00149 'max' => new GeoCoordinate($arr['lat']['max'], $arr['lon']['max']) 00150 ); 00151 }
GeoCoordinate::center_of | ( | $ | other | ) |
FInd center between two coordinates.
- Parameters:
-
GeoCoordinate $other
- Returns:
- bool|GeoCoordinate
Definition at line 93 of file geocoordinate.cls.php.
00093 { 00094 $ret = false; 00095 if ($this->is_valid() && $other->is_valid()) { 00096 $ret = new GeoCoordinate( 00097 $this->lat + ($other->lat - $this->lat) / 2.0, 00098 $this->lon + ($other->lon - $this->lon) / 2.0 00099 ); 00100 } 00101 return $ret; 00102 }
GeoCoordinate::distance_to | ( | $ | other | ) |
Calculates distance between this and other points.
- Parameters:
-
GeoCoordinate $other Coordinate of point
- Returns:
- float Distance in km or FALSE if one of the coordinates is invalid
Definition at line 79 of file geocoordinate.cls.php.
00079 { 00080 $ret = false; 00081 if ($this->is_valid() && $other->is_valid()) { 00082 $ret = GeoCalculator::distance($this->lat, $this->lon, $other->lat, $other->lon); 00083 } 00084 return $ret; 00085 }
GeoCoordinate::is_valid | ( | ) |
Returns true, if this coordinate is valid.
Invalid coordinates can be created by passing NULL or a string to contructor
- Returns:
- bool
Definition at line 129 of file geocoordinate.cls.php.
GeoCoordinate::is_within | ( | $ | coord1, | |
$ | coord2 | |||
) |
- Parameters:
-
GeoCoordinate $coord1 GeoCoordinate $coord2
Definition at line 108 of file geocoordinate.cls.php.
00108 { 00109 $ret = false; 00110 if ($this->is_valid() && $coord1->is_valid() && $coord2->is_valid()) { 00111 $max_lat = max($coord1->lat, $coord2->lat); 00112 $min_lat = min($coord1->lat, $coord2->lat); 00113 $max_lon = max($coord1->lon, $coord2->lon); 00114 $min_lon = min($coord1->lon, $coord2->lon); 00115 $ret = 00116 $this->lat >= $min_lat && $this->lat <= $max_lat && 00117 $this->lon >= $min_lon && $this->lon <= $max_lon; 00118 } 00119 return $ret; 00120 }
GeoCoordinate::lat_to_string | ( | $ | precision = 4 , |
|
$ | system = false |
|||
) |
Renders this Coordinate's Latitude to string.
- Parameters:
-
int $precision Number of digits, passed to String::number() to format values bool $system True to use C locale to format values. False to use current locale. Passed to String::number()
- Returns:
- string
Definition at line 57 of file geocoordinate.cls.php.
00057 { 00058 return String::number($this->lat, $precision, $system); 00059 }
GeoCoordinate::lon_to_string | ( | $ | precision = 4 , |
|
$ | system = false |
|||
) |
Renders this Coordinate's Longitude to string.
- Parameters:
-
int $precision Number of digits, passed to String::number() to format values bool $system True to use C locale to format values. False to use current locale. Passed to String::number()
- Returns:
- string
Definition at line 69 of file geocoordinate.cls.php.
00069 { 00070 return String::number($this->lon, $precision, $system); 00071 }
GeoCoordinate::to_string | ( | $ | divider = ' , |
|
' | , | |||
$ | precision = 4 , |
|||
$ | system = false |
|||
) |
Renders this Coordinate in the form Latitude(divider)Longitude.
- Parameters:
-
string $divider int $precision Number of digits, passed to String::number() to format values bool $system True to use C locale to format values. False to use current locale. Passed to String::number()
- Returns:
- string
Definition at line 42 of file geocoordinate.cls.php.
00042 { 00043 return 00044 $this->lat_to_string($precision, $system) . 00045 $divider . 00046 $this->lon_to_string($precision, $system); 00047 }
Member Data Documentation
GeoCoordinate::$lat |
Definition at line 15 of file geocoordinate.cls.php.
GeoCoordinate::$lon |
Definition at line 20 of file geocoordinate.cls.php.
The documentation for this class was generated from the following file:
- contributions/lib.geocalc/lib/components/geocoordinate.cls.php