Skip to content

Commit 41ec239

Browse files
committed
Merged pull request #8
2 parents db780b4 + ccb575c commit 41ec239

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

geospatial.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ PHP_FUNCTION(transform_datum)
531531
/* }}} */
532532

533533
/* {{{ proto double haversine(GeoJSONPoint from, GeoJSONPoint to [, double radius ])
534-
* Calculates the greater circle distance between the two lattitude/longitude pairs */
534+
* Calculates the greater circle distance between two points */
535535
PHP_FUNCTION(haversine)
536536
{
537537
double radius = GEO_EARTH_RADIUS;
@@ -549,18 +549,25 @@ PHP_FUNCTION(haversine)
549549
}
550550
/* }}} */
551551

552+
/* {{{ proto double vincenty(GeoJSONPoint from, GeoJSONPoint to [, long reference_ellipsoid ])
553+
* Calculates the distance between two points */
552554
PHP_FUNCTION(vincenty)
553555
{
556+
zval *from_geojson, *to_geojson;
554557
double from_lat, from_long, to_lat, to_long;
555-
double radius = GEO_EARTH_RADIUS;
556-
long reference_ellipsoid;
558+
long reference_ellipsoid = GEO_WGS84;
557559

558-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd|l", &from_lat, &from_long, &to_lat, &to_long, &reference_ellipsoid) == FAILURE) {
560+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa|l", &from_geojson, &to_geojson, &reference_ellipsoid) == FAILURE) {
559561
return;
560562
}
563+
564+
geojson_point_to_lon_lat(from_geojson, &from_long, &from_lat);
565+
geojson_point_to_lon_lat(to_geojson, &to_long, &to_lat);
566+
561567
geo_ellipsoid eli = get_ellipsoid(reference_ellipsoid);
562568
RETURN_DOUBLE(php_geo_vincenty(from_lat * GEO_DEG_TO_RAD, from_long * GEO_DEG_TO_RAD, to_lat * GEO_DEG_TO_RAD, to_long * GEO_DEG_TO_RAD, eli));
563569
}
570+
/* }}} */
564571

565572
void php_geo_fraction_along_gc_line(double from_lat, double from_long, double to_lat, double to_long, double fraction, double radius, double *res_lat, double *res_long)
566573
{

tests/Vincenty.phpt renamed to tests/vincenty.phpt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ $flindersPeakLat = dms_to_decimal(-37, 57, 3.72030);
66
$flindersPeakLong = dms_to_decimal(144, 25, 29.52440);
77
$buninyongLat = dms_to_decimal(-37, 39, 10.15610);
88
$buninyongLong = dms_to_decimal(143, 55, 35.38390);
9-
echo vincenty($flindersPeakLat, $flindersPeakLong, $buninyongLat, $buninyongLong), 'm';
9+
10+
$flinders = array(
11+
'type' => 'Point',
12+
'coordinates' => array( $flindersPeakLong, $flindersPeakLat )
13+
);
14+
$buninyong = array(
15+
'type' => 'Point',
16+
'coordinates' => array( $buninyongLong, $buninyongLat )
17+
);
18+
var_dump(vincenty($flinders, $buninyong));
1019
?>
11-
--EXPECT--
12-
54972.271m
20+
--EXPECTF--
21+
54972.271
22+
float(54972.2%d)

0 commit comments

Comments
 (0)