@@ -61,6 +61,18 @@ ZEND_BEGIN_ARG_INFO_EX(change_datum_args, 0, 0, 4)
61
61
ZEND_ARG_INFO (0 , to_reference_ellipsoid )
62
62
ZEND_END_ARG_INFO ()
63
63
64
+ ZEND_BEGIN_ARG_INFO_EX (to_decimal_args , 0 , 0 , 4 )
65
+ ZEND_ARG_INFO (0 , degrees )
66
+ ZEND_ARG_INFO (0 , minutes )
67
+ ZEND_ARG_INFO (0 , seconds )
68
+ ZEND_ARG_INFO (0 , direction )
69
+ ZEND_END_ARG_INFO ()
70
+
71
+ ZEND_BEGIN_ARG_INFO_EX (to_dms_args , 0 , 0 , 2 )
72
+ ZEND_ARG_INFO (0 , decimal )
73
+ ZEND_ARG_INFO (0 , coordinate )
74
+ ZEND_END_ARG_INFO ()
75
+
64
76
/* {{{ geospatial_functions[]
65
77
*
66
78
* Every user visible function must have an entry in geospatial_functions[].
@@ -71,6 +83,8 @@ const zend_function_entry geospatial_functions[] = {
71
83
PHP_FE (polar_to_cartesian , polar_to_cartesian_args )
72
84
PHP_FE (cartesian_to_polar , cartesian_to_polar_args )
73
85
PHP_FE (change_datum , change_datum_args )
86
+ PHP_FE (to_decimal , to_decimal_args )
87
+ PHP_FE (to_dms , to_dms_args )
74
88
/* End of functions */
75
89
{ NULL , NULL , NULL }
76
90
};
@@ -188,7 +202,7 @@ PHP_FUNCTION(helmert)
188
202
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|ll" , & x , & y , & z , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
189
203
return ;
190
204
}
191
- array_init (return_value );\
205
+ array_init (return_value );
192
206
geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
193
207
point = php_helmert (x , y , z , helmert_constants );
194
208
add_assoc_double (return_value , "x" , point .x );
@@ -261,6 +275,53 @@ geo_lat_long php_cartesian_to_polar(double x, double y, double z, geo_ellipsoid
261
275
return polar ;
262
276
}
263
277
278
+ PHP_FUNCTION (to_decimal )
279
+ {
280
+ double degrees , minutes , sign ;
281
+ double seconds , decimal ;
282
+ char * direction ;
283
+ int direction_len ;
284
+
285
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|s" , & degrees , & minutes , & seconds , & direction , & direction_len ) == FAILURE ) {
286
+ return ;
287
+ }
288
+
289
+ sign = strcmp (direction , "S" ) == 0 || strcmp (direction , "W" ) == 0 ? -1 : 1 ;
290
+ decimal = degrees + minutes / 60 + seconds / 3600 ;
291
+ decimal *= sign ;
292
+ RETURN_DOUBLE (decimal );
293
+ }
294
+
295
+
296
+ PHP_FUNCTION (to_dms )
297
+ {
298
+ double decimal , seconds ;
299
+ int degrees , minutes ;
300
+ char * direction ;
301
+ char * coordinate ;
302
+ int coordinate_len ;
303
+
304
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ds" , & decimal , & coordinate , & coordinate_len ) == FAILURE ) {
305
+ return ;
306
+ }
307
+ if (strcmp (coordinate , "longitude" ) == 0 ) {
308
+ direction = decimal < 1 ? "W" : "E" ;
309
+ } else {
310
+ direction = decimal < 1 ? "S" : "N" ;
311
+ }
312
+
313
+ array_init (return_value );
314
+ decimal = fabs (decimal );
315
+ degrees = (int ) decimal ;
316
+ minutes = decimal * 60 - degrees * 60 ;
317
+ seconds = decimal * 3600 - degrees * 3600 - minutes * 60 ;
318
+ seconds = (round (seconds * 100 )) / 100 ;
319
+ add_assoc_long (return_value , "degrees" , degrees );
320
+ add_assoc_long (return_value , "minutes" , minutes );
321
+ add_assoc_double (return_value , "seconds" , seconds );
322
+ add_assoc_string (return_value , "direction" , direction , 1 );
323
+ }
324
+
264
325
PHP_FUNCTION (cartesian_to_polar )
265
326
{
266
327
double x , y , z ;
0 commit comments