phayes / geoPHP

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

pointOnSurface() for a valid polygon always returns null #124

Open david-faith opened 8 years ago

david-faith commented 8 years ago

Using geoPHP with geos installed. pointOnSurface() for a valid polygon always returns null. While other functions such as centroid() work fine.

Example:

geoPHP::geosInstalled();          //true

$geo->geometryType();             //Polygon

$point = $geo->centroid();        //Point {coords: [-73.931519444925, 40.85512387767]}

$geo->covers($point);             //true

$geo->pointOnSurface();           //null

I'm wondering if anyone else has this problem (or I'm missing something)?

david-faith commented 8 years ago

Edit: This workaround seems to do the trick:

$geos_geometry = $geo->geos();                    //GEOSGeometry

$geos_POS = $geos_geometry->pointOnSurface();     //GEOSGeometry

$geos_POS->isEmpty();                             //false

$geos_POS->getX();                                //-73.932666589981

$geos_POS->getY();                                //40.85405746088
cvaida commented 8 years ago

That is because it seems the function is overriden in the Collection class. Had the same issue, and I commented line 310 in lib/geometry/Collection.php: public function pointOnSurface() { return NULL; } and it works fine now.

jafar690 commented 6 years ago

@david-faith where does the $geo variable come form