49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Franzz\Livetrail;
|
|
use Franzz\Objects\PhpObject;
|
|
|
|
/**
|
|
* GPX to GeoJSON Converter
|
|
*
|
|
* To convert a gpx file:
|
|
* 1. Add file <file_name>.gpx to geo/ folder
|
|
* 2. Assign file to project: UPDATE projects SET codename = '<file_name>' WHERE id_project = <id_project>;
|
|
* 3. Load any page
|
|
*/
|
|
class Converter extends PhpObject {
|
|
|
|
public function __construct() {
|
|
parent::__construct(__CLASS__);
|
|
}
|
|
|
|
public static function convertToGeoJson(string $sCodeName) {
|
|
$oGpx = new Gpx($sCodeName);
|
|
$oGeoJson = new GeoJson($sCodeName);
|
|
|
|
$oGeoJson->buildTracks($oGpx->getTracks());
|
|
if($oGeoJson->isSimplicationRequired()) $oGeoJson->buildTracks($oGpx->getTracks(), true);
|
|
$oGeoJson->sortOffTracks();
|
|
$oGeoJson->saveFile();
|
|
|
|
return [
|
|
'logs' => $oGpx->getLog().'<br />'.$oGeoJson->getLog(),
|
|
'center' => $oGeoJson->getCenter()
|
|
];
|
|
}
|
|
|
|
public static function hasGpxFile(string $sCodeName) {
|
|
return ($sCodeName != '' && file_exists(Gpx::getBackendFilePath($sCodeName)));
|
|
}
|
|
|
|
public static function isGeoJsonValid(string $sCodeName) {
|
|
$sGpxFilePath = Gpx::getBackendFilePath($sCodeName);
|
|
$sGeoJsonFilePath = GeoJson::getBackendFilePath($sCodeName);
|
|
|
|
return
|
|
!self::hasGpxFile($sCodeName) //No GPX, no need for geoJSON
|
|
||
|
|
file_exists($sGeoJsonFilePath) && filemtime($sGeoJsonFilePath) >= filemtime($sGpxFilePath); //geoJSON needs to be (re)generated
|
|
}
|
|
}
|