You are here

protected function KML::parsePolygon in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/adapters/KML.class.php \KML::parsePolygon()

File

geoPHP/lib/adapters/KML.class.php, line 130

Class

KML
PHP Geometry/KML encoder/decoder

Code

protected function parsePolygon($xml) {
  $components = array();
  $outer_boundary_element_a = $this
    ->childElements($xml, 'outerboundaryis');
  $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);
}