Skip to content

Commit 19dc0d0

Browse files
committed
Added documentation for a few more functions
1 parent a91fab2 commit 19dc0d0

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

README.rst

+85-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ geospatial - PHP Geospatial Extension
33
=====================================
44

55
PHP Extension to handle common geospatial functions. The extension currently
6-
has implementations of the Haversine and Vincenty's formulas as well as a
7-
Helmert transformation function.
6+
has implementations of the Haversine and Vincenty's formulas for calculating
7+
distances, an initial bearing calculation function, a Helmert transformation
8+
function to transfer between different supported datums, conversions between
9+
polar and Cartesian coordinates, conversions between Degree/Minute/Seconds and
10+
decimal degrees, a method to simplify linear geometries, as well as a method
11+
to calculate intermediate points on a LineString.
812

913
Instalation
1014
===========
@@ -76,13 +80,89 @@ Helmert Transformation
7680

7781
The Helmert transformation allows for the transformation of points between
7882
different datums. It can for instance be used to convert between the WGS84
79-
ellipsoid used by GPS systems and OSGB36 used by ordnance survey in the UK::
83+
ellipsoid (GEO_WGS84) used by GPS systems and OSGB36 (GEO_AIRY_1830) used by
84+
Ordnance Survey in the UK::
8085

8186
$greenwichObservatory = array(
8287
'type' => 'Point',
8388
'coordinates' => array(-0.0014833333333333 , 51.477916666667)
8489
);
85-
90+
8691
$greenwichObservatoryWGS84 = transform_datum($greenwichObservatory, GEO_WGS84, GEO_AIRY_1830);
87-
92+
8893
var_dump($greenwichObservatoryWGS84);
94+
95+
Converting between polar and Cartesian Coordinates
96+
--------------------------------------------------
97+
98+
These two functions calculate between Polar and Cartesian Coordinates,
99+
with results depending on which ellipsoid you use.
100+
101+
From Polar to Cartesian::
102+
103+
$lat = 53.38361111111;
104+
$long = 1.4669444444;
105+
106+
var_dump(polar_to_cartesian($lat, $long, GEO_AIRY_1830));
107+
108+
And back::
109+
110+
$x = 3810891.6734396;
111+
$y = 97591.624686311;
112+
$z = 5095766.3939034;
113+
114+
$polar = cartesian_to_polar($x, $y, $z, GEO_AIRY_1830);
115+
echo round($polar['lat'], 6), PHP_EOL;
116+
echo round($polar['long'], 6), PHP_EOL;
117+
echo round($polar['height'], 3), PHP_EOL;
118+
119+
Converting between Degree/Min/Sec and Decimal coordinates
120+
---------------------------------------------------------
121+
122+
From decimal to dms. The second argument is either "longitude" or "latitude"::
123+
124+
$dms = decimal_to_dms(-1.034291666667, 'longitude');
125+
var_dump($dms);
126+
127+
Which outputs::
128+
129+
array(4) {
130+
["degrees"]=> int(1)
131+
["minutes"]=> int(2)
132+
["seconds"]=> float(3.4500000011994)
133+
["direction"]=> string(1) "W"
134+
}
135+
136+
And back from DMS to decimal, where the fourth argument is either "N", "S",
137+
"E", or "W"::
138+
139+
$decimal = dms_to_decimal(0, 6, 9, 'S');
140+
141+
Which outputs::
142+
143+
float(-0.1025)
144+
145+
Simplifying LineStrings
146+
-----------------------
147+
148+
The ``rdp_simplify`` method implements RDP_ to simplify a LineString
149+
according to a certain accuracy (epsilon). As first argument it takes a
150+
GeoJSON LineString (in PHP variable format), and it outputs a similar
151+
structure but then simplified
152+
153+
.. _RDP: https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
154+
155+
Interpolation along a Greater Circle Line
156+
-----------------------------------------
157+
158+
The ``fraction_along_gc_line`` function can be used to calculate intermediate
159+
points along a Greater Circle Line. For example if you need to draw lines with
160+
more accuracy with for example Leaflet. The function takes the start and end
161+
coordinates (as GeoJson Point), and calculates the intermediate point along
162+
those line. To calculate the point 25% from the start point to the end point,
163+
you would use::
164+
165+
$point1 = [ 'type' => 'Point', 'coordinates' => [ 5, 10 ] ];
166+
$point2 = [ 'type' => 'Point', 'coordinates' => [ 15, 10 ] ];
167+
168+
var_dump(fraction_along_gc_line($point1, $point2, 0.25));

0 commit comments

Comments
 (0)