Skip to content

Commit 8677e05

Browse files
author
Nathaniel McHugh
committed
first draft at a helmert transformation
1 parent 768f82d commit 8677e05

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

geospatial.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ ZEND_BEGIN_ARG_INFO_EX(haversine_args, 0, 0, 4)
3535
ZEND_ARG_INFO(0, radius)
3636
ZEND_END_ARG_INFO()
3737

38+
ZEND_BEGIN_ARG_INFO_EX(helmert_args, 0, 0, 3)
39+
ZEND_ARG_INFO(0, x)
40+
ZEND_ARG_INFO(0, y)
41+
ZEND_ARG_INFO(0, z)
42+
ZEND_END_ARG_INFO()
43+
3844
/* {{{ geospatial_functions[]
3945
*
4046
* Every user visible function must have an entry in geospatial_functions[].
4147
*/
4248
const zend_function_entry geospatial_functions[] = {
43-
PHP_FE(haversine, haversine_args)
49+
PHP_FE(haversine, haversine_args)
50+
PHP_FE(helmert, helmert_args)
51+
/* End of functions */
4452
{ NULL, NULL, NULL }
4553
};
4654
/* }}} */
@@ -97,6 +105,46 @@ PHP_MINFO_FUNCTION(geospatial)
97105
}
98106
/* }}} */
99107

108+
PHP_FUNCTION(helmert)
109+
{
110+
double x, y, z;
111+
double xOut, yOut, zOut;
112+
double rX, rY, rZ;
113+
114+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddd", &x, &y, &z) == FAILURE) {
115+
return;
116+
}
117+
118+
array_init(return_value);
119+
rX = ROTATION_X;
120+
rX /= 3600;
121+
rX *= GEO_DEG_TO_RAD;
122+
123+
rY = ROTATION_Y;
124+
rY /= 3600;
125+
rY *= GEO_DEG_TO_RAD;
126+
127+
rZ = ROTATION_Z;
128+
rZ /= 3600;
129+
rZ *= GEO_DEG_TO_RAD;
130+
131+
xOut = x - (rZ * y) + (rY * z);
132+
xOut *= SCALE_CHANGE;
133+
xOut += WGS84_OSGB36_X;
134+
135+
yOut = (rZ * x) + y - (rX * z);
136+
yOut *= SCALE_CHANGE;
137+
yOut += WGS84_OSGB36_Y;
138+
139+
zOut = (-rY * x) + (rX * y) + z;
140+
zOut *= SCALE_CHANGE;
141+
zOut += WGS84_OSGB36_Z;
142+
143+
add_next_index_double(return_value, xOut);
144+
add_next_index_double(return_value, yOut);
145+
add_next_index_double(return_value, zOut);
146+
}
147+
100148
/* {{{ proto haversine(double fromLat, double fromLong, double toLat, double toLong [, double radius ])
101149
* Calculates the greater circle distance between the two lattitude/longitude pairs */
102150
PHP_FUNCTION(haversine)

php_geospatial.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,25 @@ extern zend_module_entry geospatial_module_entry;
4343
*/
4444
#define GEO_EARTH_RADIUS 6378.137
4545

46+
#define AIRY_1830_A 6377563.396
47+
#define AIRY_1830_B 6356256.910
48+
49+
#define WGS84_OSGB36_X -446.448;
50+
#define WGS84_OSGB36_Y 125.157;
51+
#define WGS84_OSGB36_Z -542.060;
52+
53+
#define SCALE_CHANGE 1.0000204894;
54+
55+
#define ROTATION_X -0.1502;
56+
#define ROTATION_Y -0.2470;
57+
#define ROTATION_Z -0.8421;
58+
59+
4660
PHP_MINIT_FUNCTION(geospatial);
4761
PHP_MINFO_FUNCTION(geospatial);
4862

4963
PHP_FUNCTION(haversine);
64+
PHP_FUNCTION(helmert);
5065

5166
#endif /* PHP_GEOSPATIAL_H */
5267

tests/helmert.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
helmert() function - basic test for helmert forumla
3+
--FILE--
4+
<?php
5+
$x = 3909833.018;
6+
$y = -147097.1376;
7+
$z = 5020322.478;
8+
9+
var_dump(helmert($x, $y, $z));
10+
?>
11+
--EXPECT--
12+
array(3) {
13+
[0]=>
14+
float(3909460.068)
15+
[1]=>
16+
float(-146987.30)
17+
[2]=>
18+
float(5019888.07)
19+
}

0 commit comments

Comments
 (0)