Skip to content

Commit adb793f

Browse files
committed
Add tests and documentation for 'interpolate_linestring'
1 parent 0e64038 commit adb793f

6 files changed

+386
-10
lines changed

README.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,33 @@ you would use::
189189

190190
var_dump(fraction_along_gc_line($point1, $point2, 0.25));
191191

192+
Interpolating a GeoJSONLineString
193+
---------------------------------
194+
195+
The ``interpolate_linestring`` functions takes a GeoJSONLineString. If the
196+
Pythagorean distance in degrees between two points in the line than the
197+
``epsilon`` value, it inserts a new point every ``epsilon / distance``
198+
fraction of the Great Circle Line.
199+
200+
Given the Linestring::
201+
202+
$lineString = [
203+
'type' => 'Linestring',
204+
'coordinates' => [
205+
[ 5, 10 ],
206+
[ 15, 10 ],
207+
[ 0, -50 ],
208+
]
209+
];
210+
211+
The following will return an array with 26 elements::
212+
213+
var_dump(interpolate_linestring($lineString, 3));
214+
215+
Five for the first pair, at fractions ``0.0``, ``0.3``, ``0.6``, ``0.9`` and
216+
``1.0``, and then two times, each another ``0.0485`` fraction along the Great
217+
Circle Line for the second pair.
218+
192219
Geohashing
193220
----------
194221

php_geospatial.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ function haversine(array $from, array $to, float $radius = GEO_EARTH_RADIUS): fl
3838
function vincenty(array $from, array $to, float $reference_ellipsoid = GEO_WGS84): float {}
3939

4040
function fraction_along_gc_line(array $from, array $to, float $fraction): array {}
41+
function interpolate_linestring(array $line, float $epsilon): array {}
42+
4143
function initial_bearing(array $from, array $to): float {}
4244

4345
function rdp_simplify(array $points, float $epsilon): array {}
4446

45-
function interpolate_linestring(array $line, float $epsilon): array {}
46-
4747
function geohash_encode(array $point, int $precision = 12): string {}
4848
function geohash_decode(string $geohash): array {}

php_geospatial_arginfo.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 52022e47a6841ea20db60c2c92eba319cfc6c563 */
2+
* Stub hash: 0fadd3390095e7624d9586206523e5352d345729 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dms_to_decimal, 0, 3, IS_DOUBLE, 0)
55
ZEND_ARG_TYPE_INFO(0, degrees, IS_DOUBLE, 0)
@@ -58,6 +58,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_fraction_along_gc_line, 0, 3, IS
5858
ZEND_ARG_TYPE_INFO(0, fraction, IS_DOUBLE, 0)
5959
ZEND_END_ARG_INFO()
6060

61+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_interpolate_linestring, 0, 2, IS_ARRAY, 0)
62+
ZEND_ARG_TYPE_INFO(0, line, IS_ARRAY, 0)
63+
ZEND_ARG_TYPE_INFO(0, epsilon, IS_DOUBLE, 0)
64+
ZEND_END_ARG_INFO()
65+
6166
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_initial_bearing, 0, 2, IS_DOUBLE, 0)
6267
ZEND_ARG_TYPE_INFO(0, from, IS_ARRAY, 0)
6368
ZEND_ARG_TYPE_INFO(0, to, IS_ARRAY, 0)
@@ -68,11 +73,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rdp_simplify, 0, 2, IS_ARRAY, 0)
6873
ZEND_ARG_TYPE_INFO(0, epsilon, IS_DOUBLE, 0)
6974
ZEND_END_ARG_INFO()
7075

