forked from php-geospatial/geospatial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
70 lines (48 loc) · 2.18 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# geospatial - PHP Geospatial Extension
PHP Extension to handle common geospatial functions. The extension currently has implementations of the haversine and vincenty's formulas as well as a helmert transfomation function.
## Instalation
----------------------------
git clone git@github.com:php-geospatial/geospatial.git
cd geospatial
phpize
./configure --enable-geospatial
make
sudo make install
Then add the extension to an ini file e.g. /etc/php.ini
extension = geospatial.so
## Usage
The extension makes use of the geojson standard format for specying points as co-ordinates. One important thing to note about this format is that points are specied longitude **first** i.e. longitude, latitude.
e.g.
$greenwichObservatory = array(
'type' => 'Point',
'coordinates' => array( -0.001483 , 51.477917);
);
### Haversine
$from = array(
'type' => 'Point',
'coordinates' => array( -104.88544, 39.06546 )
);
$to = array(
'type' => 'Point',
'coordinates' => array( -104.80, 39.06546 )
);
var_dump(haversine($to, $from));
### Vincenty's Formula
Vincenty's formula attempts to provide a more acurate distance between two points than the Haversine formula. Whereas the Haversine formula assumes a spherical earth the Vincenty method models the earth as an ellipsoid.
$flinders = array(
'type' => 'Point',
'coordinates' => array(144.42486788889, -37.951033416667 )
);
$buninyong = array(
'type' => 'Point',
'coordinates' => array(143.92649552778, -37.652821138889 )
);
var_dump(vincenty($flinders, $buninyong));
### Helmert Transformation
The Helmert transformation allows for the transfomation of points between different datums. It can for instance be used to convert between the WGS84 ellipsoid used by GPS systems and OSGB36 used by ordnance survey in the UK.
$greenwichObservatory = array(
'type' => 'Point',
'coordinates' => array(-0.0014833333333333 , 51.477916666667)
);
$greenwichObservatoryWGS84 = transform_datum($greenwichObservatory, GEO_WGS84, GEO_AIRY_1830);
var_dump($greenwichObservatoryWGS84);