-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-2.3.php
executable file
·214 lines (173 loc) · 7.38 KB
/
test-2.3.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
//--------------------------------------------------------------------------
// PHPcoord
// text.php
//
// (c) 2005 Jonathan Stott
//
// Created on 11-Aug-2005
//
// 2.3 - 24 Aug 2006
// - Changed OSRef->toSixFigureString() so that the eastings and northings
// are rounded rather than floored.
// 2.2 - 11 Feb 2006
// - Used different algorithm for calculating distance between latitudes
// and longitudes - fixes a number of problems with distance calculations
// 2.1 - 22 Dec 2005
// - Added getOSRefFromSixFigureReference function
// 2.0 - 21 Dec 2005
// - Completely different object design - conversion functions now through
// objects rather than static functions
// - Updated comments and documentation
// 1.1 - 11 Sep 2005
// - Added OSGB36/WGS84 data conversions
// 1.0 - 11 Aug 2005
// - Initial version
//--------------------------------------------------------------------------
require_once("vendor/autoload.php");
use Phpcoord\OSRef;
use Phpcoord\UTMRef;
use Phpcoord\LatLng;
///////////////////////////////////////////////////////////////////////////////////////////
//// I haven't tested whether this page works after conversion to composer package !!! ////
///////////////////////////////////////////////////////////////////////////////////////////
?>
<html>
<head>
<title>phpcoord Test Script</title>
</head>
<body>
<h1>phpcoord Test Script</h1>
<h2>Calculate Surface Distance between two Latitudes/Longitudes</h2>
<p>
The LatLngDistance function takes two latitudes/longitudes and calculates
the surface distance between the two in kilometres:
</p>
<p>
<pre>$lld1 = new LatLng(40.718119, -73.995667); // New York
echo "New York Lat/Long: " . $lld1->toString() . "<br />";
$lld2 = new LatLng(51.499981, -0.125313); // London
$d = $lld1->distance($lld2);
echo "Surface Distance between New York and London: " . $d . "km";</pre>
<?php
$lld1 = new LatLng(40.718119, -73.995667); // New York
echo "New York Lat/Long: " . $lld1->toString() . "<br />";
$lld2 = new LatLng(51.499981, -0.125313); // London
echo "London Lat/Long: " . $lld2->toString() . "<br />";
$d = $lld1->distance($lld2);
echo "Surface Distance between New York and London: " . $d . "km";
?>
</p>
<h2>Convert OS Grid Reference to Latitude/Longitude</h2>
<p>
Note that the OSGB-Latitude/Longitude conversions use the OSGB36 datum by default. The
majority of applications use the WGS84 datum, for which the appropriate conversions
need to be added. See the examples below to see the difference between the two data.
</p>
<p>
Using OSGB36 (convert an OSGB grid reference to a latitude and longitude using the OSGB36 datum):
<pre>$os1 = new OSRef(651409.903, 313177.270);
echo "OS Grid Reference: " . $os1->toString() . " - " . $os1->toSixFigureString() . "<br />";
$ll1 = $os1->toLatLng();
echo "Converted to Lat/Long: " . $ll1->toString();</pre>
<?php
$os1 = new OSRef(651409.903, 313177.270);
echo "OS Grid Reference: " . $os1->toString() . " - " . $os1->toSixFigureString() . "<br />";
$ll1 = $os1->toLatLng();
echo "Converted to Lat/Long: " . $ll1->toString();
?>
</p>
<p>
Using WGS84 (convert an OSGB grid reference to a latitude and longitude using the WGS84 datum):
<pre>$os1w = new OSRef(651409.903, 313177.270);
echo "OS Grid Reference: " . $os1w->toString() . " - " . $os1w->toSixFigureString() . "<br />";
$l1w = $os1w->toLatLng();
$l1w->OSGB36ToWGS84();
echo "Converted to Lat/Long: " . $ll1w->toString();</pre>
<?php
$os1w = new OSRef(651409.903, 313177.270);
echo "OS Grid Reference: " . $os1w->toString() . " - " . $os1w->toSixFigureString() . "<br />";
$ll1w = $os1w->toLatLng();
$ll1w->OSGB36ToWGS84();
echo "Converted to Lat/Long: " . $ll1w->toString();
?>
</p>
<h2>Convert Latitude/Longitude to OS Grid Reference</h2>
<p>
Note that the OSGB-Latitude/Longitude conversions use the OSGB36 datum by default. The
majority of applications use the WGS84 datum, for which the appropriate conversions
need to be added. See the examples below to see the difference between the two data.
</p>
<p>
Using OSGB36 (convert a latitude and longitude using the OSGB36 datum to an OSGB grid reference):
<pre>$ll2 = new LatLng(52.657570301933, 1.7179215806451);
echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
$os2 = $ll2->toOSRef();
echo "Converted to OS Grid Ref: " . $os2->toString() . " - " . $os2->toSixFigureString();</pre>
<?php
$ll2 = new LatLng(52.657570301933, 1.7179215806451);
echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
$os2 = $ll2->toOSRef();
echo "Converted to OS Grid Ref: " . $os2->toString() . " - " . $os2->toSixFigureString();
?>
</p>
<p>
Using WGS84 (convert a latitude and longitude using the WGS84 datum to an OSGB grid reference):
<pre>$ll2w = new LatLng(52.657570301933, 1.7179215806451);
echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
$ll2w->WGS84ToOSGB36();
$os2w = $ll2w->toOSRef();
echo "Converted to OS Grid Ref: " . $os2w->toString() . " - " . $os2w->toSixFigureString();</pre>
<?php
$ll2w = new LatLng(52.657570301933, 1.7179215806451);
echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
$ll2w->WGS84ToOSGB36();
$os2w = $ll2w->toOSRef();
echo "Converted to OS Grid Ref: " . $os2w->toString() . " - " . $os2w->toSixFigureString();
?>
</p>
<h2>Convert Six-Figure OS Grid Reference String to an OSRef Object</h2>
<p>
To convert a string representing a six-figure OSGB grid reference:
<pre>$os6 = "TG514131";
echo "Six figure string: " . $os6 . "<br />";
$os6x = getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();</pre>
<?php
$os6 = "TG514131";
echo "Six figure string: " . $os6 . "<br />";
$os6x = OSRef::getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();
?>
</p>
<h2>Convert UTM Reference to Latitude/Longitude</h2>
<p>
<pre>$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "<br />";
$ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();</pre>
<?php
$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "<br />";
$ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();
?>
</p>
<h2>Convert Latitude/Longitude to UTM Reference</h2>
<p>
<pre>$ll4 = new LatLng(-60.1167, -111.7833);
echo "Latitude/Longitude: " . $ll4->toString() . "<br />";
$utm2 = $ll4->toUTMRef();
echo "Converted to UTM Ref: " . $utm2->toString() ;</pre>
<?php
$ll4 = new LatLng(-60.1167, -111.7833);
echo "Latitude/Longitude: " . $ll4->toString() . "<br />";
$utm2 = $ll4->toUTMRef();
echo "Converted to UTM Ref: " . $utm2->toString() ;
?>
</p>
<p>
(c) 2005, Jonathan Stott
</p>
</body>
</html>