2
2
+----------------------------------------------------------------------+
3
3
| PHP Version 5 |
4
4
+----------------------------------------------------------------------+
5
- | Copyright (c) 1997-2012 The PHP Group |
5
+ | Copyright (c) 1997-2013 The PHP Group |
6
6
+----------------------------------------------------------------------+
7
7
| This source file is subject to version 3.01 of the PHP license, |
8
8
| that is bundled with this package in the file LICENSE, and is |
12
12
| obtain it through the world-wide-web, please send a note to |
13
13
| license@php.net so we can mail you a copy immediately. |
14
14
+----------------------------------------------------------------------+
15
- | Author: |
15
+ | Authors: Derick Rethans <github@derickrethans.nl> |
16
+ | Michael Maclean <michael@no-surprises.co.uk> |
17
+ | Nathaniel McHugh <nmchugh@inviqa.com> |
18
+ | Marcus Deglos <marcus@deglos.com> |
16
19
+----------------------------------------------------------------------+
17
20
*/
18
21
19
-
20
- /* $Id$ */
21
-
22
22
#ifdef HAVE_CONFIG_H
23
23
#include "config.h"
24
24
#endif
@@ -328,7 +328,7 @@ geo_lat_long cartesian_to_polar(double x, double y, double z, geo_ellipsoid eli)
328
328
return polar ;
329
329
}
330
330
331
- /* {{{ proto dms_to_decimal(double degrees, double minutes, double seconds [,string direction])
331
+ /* {{{ proto double dms_to_decimal(double degrees, double minutes, double seconds [,string direction])
332
332
* Convert degrees, minutes & seconds values to decimal degrees */
333
333
PHP_FUNCTION (dms_to_decimal )
334
334
{
@@ -353,7 +353,7 @@ PHP_FUNCTION(dms_to_decimal)
353
353
}
354
354
/* }}} */
355
355
356
- /* {{{ proto decimal_to_dms(double decimal, string coordinate)
356
+ /* {{{ proto array decimal_to_dms(double decimal, string coordinate)
357
357
* Convert decimal degrees value to whole degrees and minutes and decimal seconds */
358
358
PHP_FUNCTION (decimal_to_dms )
359
359
{
@@ -385,13 +385,14 @@ PHP_FUNCTION(decimal_to_dms)
385
385
}
386
386
/* }}} */
387
387
388
- /* {{{ proto helmert(double x, double y, double z [, long from_reference_ellipsoid, long to_reference_ellipsoid])
389
- * Convert polar ones (latitude, longitude) tp cartesian co-ordiantes (x, y, z) */
388
+ /* {{{ proto array helmert(double x, double y, double z [, long from_reference_ellipsoid, long to_reference_ellipsoid])
389
+ * Convert cartesian co-ordinates between reference elipsoids */
390
390
PHP_FUNCTION (helmert )
391
391
{
392
392
double x , y , z ;
393
393
geo_cartesian point ;
394
- long from_reference_ellipsoid , to_reference_ellipsoid ;
394
+ long from_reference_ellipsoid = 0 , to_reference_ellipsoid = 0 ;
395
+
395
396
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|ll" , & x , & y , & z , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
396
397
return ;
397
398
}
@@ -405,7 +406,7 @@ PHP_FUNCTION(helmert)
405
406
}
406
407
/* }}} */
407
408
408
- /* {{{ proto polar_to_cartesian(double latitude, double longitude[, long reference_ellipsoid])
409
+ /* {{{ proto array polar_to_cartesian(double latitude, double longitude[, long reference_ellipsoid])
409
410
* Convert polar ones (latitude, longitude) tp cartesian co-ordiantes (x, y, z) */
410
411
PHP_FUNCTION (polar_to_cartesian )
411
412
{
@@ -426,8 +427,8 @@ PHP_FUNCTION(polar_to_cartesian)
426
427
}
427
428
/* }}} */
428
429
429
- /* {{{ proto cartesian_to_polar(double x, double y, double z [, long reference_ellipsoid])
430
- * Convert cartesian co-ordiantes (x, y, z) to polar ones (latitude, longitude) */
430
+ /* {{{ proto array cartesian_to_polar(double x, double y, double z [, long reference_ellipsoid])
431
+ * Convert cartesian co-ordinates (x, y, z) to polar ones (latitude, longitude) */
431
432
PHP_FUNCTION (cartesian_to_polar )
432
433
{
433
434
double x , y , z ;
@@ -448,44 +449,53 @@ PHP_FUNCTION(cartesian_to_polar)
448
449
/* }}} */
449
450
450
451
451
- /* {{{ proto transform_datum(double latitude, double longitude , long from_reference_ellipsoid, long to_reference_ellipsoid)
452
- * Unified function to transform projection of geo-cordinates between datums */
452
+ /* {{{ proto GeoJSONPoint transform_datum(GeoJSONPoint coordinates , long from_reference_ellipsoid, long to_reference_ellipsoid)
453
+ * Unified function to transform projection of geo-coordinates between datums */
453
454
PHP_FUNCTION (transform_datum )
454
455
{
455
456
double latitude , longitude ;
457
+ zval * geojson ;
456
458
long from_reference_ellipsoid , to_reference_ellipsoid ;
457
459
geo_cartesian point , converted_point ;
458
460
geo_lat_long polar ;
459
461
460
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddll " , & latitude , & longitude , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
462
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "all " , & geojson , & from_reference_ellipsoid , & to_reference_ellipsoid ) == FAILURE ) {
461
463
return ;
462
464
}
463
465
466
+ geojson_point_to_lon_lat (geojson , & longitude , & latitude );
467
+
464
468
geo_ellipsoid eli_from = get_ellipsoid (from_reference_ellipsoid );
465
469
geo_ellipsoid eli_to = get_ellipsoid (to_reference_ellipsoid );
466
470
point = polar_to_cartesian (latitude , longitude , eli_from );
467
471
geo_helmert_constants helmert_constants = get_helmert_constants (from_reference_ellipsoid , to_reference_ellipsoid );
468
472
converted_point = helmert (point .x , point .y , point .z , helmert_constants );
469
473
polar = cartesian_to_polar (converted_point .x , converted_point .y , converted_point .z , eli_to );
470
-
474
+ /*
471
475
array_init(return_value);
472
476
add_assoc_double(return_value, "lat", polar.latitude);
473
477
add_assoc_double(return_value, "long", polar.longitude);
474
478
add_assoc_double(return_value, "height", polar.height);
479
+ */
480
+ retval_point_from_coordinates (return_value , polar .longitude , polar .latitude );
475
481
}
476
482
/* }}} */
477
483
478
- /* {{{ proto haversine(double fromLat, double fromLong, double toLat, double toLong [, double radius ])
484
+ /* {{{ proto double haversine(GeoJSONPoint from, GeoJSONPoint to [, double radius ])
479
485
* Calculates the greater circle distance between the two lattitude/longitude pairs */
480
486
PHP_FUNCTION (haversine )
481
487
{
482
- double from_lat , from_long , to_lat , to_long ;
483
488
double radius = GEO_EARTH_RADIUS ;
489
+ zval * from_geojson , * to_geojson ;
490
+ double from_lat , from_long , to_lat , to_long ;
484
491
485
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "dddd |d" , & from_lat , & from_long , & to_lat , & to_long , & radius ) == FAILURE ) {
492
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "aa |d" , & from_geojson , & to_geojson , & radius ) == FAILURE ) {
486
493
return ;
487
494
}
488
495
496
+ geojson_point_to_lon_lat (from_geojson , & from_long , & from_lat );
497
+ geojson_point_to_lon_lat (to_geojson , & to_long , & to_lat );
498
+
489
499
RETURN_DOUBLE (php_geo_haversine (from_lat * GEO_DEG_TO_RAD , from_long * GEO_DEG_TO_RAD , to_lat * GEO_DEG_TO_RAD , to_long * GEO_DEG_TO_RAD ) * radius );
490
500
}
491
501
/* }}} */
@@ -508,7 +518,7 @@ void php_geo_fraction_along_gc_line(double from_lat, double from_long, double to
508
518
* res_long = atan2 (y , x );
509
519
}
510
520
511
- /* {{{ proto GeoJSON fraction_along_gc_line(GeoJSONPoint from, GeoJSONPoint to, double fraction [, double radius ])
521
+ /* {{{ proto GeoJSONPoint fraction_along_gc_line(GeoJSONPoint from, GeoJSONPoint to, double fraction [, double radius ])
512
522
* Calculates a lat/long pair at a fraction (0-1) of the distance along a GC line */
513
523
PHP_FUNCTION (fraction_along_gc_line )
514
524
{
0 commit comments