71-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_interpolate_linestring, 0, 2, IS_ARRAY, 0)
72-
ZEND_ARG_TYPE_INFO(0, line, IS_ARRAY, 0)
73-
ZEND_ARG_TYPE_INFO(0, epsilon, IS_DOUBLE, 0)
74-
ZEND_END_ARG_INFO()
75-
7676
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_geohash_encode, 0, 1, IS_STRING, 0)
7777
ZEND_ARG_TYPE_INFO(0, point, IS_ARRAY, 0)
7878
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, precision, IS_LONG, 0, "12")
@@ -92,9 +92,9 @@ ZEND_FUNCTION(transform_datum);
9292
ZEND_FUNCTION(haversine);
9393
ZEND_FUNCTION(vincenty);
9494
ZEND_FUNCTION(fraction_along_gc_line);
95+
ZEND_FUNCTION(interpolate_linestring);
9596
ZEND_FUNCTION(initial_bearing);
9697
ZEND_FUNCTION(rdp_simplify);
97-
ZEND_FUNCTION(interpolate_linestring);
9898
ZEND_FUNCTION(geohash_encode);
9999
ZEND_FUNCTION(geohash_decode);
100100

@@ -109,9 +109,9 @@ static const zend_function_entry ext_functions[] = {
109109
ZEND_FE(haversine, arginfo_haversine)
110110
ZEND_FE(vincenty, arginfo_vincenty)
111111
ZEND_FE(fraction_along_gc_line, arginfo_fraction_along_gc_line)
112+
ZEND_FE(interpolate_linestring, arginfo_interpolate_linestring)
112113
ZEND_FE(initial_bearing, arginfo_initial_bearing)
113114
ZEND_FE(rdp_simplify, arginfo_rdp_simplify)
114-
ZEND_FE(interpolate_linestring, arginfo_interpolate_linestring)
115115
ZEND_FE(geohash_encode, arginfo_geohash_encode)
116116
ZEND_FE(geohash_decode, arginfo_geohash_decode)
117117
ZEND_FE_END
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
--TEST--
2+
Test for "interpolate_linestring" #1
3+
--FILE--
4+
<?php
5+
$lineString = [
6+
'type' => 'Linestring',
7+
'coordinates' => [
8+
[ 5, 10 ],
9+
[ 15, 10 ],
10+
[ 0, -50 ],
11+
]
12+
];
13+
14+
var_dump(interpolate_linestring($lineString, 3));
15+
?>
16+
--EXPECTF--
17+
array(26) {
18+
[0]=>
19+
array(2) {
20+
[0]=>
21+
float(5)
22+
[1]=>
23+
float(10)
24+
}
25+
[1]=>
26+
array(2) {
27+
[0]=>
28+
float(7.9998706635703245)
29+
[1]=>
30+
float(10.03143197167244)
31+
}
32+
[2]=>
33+
array(2) {
34+
[0]=>
35+
float(11.000073920872426)
36+
[1]=>
37+
float(10.035925156338873)
38+
}
39+
[3]=>
40+
array(2) {
41+
[0]=>
42+
float(14.000110773799255)
43+
[1]=>
44+
float(10.013466491669567)
45+
}
46+
[4]=>
47+
array(2) {
48+
[0]=>
49+
float(14.999999999999998)
50+
[1]=>
51+
float(10)
52+
}
53+
[5]=>
54+
array(2) {
55+
[0]=>
56+
float(14.431497984318062)
57+
[1]=>
58+
float(7.0743500242581225)
59+
}
60+
[6]=>
61+
array(2) {
62+
[0]=>
63+
float(13.87016260996529)
64+
[1]=>
65+
float(4.148019326790382)
66+
}
67+
[7]=>
68+
array(2) {
69+
[0]=>
70+
float(13.312974140472463)
71+
[1]=>
72+
float(1.221294808989993)
73+
}
74+
[8]=>
75+
array(2) {
76+
[0]=>
77+
float(12.756998952507347)
78+
[1]=>
79+
float(-1.7055449208364544)
80+
}
81+
[9]=>
82+
array(2) {
83+
[0]=>
84+
float(12.199328445763877)
85+
[1]=>
86+
float(-4.632223663590317)
87+
}
88+
[10]=>
89+
array(2) {
90+
[0]=>
91+
float(11.63701903368877)
92+
[1]=>
93+
float(-7.55846185163128)
94+
}
95+
[11]=>
96+
array(2) {
97+
[0]=>
98+
float(11.067030621797189)
99+
[1]=>
100+
float(-10.483970622513857)
101+
}
102+
[12]=>
103+
array(2) {
104+
[0]=>
105+
float(10.486160869758637)
106+
[1]=>
107+
float(-13.408445478413974)
108+
}
109+
[13]=>
110+
array(2) {
111+
[0]=>
112+
float(9.890972221197222)
113+
[1]=>
114+
float(-16.331559233911236)
115+
}
116+
[14]=>
117+
array(2) {
118+
[0]=>
119+
float(9.277708136408956)
120+
[1]=>
121+
float(-19.252953899216553)
122+
}
123+
[15]=>
124+
array(2) {
125+
[0]=>
126+
float(8.642194115015831)
127+
[1]=>
128+
float(-22.172231059691807)
129+
}
130+
[16]=>
131+
array(2) {
132+
[0]=>
133+
float(7.979717846837639)
134+
[1]=>
135+
float(-25.08894018486976)
136+
}
137+
[17]=>
138+
array(2) {
139+
[0]=>
140+
float(7.284881023816488)
141+
[1]=>
142+
float(-28.002564114424196)
143+
}
144+
[18]=>
145+
array(2) {
146+
[0]=>
147+
float(6.55141274516024)
148+
[1]=>
149+
float(-30.91250069881375)
150+
}
151+
[19]=>
152+
array(2) {
153+
[0]=>
154+
float(5.771930687062061)
155+
[1]=>
156+
float(-33.81803917851203)
157+
}
158+
[20]=>
159+
array(2) {
160+
[0]=>
161+
float(4.937630724808758)
162+
[1]=>
163+
float(-36.718329304916004)
164+
}
165+
[21]=>
166+
array(2) {
167+
[0]=>
168+
float(4.037877612215368)
169+
[1]=>
170+
float(-39.61234033808264)
171+
}
172+
[22]=>
173+
array(2) {
174+
[0]=>
175+
float(3.059657259010722)
176+
[1]=>
177+
float(-42.49880573947054)
178+
}
179+
[23]=>
180+
array(2) {
181+
[0]=>
182+
float(1.9868328958488306)
183+
[1]=>
184+
float(-45.37614734526896)
185+
}
186+
[24]=>
187+
array(2) {
188+
[0]=>
189+
float(0.7991194226357126)
190+
[1]=>
191+
float(-48.2423696103279)
192+
}
193+
[25]=>
194+
array(2) {
195+
[0]=>
196+
float(0)
197+
[1]=>
198+
float(-50)
199+
}
200+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
Test for "interpolate_linestring" #2
3+
--FILE--
4+
<?php
5+
$lineString = [
6+
'type' => 'Linestring',
7+
'coordinates' => [
8+
[ 0, 0 ],
9+
[ 90, 0 ],
10+
]
11+
];
12+
13+
var_dump(interpolate_linestring($lineString, 20));
14+
?>
15+
--EXPECTF--
16+
array(6) {
17+
[0]=>
18+
array(2) {
19+
[0]=>
20+
float(0)
21+
[1]=>
22+
float(0)
23+
}
24+
[1]=>
25+
array(2) {
26+
[0]=>
27+
float(19.999999999999996)
28+
[1]=>
29+
float(0)
30+
}
31+
[2]=>
32+
array(2) {
33+
[0]=>
34+
float(40.00000000000001)
35+
[1]=>
36+
float(0)
37+
}
38+
[3]=>
39+
array(2) {
40+
[0]=>
41+
float(59.99999999999999)
42+
[1]=>
43+
float(0)
44+
}
45+
[4]=>
46+
array(2) {
47+
[0]=>
48+
float(80)
49+
[1]=>
50+
float(0)
51+
}
52+
[5]=>
53+
array(2) {
54+
[0]=>
55+
float(90)
56+
[1]=>
57+
float(0)
58+
}
59+
}

0 commit comments

Comments
 (0)