protected function featureFromXML() { $features = []; $properties = []; $id = ""; $geom_types = geoPHP::geometryList(); $placemark_elements = $this->xmlobj->getElementsByTagName('placemark'); if ($placemark_elements->length) { foreach ($placemark_elements as $placemark) { $properties = []; 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)) { $adapter = new KML(); $geometry = $adapter->read($child->ownerDocument->saveXML($child)); } elseif ($node_name == 'extendeddata') { foreach ($child->childNodes as $data) { if ($data->nodeName != '#text') { if ($data->nodeName == 'data') { $value = $data->getElementsByTagName('value')[0]; $properties[$data->getAttribute('name')] = preg_replace('/\\n\\s+/', ' ', trim($value->textContent)); } elseif ($data->nodeName == 'schemadata') { foreach ($data->childNodes as $schemadata) { if ($schemadata->nodeName != '#text') { $properties[$schemadata->getAttribute('name')] = preg_replace('/\\n\\s+/', ' ', trim($schemadata->textContent)); } } } } } } elseif (!in_array($node_name, ['#text', 'lookat', 'style', 'styleurl'])) { $properties[$child->nodeName] = preg_replace('/\\n\\s+/', ' ', trim($child->textContent)); } } $feature = new Feature($geometry, $properties, $id); $features[] = $feature; } } else { throw new Exception("Cannot Read Feature From KML"); } $id = ""; $properties = []; $collection = new FeatureCollection($features, $properties, $id); return $collection; }
<h1 id="title">KML Parser Example</h1> <div id="tags"></div> <p id="shortdesc"> Demonstrate the operation of the KML parser with this KML file : <a href="http://code.google.com/apis/kml/documentation/KML_Samples.kml">code.google.com/apis/kml/documentation/KML_Samples.kml</a> </p> <div id="output"> <?php $url = '<script type="text/javascript">document.write(document.getElementById(\'file_url\'))</script>'; ?> <?php require_once 'lib/Format/KML.class.php'; $options = array("extractStyles" => true); $test = new KML($options); /** read **/ $features = $test->read("http://code.google.com/apis/kml/documentation/KML_Samples.kml"); $html = ""; foreach ($features as $feature) { $html .= "<h2>Geometry : <b>" . get_class($feature->geometry) . "</b></h2>"; if (count($feature->attributes) > 0) { $html .= "<h3>attributes : </h3>"; $html .= "<ul>"; foreach ($feature->attributes as $key => $value) { $html .= "<li>" . $key . " : " . $value . "</li>"; } $html .= "</ul>"; } if (count($feature->style) > 0) { $html .= "<h3>style : </h3>";
function test_Format_KML_extendedData() { $f = new KML(); $features = $f->read(self::ext_data); $this->assertEqual($features[0]->attributes["all_bridges"]["value"], "3030"); $this->assertEqual($features[0]->attributes["all_bridges"]["displayName"], "all bridges"); }
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. require_once dirname(__FILE__) . "/../php/mb_validateSession.php"; require_once dirname(__FILE__) . "/../classes/class_connector.php"; require_once dirname(__FILE__) . "/../classes/class_kml_ows.php"; //FIXME: what about projections? //header("Content-Type: text/x-json"); if (isset($_REQUEST["url"])) { $url = $_REQUEST["url"]; } else { echo "{}"; exit; } $kml = new KML(); $con = new connector(); $kmlString = $con->load($url); try { if ($kml->parseKml($kmlString)) { $geojson = $kml->toGeoJSON(); echo $geojson; } else { echo "{}"; } } catch (Exception $e) { echo $e; die; }
<?php # $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $ # http://www.mapbender.org/index.php/class_wmc.php # Copyright (C) 2002 CCGIS # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. mb_internal_encoding("UTF-8"); require_once dirname(__FILE__) . "/../php/mb_validateSession.php"; require_once dirname(__FILE__) . "/../classes/class_kml_ows.php"; $kmlId = $_GET["kmlId"]; $kml = new KML(); $kmlDoc = $kml->getKmlDocumentFromDB($kmlId); if ($kmlDoc) { header("Content-type: application/xhtml+xml; charset=" . CHARSET); echo $kmlDoc; } else { echo "You may not have the rights to access this document. Check your log file."; }
public function collectionToKML($geom) { $components = $geom->getComponents(); $str = '<' . $this->nss . 'MultiGeometry>'; foreach ($geom->getComponents() as $comp) { $sub_adapter = new KML(); $str .= $sub_adapter->write($comp); } return $str . '</' . $this->nss . 'MultiGeometry>'; }
<?php @session_start(); require_once '../include/var_global.php'; require_once '../include/bdatos.php'; require_once '../include/log.php'; require_once '../include/fecha_hora.php'; require_once '../include/funciones.php'; require_once '../include/clases/KML.php'; $connectionBD = conectaBD(); $archivoMKL = new KML(); $archivoMKL->queryKML($_POST['tipo_paciente'], $_POST['fecha_inicio'], $_POST['fecha_fin'], $_POST['estado']); $archivoMKL->doKML(); $archivoMKL->getKML(); $connectionBD = closeConexion();
<?php require_once 'lib/Format/KML.class.php'; $options = array("extractStyles" => true); $test = new KML($options); /** read **/ $test->read("KML_Samples.kml"); //Util::dump($test->features, "features"); /** write **/ $kml = $test->write($test->features); Util::dump($kml, "kml !");
} break; case 'clear': session_destroy(); $kml_file = "parse_test.kml"; $kml_file_url = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/' . $kml_file; $kml_generated_file = "parse_test.kml"; $kml_generated_file_url = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/' . $kml_generated_file; break; } } $start_time = microtime(true); $kml_data = file_get_contents($kml_file); $open_file_time = microtime(true) - $start_time; $start_time = microtime(true); $kml = KML::createFromText($kml_data); $parse_time = microtime(true) - $start_time; $start_time = microtime(true); $generated_kml = $kml->__toString(); $generate_kml_time = microtime(true) - $start_time; $start_time = microtime(true); $generated_wkt = $kml->toWKT(); $generate_wkt_time = microtime(true) - $start_time; $start_time = microtime(true); $generated_json = $kml->toJSON(); $generate_json_time = microtime(true) - $start_time; $total_procress_time = $open_file_time + $parse_time + $generate_kml_time + $generate_wkt_time + $generated_json; $kml_object = object_to_array(simplexml_load_file($kml_file)); $generated_kml_object = object_to_array(simplexml_load_string($generated_kml)); $kml_diff = array_compare($kml_object, $generated_kml_object); if ($reset_cache) {
$serverFilename = "../tmp/kml" . time() . ".xml"; copy($clientFilename, $serverFilename); $kmlDoc = loadFile($serverFilename); $kmlObj = new KML(); if ($kmlObj->parseKml($kmlDoc)) { $geoJSON = $kmlObj->toGeoJSON(); setGeoJson($geoJSON); } else { echo "<script language='javascript'>"; echo "alert('KML load failed. See the error log for details.');"; echo "</script>"; } } elseif ($kmlUrl) { $connector = new connector($kmlUrl); $kmlDoc = $connector->file; $kmlObj = new KML(); if ($kmlObj->parseKml($kmlDoc)) { $geoJSON = $kmlObj->toGeoJSON(); setGeoJson($geoJSON); } else { echo "<script language='javascript'>"; echo "alert('KML load failed. See the error log for details.');"; echo "</script>"; } } function setGeoJson($geoJSON) { echo "<script language='javascript'>"; if ($geoJSON) { echo "var geoJSON = " . $geoJSON . ";"; echo "window.opener.kmlHasLoaded.trigger(geoJSON);";
//url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml' url: 'http://cie.servehttp.com/lepra.chiapas/include/chiapas.kml' //url: 'http://cie.servehttp.com/lepra.chiapas/include/cta.kml' }); archivoKML.setMap(map);*/ /*var kmlLayer = new google.maps.KmlLayer({ url: 'http://cie.servehttp.com/lepra.chiapas/include/jurs.KML', suppressInfoWindows: true, map: map });*/ <?php if (!empty($_POST)) { require_once 'include/clases/KML.php'; $archivoKML = new KML(); $archivoKML->queryKML($_POST['tipo_paciente'], $_POST['fecha_inicio'], $_POST['fecha_fin'], $_POST['estado']); $matriz = $archivoKML->getMatriz(); if ($matriz == null) { echo 'alert("No se econtraron casos");'; } else { //print_r($matriz); foreach ($matriz as $elemento) { echo ' var pac_' . $elemento['id'] . ' = new google.maps.Marker({ position: new google.maps.LatLng(' . $elemento['lat'] . ', ' . $elemento['lon'] . '), map: map, title: "' . $elemento['name'] . '", icon: "'; if ($elemento['sexo'] == 1) { echo 'http://maps.google.com/mapfiles/kml/shapes/man.png';
function buildKML($kmlXMLObject) { $kml = new \KML(); $featureXMLObject = $kmlXMLObject->children(); $root_objects = array('Document', 'Placemark', 'Folder', 'NetworkLink'); foreach ($featureXMLObject as $key => $value) { if (in_array($key, $root_objects)) { $kml->setFeature(call_user_func('libKML\\build' . $key, $value)); //var_dump(call_user_func('libKML\build'. $key, $value)); } } return $kml; }
# $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $ # http://www.mapbender.org/index.php/class_wmc.php # Copyright (C) 2002 CCGIS # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. require_once dirname(__FILE__) . "/../php/mb_validateSession.php"; require_once dirname(__FILE__) . "/../classes/class_kml_ows.php"; $kmlId = $_POST["kmlId"]; $placemarkId = $_POST["placemarkId"]; $command = $_POST["command"]; $geoJSON = $_POST["geoJSON"]; $kml = new KML(); // returns true if the update succeeded, false if not if ($kml->updateKml($kmlId, $placemarkId, $geoJSON)) { echo "1"; } else { echo "0"; }