PHP code example of ycdev / php-igc-inspector

1. Go to this page and download the library: Download ycdev/php-igc-inspector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ycdev / php-igc-inspector example snippets


use Ycdev\PhpIgcInspector\PhpIgcInspector;

// Créer une instance depuis un fichier
$inspector = PhpIgcInspector::fromFile('vol.igc');

// Valider et parser le fichier
$inspector->validate();

// Récupérer les données parsées
$flight = $inspector->getFlight();

// Exporter en JSON
$json = $inspector->toJson();

public function __construct(string $content, bool $withRaw = false)

$content = file_get_contents('vol.igc');
$inspector = new PhpIgcInspector($content);

public static function fromFile(string $filePath, bool $withRaw = false): self

$inspector = PhpIgcInspector::fromFile('vol.igc');

public static function rawExtractFromFile(string $igcFilePath, string $outputDirectory, ?string $prefix = null): array

$files = PhpIgcInspector::rawExtractFromFile('vol.igc', './extracted', 'mon_vol');
// Retourne : ['A' => './extracted/mon_vol_record_A.igc', 'B' => './extracted/mon_vol_record_B.igc', ...]

public function validate(): bool

try {
    $inspector->validate();
    echo "Fichier valide !";
} catch (InvalidIgcException $e) {
    echo "Erreur : " . $e->getMessage();
}

public function getFlight(): ?object

$flight = $inspector->getFlight();
echo "Nombre de points GPS : " . count($flight->Fix);
echo "Pilote : " . $flight->OtherInformation->pilot;

public function getMetadata(): ?object

$metadata = $inspector->getMetadata();
// Contient : OtherInformation, Task, Manufacturer, etc.
// Ne contient PAS : Fix (tableau de points GPS)

public function toJson(): ?string

$json = $inspector->toJson();
file_put_contents('flight.json', $json);

public function stringify(int $flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE): ?string

// JSON compact
$json = $inspector->stringify(JSON_UNESCAPED_UNICODE);

// JSON avec options personnalisées
$json = $inspector->stringify(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK);

public function validTurnPoint(float $proximityRadius = 5000.0): bool

if ($inspector->validTurnPoint(5000.0)) {
    echo "Tous les turnpoints sont validés !";
    $task = $inspector->getFlight()->Task;
    $validation = $task->turnPointValidation;
    echo "Points validés : " . $validation->validatedCount . " / " . $validation->totalWaypoints;
}

public function rawExtract(string $outputDirectory, ?string $prefix = null): array

$files = $inspector->rawExtract('./extracted', 'mon_vol');
foreach ($files as $type => $filepath) {
    echo "Type $type extrait dans : $filepath\n";
}

public static function calculateDistance(
    float $latitude1,
    float $longitude1,
    float $latitude2,
    float $longitude2
): float

$distance = PhpIgcUtils::calculateDistance(51.1883, -1.0285, 51.2000, -1.0400);
echo "Distance : " . round($distance, 2) . " mètres";

public static function calculateProximity(
    float $latitude1,
    float $longitude1,
    float $latitude2,
    float $longitude2
): float

public static function igcToDecimal(int $degrees, int $minutes, int $thousandths): float

// Latitude : 51° 11.299' = 5111299
$latitude = PhpIgcUtils::igcToDecimal(51, 11, 299);
// Retourne : 51.1883

public static function decimalToIgc(float $decimalDegrees, bool $isLongitude = false): array

$coords = PhpIgcUtils::decimalToIgc(51.1883, false);
// Retourne : ['degrees' => 51, 'minutes' => 11, 'thousandths' => 299]

public static function secondsToTime(int $seconds): string

$time = PhpIgcUtils::secondsToTime(9332);
// Retourne : "02:35:32"

public static function timeToSeconds(string $timeString): int

$seconds = PhpIgcUtils::timeToSeconds("02:35:32");
// Retourne : 9332

$seconds = PhpIgcUtils::timeToSeconds("023532");
// Retourne : 9332

public static function formatDistance(float $distance, int $decimals = 2): string

$formatted = PhpIgcUtils::formatDistance(125430);
// Retourne : "125.43 km"

$formatted = PhpIgcUtils::formatDistance(456.7);
// Retourne : "456.70 m"

public static function formatSpeed(float $speed, int $decimals = 2): string

$formatted = PhpIgcUtils::formatSpeed(125.5);
// Retourne : "125.50 km/h"

public static function calculateSpeed(
    float $latitude1,
    float $longitude1,
    int $timestamp1,
    float $latitude2,
    float $longitude2,
    int $timestamp2
): ?float

$speed = PhpIgcUtils::calculateSpeed(
    51.1883, -1.0285, 1659692972,
    51.2000, -1.0400, 1659693000
);
// Retourne la vitesse en km/h

