protected function KML::geomFromXML in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/lib/adapters/KML.class.php \KML::geomFromXML()
1 call to KML::geomFromXML()
- KML::geomFromText in geoPHP/
lib/ adapters/ KML.class.php
File
- geoPHP/
lib/ adapters/ KML.class.php, line 76
Class
- KML
- PHP Geometry/KML encoder/decoder
Code
protected function geomFromXML() {
$geometries = array();
$geom_types = geoPHP::geometryList();
$placemark_elements = $this->xmlobj
->getElementsByTagName('placemark');
if ($placemark_elements->length) {
foreach ($placemark_elements as $placemark) {
foreach ($placemark->childNodes as $child) {
// Node names are all the same, except for MultiGeometry, which maps to GeometryCollection
$node_name = $child->nodeName == 'multigeometry' ? 'geometrycollection' : $child->nodeName;
if (array_key_exists($node_name, $geom_types)) {
$function = 'parse' . $geom_types[$node_name];
$geometries[] = $this
->{$function}($child);
}
}
}
}
else {
// The document does not have a placemark, try to create a valid geometry from the root element
$node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName;
if (array_key_exists($node_name, $geom_types)) {
$function = 'parse' . $geom_types[$node_name];
$geometries[] = $this
->{$function}($this->xmlobj->documentElement);
}
}
return geoPHP::geometryReduce($geometries);
}