/** * test for getPointOnSurface * * @param array $ring array of points forming the ring * * @dataProvider providerForTestGetPointOnSurface * @return void */ public function testGetPointOnSurface($ring) { $this->assertEquals( $this->object->isPointInsidePolygon( $this->object->getPointOnSurface($ring), $ring ), true ); }
/** * Generate the WKT for the data from ESRI shape files. * * @param array $row_data GIS data * * @return string the WKT for the data from ESRI shape files * @access public */ public function getShape($row_data) { // Determines whether each line ring is an inner ring or an outer ring. // If it's an inner ring get a point on the surface which can be used to // correctly classify inner rings to their respective outer rings. foreach ($row_data['parts'] as $i => $ring) { $row_data['parts'][$i]['isOuter'] = GISPolygon::isOuterRing($ring['points']); } // Find points on surface for inner rings foreach ($row_data['parts'] as $i => $ring) { if (!$ring['isOuter']) { $row_data['parts'][$i]['pointOnSurface'] = GISPolygon::getPointOnSurface($ring['points']); } } // Classify inner rings to their respective outer rings. foreach ($row_data['parts'] as $j => $ring1) { if ($ring1['isOuter']) { continue; } foreach ($row_data['parts'] as $k => $ring2) { if (!$ring2['isOuter']) { continue; } // If the pointOnSurface of the inner ring // is also inside the outer ring if (GISPolygon::isPointInsidePolygon($ring1['pointOnSurface'], $ring2['points'])) { if (!isset($ring2['inner'])) { $row_data['parts'][$k]['inner'] = array(); } $row_data['parts'][$k]['inner'][] = $j; } } } $wkt = 'MULTIPOLYGON('; // for each polygon foreach ($row_data['parts'] as $ring) { if (!$ring['isOuter']) { continue; } $wkt .= '('; // start of polygon $wkt .= '('; // start of outer ring foreach ($ring['points'] as $point) { $wkt .= $point['x'] . ' ' . $point['y'] . ','; } $wkt = mb_substr($wkt, 0, mb_strlen($wkt) - 1); $wkt .= ')'; // end of outer ring // inner rings if any if (isset($ring['inner'])) { foreach ($ring['inner'] as $j) { $wkt .= ',('; // start of inner ring foreach ($row_data['parts'][$j]['points'] as $innerPoint) { $wkt .= $innerPoint['x'] . ' ' . $innerPoint['y'] . ','; } $wkt = mb_substr($wkt, 0, mb_strlen($wkt) - 1); $wkt .= ')'; // end of inner ring } } $wkt .= '),'; // end of polygon } $wkt = mb_substr($wkt, 0, mb_strlen($wkt) - 1); $wkt .= ')'; // end of multipolygon return $wkt; }