@@ -54,21 +54,21 @@ ZEND_BEGIN_ARG_INFO_EX(cartesian_to_polar_args, 0, 0, 4)
54
54
ZEND_ARG_INFO (0 , reference_ellipsoid )
55
55
ZEND_END_ARG_INFO ()
56
56
57
- ZEND_BEGIN_ARG_INFO_EX (change_datum_args , 0 , 0 , 4 )
57
+ ZEND_BEGIN_ARG_INFO_EX (transform_datum_args , 0 , 0 , 4 )
58
58
ZEND_ARG_INFO (0 , latitude )
59
59
ZEND_ARG_INFO (0 , longitude )
60
60
ZEND_ARG_INFO (0 , from_reference_ellipsoid )
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 )
64
+ ZEND_BEGIN_ARG_INFO_EX (dms_to_decimal_args , 0 , 0 , 4 )
65
65
ZEND_ARG_INFO (0 , degrees )
66
66
ZEND_ARG_INFO (0 , minutes )
67
67
ZEND_ARG_INFO (0 , seconds )
68
68
ZEND_ARG_INFO (0 , direction )
69
69
ZEND_END_ARG_INFO ()
70
70
71
- ZEND_BEGIN_ARG_INFO_EX (to_dms_args , 0 , 0 , 2 )
71
+ ZEND_BEGIN_ARG_INFO_EX (decimal_to_dms_args , 0 , 0 , 2 )
72
72
ZEND_ARG_INFO (0 , decimal )
73
73
ZEND_ARG_INFO (0 , coordinate )
74
74
ZEND_END_ARG_INFO ()
@@ -82,9 +82,9 @@ const zend_function_entry geospatial_functions[] = {
82
82
PHP_FE (helmert , helmert_args )
83
83
PHP_FE (polar_to_cartesian , polar_to_cartesian_args )
84
84
PHP_FE (cartesian_to_polar , cartesian_to_polar_args )
85
- PHP_FE (change_datum , change_datum_args )
86
- PHP_FE (to_decimal , to_decimal_args )
87
- PHP_FE (to_dms , to_dms_args )
85
+ PHP_FE (transform_datum , transform_datum_args )
86
+ PHP_FE (dms_to_decimal , dms_to_decimal_args )
87
+ PHP_FE (decimal_to_dms , decimal_to_dms_args )
88
88
/* End of functions */
89
89
{ NULL , NULL , NULL }
90
90
};
@@ -170,7 +170,7 @@ geo_helmert_constants get_helmert_constants(long from, long to)
170
170
}
171
171
}
172
172
173
- geo_cartesian php_helmert (double x , double y , double z , geo_helmert_constants helmet_consts )
173
+ geo_cartesian helmert (double x , double y , double z , geo_helmert_constants helmet_consts )
174
174
{
175
175
double rX , rY , rZ ;
176
176
double xOut , yOut , zOut ;
@@ -193,24 +193,7 @@ geo_cartesian php_helmert(double x, double y, double z, geo_helmert_constants he
193
193
return point ;
194
194
}
195
195
196
-
197
- PHP_FUNCTION (helmert )
198
- {
199
- double x , y , z ;
200
- geo_cartesian point ;
201
- long from_reference_ellipsoid , to_reference_ellipsoid ;
202
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|ll" , & x , & y , & z , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
203
- return ;
204
- }
205
- array_init (return_value );
206
- geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
207
- point = php_helmert (x , y , z , helmert_constants );
208
- add_assoc_double (return_value , "x" , point .x );
209
- add_assoc_double (return_value , "y" , point .y );
210
- add_assoc_double (return_value , "z" , point .z );
211
- }
212
-
213
- geo_cartesian php_polar_to_cartesian (double latitude , double longitude , geo_ellipsoid eli )
196
+ geo_cartesian polar_to_cartesian (double latitude , double longitude , geo_ellipsoid eli )
214
197
{
215
198
double x , y , z ;
216
199
@@ -231,24 +214,8 @@ geo_cartesian php_polar_to_cartesian(double latitude, double longitude, geo_elli
231
214
return point ;
232
215
}
233
216
234
- PHP_FUNCTION (polar_to_cartesian )
235
- {
236
- double latitude , longitude ;
237
- long reference_ellipsoid ;
238
- geo_cartesian point ;
239
-
240
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "dd|l" , & latitude , & longitude , & reference_ellipsoid ) == FAILURE ) {
241
- return ;
242
- }
243
- geo_ellipsoid eli = get_ellipsoid (reference_ellipsoid );
244
- array_init (return_value );
245
- point = php_polar_to_cartesian (latitude , longitude , eli );
246
- add_assoc_double (return_value , "x" , point .x );
247
- add_assoc_double (return_value , "y" , point .y );
248
- add_assoc_double (return_value , "z" , point .z );
249
- }
250
217
251
- geo_lat_long php_cartesian_to_polar (double x , double y , double z , geo_ellipsoid eli )
218
+ geo_lat_long cartesian_to_polar (double x , double y , double z , geo_ellipsoid eli )
252
219
{
253
220
254
221
double latitude , longitude ;
@@ -275,25 +242,32 @@ geo_lat_long php_cartesian_to_polar(double x, double y, double z, geo_ellipsoid
275
242
return polar ;
276
243
}
277
244
278
- PHP_FUNCTION (to_decimal )
245
+ /* {{{ proto dms_to_decimal(double degrees, double minutes, double seconds [,string direction])
246
+ * Convert degrees, minutes & seconds values to decimal degrees */
247
+ PHP_FUNCTION (dms_to_decimal )
279
248
{
280
249
double degrees , minutes , sign ;
281
250
double seconds , decimal ;
282
- char * direction ;
251
+ char * direction = "" ;
283
252
int direction_len ;
284
253
285
254
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|s" , & degrees , & minutes , & seconds , & direction , & direction_len ) == FAILURE ) {
286
255
return ;
287
256
}
288
-
289
- sign = strcmp (direction , "S" ) == 0 || strcmp (direction , "W" ) == 0 ? -1 : 1 ;
290
- decimal = degrees + minutes / 60 + seconds / 3600 ;
257
+ if (strcmp ("" , direction ) == 0 ) {
258
+ sign = degrees > 1 ? 1 : -1 ;
259
+ } else {
260
+ sign = strcmp (direction , "S" ) == 0 || strcmp (direction , "W" ) == 0 ? -1 : 1 ;
261
+ }
262
+ decimal = abs (degrees ) + minutes / 60 + seconds / 3600 ;
291
263
decimal *= sign ;
292
264
RETURN_DOUBLE (decimal );
293
265
}
266
+ /* }}} */
294
267
295
-
296
- PHP_FUNCTION (to_dms )
268
+ /* {{{ proto decimal_to_dms(double decimal, string coordinate)
269
+ * Convert decimal degrees value to whole degrees and minutes and decimal seconds */
270
+ PHP_FUNCTION (decimal_to_dms )
297
271
{
298
272
double decimal , seconds ;
299
273
int degrees , minutes ;
@@ -315,13 +289,54 @@ PHP_FUNCTION(to_dms)
315
289
degrees = (int ) decimal ;
316
290
minutes = decimal * 60 - degrees * 60 ;
317
291
seconds = decimal * 3600 - degrees * 3600 - minutes * 60 ;
318
- seconds = (round (seconds * 100 )) / 100 ;
319
292
add_assoc_long (return_value , "degrees" , degrees );
320
293
add_assoc_long (return_value , "minutes" , minutes );
321
294
add_assoc_double (return_value , "seconds" , seconds );
322
295
add_assoc_string (return_value , "direction" , direction , 1 );
323
296
}
297
+ /* }}} */
298
+
299
+ /* {{{ proto helmert(double x, double y, double z [, long from_reference_ellipsoid, long to_reference_ellipsoid])
300
+ * Convert polar ones (latitude, longitude) tp cartesian co-ordiantes (x, y, z) */
301
+ PHP_FUNCTION (helmert )
302
+ {
303
+ double x , y , z ;
304
+ geo_cartesian point ;
305
+ long from_reference_ellipsoid , to_reference_ellipsoid ;
306
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|ll" , & x , & y , & z , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
307
+ return ;
308
+ }
309
+ array_init (return_value );
310
+ geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
311
+ point = helmert (x , y , z , helmert_constants );
312
+ add_assoc_double (return_value , "x" , point .x );
313
+ add_assoc_double (return_value , "y" , point .y );
314
+ add_assoc_double (return_value , "z" , point .z );
315
+ }
316
+ /* }}} */
317
+
318
+ /* {{{ proto polar_to_cartesian(double latitude, double longitude[, long reference_ellipsoid])
319
+ * Convert polar ones (latitude, longitude) tp cartesian co-ordiantes (x, y, z) */
320
+ PHP_FUNCTION (polar_to_cartesian )
321
+ {
322
+ double latitude , longitude ;
323
+ long reference_ellipsoid ;
324
+ geo_cartesian point ;
325
+
326
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "dd|l" , & latitude , & longitude , & reference_ellipsoid ) == FAILURE ) {
327
+ return ;
328
+ }
329
+ geo_ellipsoid eli = get_ellipsoid (reference_ellipsoid );
330
+ array_init (return_value );
331
+ point = polar_to_cartesian (latitude , longitude , eli );
332
+ add_assoc_double (return_value , "x" , point .x );
333
+ add_assoc_double (return_value , "y" , point .y );
334
+ add_assoc_double (return_value , "z" , point .z );
335
+ }
336
+ /* }}} */
324
337
338
+ /* {{{ proto cartesian_to_polar(double x, double y, double z [, long reference_ellipsoid])
339
+ * Convert cartesian co-ordiantes (x, y, z) to polar ones (latitude, longitude) */
325
340
PHP_FUNCTION (cartesian_to_polar )
326
341
{
327
342
double x , y , z ;
@@ -333,14 +348,17 @@ PHP_FUNCTION(cartesian_to_polar)
333
348
}
334
349
geo_ellipsoid eli = get_ellipsoid (reference_ellipsoid );
335
350
array_init (return_value );
336
- polar = php_cartesian_to_polar (x , y , z , eli );
351
+ polar = cartesian_to_polar (x , y , z , eli );
337
352
add_assoc_double (return_value , "lat" , polar .latitude );
338
353
add_assoc_double (return_value , "long" , polar .longitude );
339
354
add_assoc_double (return_value , "height" , polar .height );
340
355
}
356
+ /* }}} */
341
357
342
358
343
- PHP_FUNCTION (change_datum )
359
+ /* {{{ proto transform_datum(double latitude, double longitude, long from_reference_ellipsoid, long to_reference_ellipsoid)
360
+ * Unified function to transform projection of geo-cordinates between datums */
361
+ PHP_FUNCTION (transform_datum )
344
362
{
345
363
double latitude , longitude ;
346
364
long from_reference_ellipsoid , to_reference_ellipsoid ;
@@ -351,16 +369,17 @@ PHP_FUNCTION(change_datum)
351
369
}
352
370
geo_ellipsoid eli_from = get_ellipsoid (from_reference_ellipsoid );
353
371
geo_ellipsoid eli_to = get_ellipsoid (to_reference_ellipsoid );
354
- point = php_polar_to_cartesian (latitude , longitude , eli_from );
372
+ point = polar_to_cartesian (latitude , longitude , eli_from );
355
373
geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
356
- converted_point = php_helmert (point .x , point .y , point .z , helmert_constants );
357
- polar = php_cartesian_to_polar (converted_point .x , converted_point .y , converted_point .z , eli_to );
374
+ converted_point = helmert (point .x , point .y , point .z , helmert_constants );
375
+ polar = cartesian_to_polar (converted_point .x , converted_point .y , converted_point .z , eli_to );
358
376
359
377
array_init (return_value );
360
378
add_assoc_double (return_value , "lat" , polar .latitude );
361
379
add_assoc_double (return_value , "long" , polar .longitude );
362
380
add_assoc_double (return_value , "height" , polar .height );
363
381
}
382
+ /* }}} */
364
383
365
384
/* {{{ proto haversine(double fromLat, double fromLong, double toLat, double toLong [, double radius ])
366
385
* Calculates the greater circle distance between the two lattitude/longitude pairs */
0 commit comments