phayes / geoPHP

Advanced geometry operations in PHP
https://geophp.net
Other
865 stars 265 forks source link

Convert distance (spatial reference) to meters ? #163

Closed nakasix closed 5 years ago

nakasix commented 5 years ago

Hello,

Is it possible to get the result of distance method in meters or how to convert this distance ?

Regards,

BathoryPeter commented 5 years ago

Which one are you using? greatCircleLength() should return in meters if the coordinates are in lat/lon. Use haversineLength() if you have projected coordinates.

nakasix commented 5 years ago

In fact, I do not use any of these functions. I use the distance function to know the distance between two points, but I would like to get it in meters.

My sample code is :

$obj_geophp_point = geoPHP::load("POINT($flt_longitude $flt_latitude)"); # My point
$str_kml = file_get_contents('map.kml'); # My KML
$obj_geophp_kml = geoPHP::load($str_kml,'kml'); # KML with one Polygon = My Polygon
$flt_result = $obj_geophp_kml->distance($obj_geophp_point); # Get distance between Polygon and distance
var_dump($flt_result);

Regards,

BathoryPeter commented 5 years ago

Oh, I'm sorry, selecting the proper length method is a frequently asked question, I associated that. As I know, geoPHP has no distance method like that. You can implement it based on the previously mentioned length methods.

nakasix commented 5 years ago

Thank you, I will implement my own method.