You are here

public function KML::geomFromText in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/adapters/KML.class.php \KML::geomFromText()
1 call to KML::geomFromText()
KML::read in geoPHP/lib/adapters/KML.class.php
Read KML string into geometry objects

File

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

Class

KML
PHP Geometry/KML encoder/decoder

Code

public function geomFromText($text) {

  // Change to lower-case and strip all CDATA
  $text = mb_strtolower($text, mb_detect_encoding($text));
  $text = preg_replace('/<!\\[cdata\\[(.*?)\\]\\]>/s', '', $text);

  // Load into DOMDOcument
  $xmlobj = new DOMDocument();
  @$xmlobj
    ->loadXML($text);
  if ($xmlobj === false) {
    throw new Exception("Invalid KML: " . $text);
  }
  $this->xmlobj = $xmlobj;
  try {
    $geom = $this
      ->geomFromXML();
  } catch (InvalidText $e) {
    throw new Exception("Cannot Read Geometry From KML: " . $text);
  } catch (Exception $e) {
    throw $e;
  }
  return $geom;
}