@@ -143,24 +143,35 @@ geo_ellipsoid get_ellipsoid(long ellipsoid_const)
143
143
}
144
144
}
145
145
146
- geo_cartesian php_helmert (double x , double y , double z )
146
+ geo_helmert_constants get_helmert_constants (long from , long to )
147
+ {
148
+ switch (from - to ) {
149
+ case 1 :
150
+ return osgb36_wgs84 ;
151
+ break ;
152
+ default :
153
+ case -1 :
154
+ return wgs84_osgb36 ;
155
+ break ;
156
+ }
157
+ }
158
+
159
+ geo_cartesian php_helmert (double x , double y , double z , geo_helmert_constants helmet_consts )
147
160
{
148
161
double rX , rY , rZ ;
149
162
double xOut , yOut , zOut ;
163
+ double scale_change ;
150
164
geo_cartesian point ;
165
+ scale_change = 1 + (helmet_consts .scale_change );
166
+ rX = helmet_consts .rotation_x / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
167
+ rY = helmet_consts .rotation_y / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
168
+ rZ = helmet_consts .rotation_z / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
151
169
152
- rX = ROTATION_X / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
153
- rY = ROTATION_Y / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
154
- rZ = ROTATION_Z / GEO_SEC_IN_DEG * GEO_DEG_TO_RAD ;
170
+ xOut = helmet_consts .translation_x + ((x - (rZ * y ) + (rY * z )) * scale_change );
155
171
156
- xOut = WGS84_OSGB36_X ;
157
- xOut += (x - (rZ * y ) + (rY * z )) * SCALE_CHANGE ;
172
+ yOut = helmet_consts .translation_y + (((rZ * x ) + y - (rX * z )) * scale_change );
158
173
159
- yOut = WGS84_OSGB36_Y ;
160
- yOut += ((rZ * x ) + y - (rX * z )) * SCALE_CHANGE ;
161
-
162
- zOut = WGS84_OSGB36_Z ;
163
- zOut += ((-1 * rY * x ) + (rX * y ) + z ) * SCALE_CHANGE ;
174
+ zOut = helmet_consts .translation_z + (((-1 * rY * x ) + (rX * y ) + z ) * scale_change );
164
175
165
176
point .x = xOut ;
166
177
point .y = yOut ;
@@ -173,12 +184,13 @@ PHP_FUNCTION(helmert)
173
184
{
174
185
double x , y , z ;
175
186
geo_cartesian point ;
176
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd" , & x , & y , & z ) == FAILURE ) {
187
+ long from_reference_ellipsoid , to_reference_ellipsoid ;
188
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|ll" , & x , & y , & z , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
177
189
return ;
178
190
}
179
-
180
- array_init ( return_value );
181
- point = php_helmert (x , y , z );
191
+ array_init ( return_value );\
192
+ geo_helmert_constants helmert_constants = get_helmert_constants ( from_reference_ellipsoid , to_reference_ellipsoid );
193
+ point = php_helmert (x , y , z , helmert_constants );
182
194
add_assoc_double (return_value , "x" , point .x );
183
195
add_assoc_double (return_value , "y" , point .y );
184
196
add_assoc_double (return_value , "z" , point .z );
@@ -267,9 +279,6 @@ PHP_FUNCTION(cartesian_to_polar)
267
279
}
268
280
269
281
270
-
271
-
272
-
273
282
PHP_FUNCTION (change_datum )
274
283
{
275
284
double latitude , longitude ;
@@ -282,7 +291,8 @@ PHP_FUNCTION(change_datum)
282
291
geo_ellipsoid eli_from = get_ellipsoid (from_reference_ellipsoid );
283
292
geo_ellipsoid eli_to = get_ellipsoid (to_reference_ellipsoid );
284
293
point = php_polar_to_cartesian (latitude , longitude , eli_from );
285
- converted_point = php_helmert (point .x , point .y , point .z );
294
+ geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
295
+ converted_point = php_helmert (point .x , point .y , point .z , helmert_constants );
286
296
polar = php_cartesian_to_polar (converted_point .x , converted_point .y , converted_point .z , eli_to );
287
297
288
298
array_init (return_value );
0 commit comments