protected function KML::parsePolygon in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/lib/adapters/KML.class.php \KML::parsePolygon()
File
- geoPHP/
lib/ adapters/ KML.class.php, line 134
Class
- KML
- PHP Geometry/KML encoder/decoder
Code
protected function parsePolygon($xml) {
$components = array();
$outer_boundary_element_a = $this
->childElements($xml, 'outerboundaryis');
if (empty($outer_boundary_element_a)) {
return new Polygon();
// It's an empty polygon
}
$outer_boundary_element = $outer_boundary_element_a[0];
$outer_ring_element_a = $this
->childElements($outer_boundary_element, 'linearring');
$outer_ring_element = $outer_ring_element_a[0];
$components[] = $this
->parseLineString($outer_ring_element);
if (count($components) != 1) {
throw new Exception("Invalid KML");
}
$inner_boundary_element_a = $this
->childElements($xml, 'innerboundaryis');
if (count($inner_boundary_element_a)) {
foreach ($inner_boundary_element_a as $inner_boundary_element) {
foreach ($this
->childElements($inner_boundary_element, 'linearring') as $inner_ring_element) {
$components[] = $this
->parseLineString($inner_ring_element);
}
}
}
return new Polygon($components);
}