phayes / geoPHP

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

How to use contains method ? #162

Closed nakasix closed 5 years ago

nakasix commented 5 years ago

Hello,

I have this code in PHP :

# Load my point
$obj_geophp_point = geoPHP::load("POINT($flt_latitude $flt_longitude)");

#Load my KML map
$str_kml = file_get_contents(FCPATH . 'misc/pacwan/map.kml');
$obj_geophp_kml = geoPHP::load($str_kml,'kml');

# Get all Polygon
$ary_components = $obj_geophp_kml->getComponents();

# Foreach Polygon, test the point.
foreach ($ary_components as $value) {
    var_dump($value->contains($obj_geophp_point));
}

My point is in Polygon, but the "contains" function always return "false". Is this an error of use? Could you help me?

Thanx,

nakasix commented 5 years ago

Sorry, I had reversed longitude and latitude...

BathoryPeter commented 5 years ago

Do you have GEOS installed? Contains is an advanced method requires GEOS. See here: https://geophp.net/api.html#user-content-methods-1

In my fork, I have a basic native implementation for Polygons: https://github.com/funiq/geoPHP/blob/master/src/Geometry/Polygon.php#L301

nakasix commented 5 years ago

Yes, of course ! But it's OK, I had reversed longitude and latitude...