Skip to content

Geojsonify vincenty #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions geospatial.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ PHP_FUNCTION(transform_datum)
/* }}} */

/* {{{ proto double haversine(GeoJSONPoint from, GeoJSONPoint to [, double radius ])
* Calculates the greater circle distance between the two lattitude/longitude pairs */
* Calculates the greater circle distance between two points */
PHP_FUNCTION(haversine)
{
double radius = GEO_EARTH_RADIUS;
Expand All @@ -549,18 +549,25 @@ PHP_FUNCTION(haversine)
}
/* }}} */

/* {{{ proto double vincenty(GeoJSONPoint from, GeoJSONPoint to [, long reference_ellipsoid ])
* Calculates the distance between two points */
PHP_FUNCTION(vincenty)
{
zval *from_geojson, *to_geojson;
double from_lat, from_long, to_lat, to_long;
double radius = GEO_EARTH_RADIUS;
long reference_ellipsoid;
long reference_ellipsoid = GEO_WGS84;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd|l", &from_lat, &from_long, &to_lat, &to_long, &reference_ellipsoid) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa|l", &from_geojson, &to_geojson, &reference_ellipsoid) == FAILURE) {
return;
}

geojson_point_to_lon_lat(from_geojson, &from_long, &from_lat);
geojson_point_to_lon_lat(to_geojson, &to_long, &to_lat);

geo_ellipsoid eli = get_ellipsoid(reference_ellipsoid);
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));
}
/* }}} */

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)
{
Expand Down
16 changes: 13 additions & 3 deletions tests/Vincenty.phpt → tests/vincenty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ $flindersPeakLat = dms_to_decimal(-37, 57, 3.72030);
$flindersPeakLong = dms_to_decimal(144, 25, 29.52440);
$buninyongLat = dms_to_decimal(-37, 39, 10.15610);
$buninyongLong = dms_to_decimal(143, 55, 35.38390);
echo vincenty($flindersPeakLat, $flindersPeakLong, $buninyongLat, $buninyongLong), 'm';

$flinders = array(
'type' => 'Point',
'coordinates' => array( $flindersPeakLong, $flindersPeakLat )
);
$buninyong = array(
'type' => 'Point',
'coordinates' => array( $buninyongLong, $buninyongLat )
);
var_dump(vincenty($flinders, $buninyong));
?>
--EXPECT--
54972.271m
--EXPECTF--
54972.271
float(54972.2%d)