public function MethodsTests::_methods_tester_with_geos in geoPHP 8
Same name and namespace in other branches
- 7 geoPHP/tests/tests/methodsTest.php \MethodsTests::_methods_tester_with_geos()
1 call to MethodsTests::_methods_tester_with_geos()
- MethodsTests::testMethods in geoPHP/
tests/ tests/ methodsTest.php
File
- geoPHP/
tests/ tests/ methodsTest.php, line 328
Class
Code
public function _methods_tester_with_geos($geometry) {
// Cannot test methods if GEOS is not intstalled.
if (!geoPHP::geosInstalled()) {
return;
}
$methods = [
// 'boundary', //@@TODO: Uncomment this and fix errors
// @@TODO: Testing reveales errors in this method -- POINT vs. POLYGON
'envelope',
'getBBox',
'x',
'y',
'startPoint',
'endPoint',
'isRing',
'isClosed',
'numPoints',
];
foreach ($methods as $method) {
// Turn GEOS on.
geoPHP::geosInstalled(TRUE);
$geos_result = $geometry
->{$method}();
// Turn GEOS off.
geoPHP::geosInstalled(FALSE);
$norm_result = $geometry
->{$method}();
// Turn GEOS back On.
geoPHP::geosInstalled(TRUE);
$geos_type = gettype($geos_result);
$norm_type = gettype($norm_result);
if ($geos_type != $norm_type) {
$this
->fail('Type mismatch on ' . $method);
$this
->dump($geos_type);
$this
->dump($norm_type);
continue;
}
// Now check base on type.
if ($geos_type == 'object') {
$haus_dist = $geos_result
->hausdorffDistance(geoPHP::load($norm_result
->out('wkt'), 'wkt'));
// Get the length of the diagonal of the bbox - this is used to scale the haustorff distance
// Using Pythagorean theorem.
$bb = $geos_result
->getBBox();
$scale = sqrt(($bb['maxy'] - $bb['miny'] ^ 2) + ($bb['maxx'] - $bb['minx'] ^ 2));
// The difference in the output of GEOS and native-PHP methods should be less than 0.5 scaled haustorff units.
if ($haus_dist / $scale > 0.5) {
$this
->fail('Output mismatch on ' . $method);
$this
->dump('GEOS : ');
$this
->dump($geos_result
->out('wkt'));
$this
->dump('NORM : ');
$this
->dump($norm_result
->out('wkt'));
continue;
}
}
if ($geos_type == 'boolean' || $geos_type == 'string') {
if ($geos_result !== $norm_result) {
$this
->fail('Output mismatch on ' . $method);
$this
->dump('GEOS : ');
$this
->dump((string) $geos_result);
$this
->dump('NORM : ');
$this
->dump((string) $norm_result);
continue;
}
}
// @@TODO: Run tests for output of types arrays and float
// @@TODO: centroid function is non-compliant for collections and strings
}
}