本文整理汇总了PHP中c2cTools::simplexmlLoadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::simplexmlLoadFile方法的具体用法?PHP c2cTools::simplexmlLoadFile怎么用?PHP c2cTools::simplexmlLoadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cTools
的用法示例。
在下文中一共展示了c2cTools::simplexmlLoadFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kml2wkt
/**
* kml2wkt does what its name implies :
* it takes a kml file, parses it for linestrings and returns an equivalent WKT LINESTRING
*
* The returned WKT can be 2, 3 or 4D.
* If does not really handle 4D parsing (beyond scope IMO) => KML import is restricted to routes (outings will only support GPX input)
* If $dim = 4, then time field will be zero-padded.
*/
public static function kml2wkt($path, $dim = 3)
{
// FIXME: document structure is very user customizable, and thus this function is not very robust ...
// a solution would be to extract points linked to a linestring (if these points are present), and to sort them by date to build the linestring.
$xml = c2cTools::simplexmlLoadFile($path);
// TODO: handle files with Document>NetworkLink>Url>href : wget content... (mymaps generates these ones)
// TODO: handle files with one waypoint for point update ?
// TODO : handle multilines geometries ?
$i = 0;
$wkta = array();
if ($pm = $xml->Document->Placemark) {
// this is a simple kml
// (for instance, one made with google "my maps")
// in which these is no folder.
c2cTools::log("ParseGeo::kml2wkt({$path}, {$dim}) with xml->Document->Placemark");
return 'LINESTRING(' . self::getKmlCoordinates($pm->LineString->coordinates, $dim) . ')';
} elseif ($geom_folders = $xml->Document->Folder) {
// this is a "complex" KML with several folders (typical output of gpsbabel from gpx)
$trk_coords = array();
// kml file may contain three geom folders : Waypoints, Tracks and Routes
foreach ($geom_folders as $folder) {
// we're just looking for tracks :
if ($folder->name == 'Tracks') {
// there might be subfolders if gps signal has been interrupted
// we merge these folders together to build a single track.
foreach ($folder->Folder as $track) {
$trk_coords[] = self::getKmlCoordinates($track->Placemark->LineString->coordinates, $dim);
}
}
}
c2cTools::log("ParseGeo::kml2wkt({$path}, {$dim}) with xml->Document->Folder");
return 'LINESTRING(' . implode(', ', $trk_coords) . ')';
} else {
c2cTools::log("kml2wkt : no track found");
return false;
}
}