public static function validatePointsProximity(
    array $points,
    float $distance,
    string $igcContent,
    bool $

$points = [
    ['latitude' => 51.1883, 'longitude' => -1.0285],
    ['latitude' => 51.2000, 'longitude' => -1.0400],
];

$igcContent = file_get_contents('vol.igc');
$result = PhpIgcUtils::validatePointsProximity($points, 5000.0, $igcContent);

if ($result->allValidated) {
    echo "Tous les points sont validés !\n";
} else {
    echo "Points validés : " . $result->validatedCount . " / " . $result->totalPoints . "\n";
    foreach ($result->invalidatedPoints as $point) {
        echo "Point non validé : " . $point->reason . "\n";
    }
}

// Avec l'objet IGC inclus
$result = PhpIgcUtils::validatePointsProximity($points, 5000.0, $igcContent, true);
$flight = $result->igcObject; // Objet flight complet

use Ycdev\PhpIgcInspector\PhpIgcInspector;
use Ycdev\PhpIgcInspector\Exception\InvalidIgcException;

try {
    $inspector = PhpIgcInspector::fromFile('vol.igc');
    $inspector->validate();
    
    $flight = $inspector->getFlight();
    
    echo "Pilote : " . $flight->OtherInformation->pilot . "\n";
    echo "Date : " . $flight->OtherInformation->date . "\n";
    echo "Nombre de points GPS : " . count($flight->Fix) . "\n";
    echo "Distance totale : " . $flight->OtherInformation->totalDistanceFormatted . "\n";
    echo "Durée : " . $flight->OtherInformation->flightDurationFormatted . "\n";
    
} catch (InvalidIgcException $e) {
    echo "Erreur de validation : " . $e->getMessage() . "\n";
}

$inspector = PhpIgcInspector::fromFile('vol.igc');
$inspector->validate();

if ($inspector->validTurnPoint(5000.0)) {
    $task = $inspector->getFlight()->Task;
    $validation = $task->turnPointValidation;
    
    echo "Tous les turnpoints sont validés !\n";
    echo "Points validés : " . $validation->validatedCount . " / " . $validation->totalWaypoints . "\n";
    
    foreach ($validation->validatedTurnPoints as $turnPoint) {
        echo sprintf(
            "Turnpoint %d (%s) validé à %s (distance: %.2f m)\n",
            $turnPoint->index,
            $turnPoint->type,
            $turnPoint->validatedAt,
            $turnPoint->distance
        );
    }
} else {
    echo "Certains turnpoints n'ont pas été validés.\n";
    foreach ($validation->missedTurnPoints as $missed) {
        echo "Turnpoint manqué : " . $missed->type . " (index " . $missed->index . ")\n";
    }
}

use Ycdev\PhpIgcInspector\PhpIgcUtils;

$distance = PhpIgcUtils::calculateDistance(
    51.1883,  // Latitude point 1
    -1.0285,  // Longitude point 1
    51.2000,  // Latitude point 2
    -1.0400   // Longitude point 2
);

echo "Distance : " . PhpIgcUtils::formatDistance($distance) . "\n";

use Ycdev\PhpIgcInspector\PhpIgcUtils;

// Liste de points à valider (waypoints personnalisés)
$waypoints = [
    ['latitude' => 51.1883, 'longitude' => -1.0285, 'name' => 'Départ'],
    ['latitude' => 51.2000, 'longitude' => -1.0400, 'name' => 'Turnpoint 1'],
    ['latitude' => 51.2100, 'longitude' => -1.0500, 'name' => 'Arrivée'],
];

$igcContent = file_get_contents('vol.igc');
$result = PhpIgcUtils::validatePointsProximity($waypoints, 5000.0, $igcContent);

echo "Résultats de validation :\n";
echo "Points validés : " . $result->validatedCount . " / " . $result->totalPoints . "\n";
echo "Distance maximale : " . PhpIgcUtils::formatDistance($result->distance) . "\n";

foreach ($result->validatedPoints as $point) {
    echo sprintf(
        "✓ Point validé (distance: %.2f m) à %s\n",
        $point->minDistance,
        $point->validatedAt ?? 'N/A'
    );
}

foreach ($result->invalidatedPoints as $point) {
    echo sprintf(
        "✗ Point non validé : %s (distance min: %s)\n",
        $point->reason,
        $point->minDistance !== null ? PhpIgcUtils::formatDistance($point->minDistance) : 'N/A'
    );
}
bash
composer 

phpIgcInspector/
├── src/
│   ├── PhpIgcInspector.php          # Classe principale
│   ├── PhpIgcUtils.php              # Fonctions utilitaires
│   ├── Exception/
│   │   └── InvalidIgcException.php  # Exception personnalisée
│   ├── Data/
│   │   ├── EventTypeCode.php        # Codes d'événements
│   │   └── ManufacturerCodesData.php # Codes fabricants IGC
│   └── RecordTypes/                 # Types d'enregistrements IGC
└── doc/                              # Documentation et spécifications IGC