feat: Gestion des secteurs et migration v3.0.4+304
- Ajout système complet de gestion des secteurs avec contours géographiques - Import des contours départementaux depuis GeoJSON - API REST pour la gestion des secteurs (/api/sectors) - Service de géolocalisation pour déterminer les secteurs - Migration base de données avec tables x_departements_contours et sectors_adresses - Interface Flutter pour visualisation et gestion des secteurs - Ajout thème sombre dans l'application - Corrections diverses et optimisations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
173
api/test_import_errors.php
Normal file
173
api/test_import_errors.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/**
|
||||
* Script pour diagnostiquer les erreurs d'import des départements
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/src/Config/AppConfig.php';
|
||||
require_once __DIR__ . '/src/Core/Database.php';
|
||||
|
||||
echo "Diagnostic des erreurs d'import\n";
|
||||
echo "==============================\n\n";
|
||||
|
||||
try {
|
||||
$appConfig = AppConfig::getInstance();
|
||||
Database::init($appConfig->getDatabaseConfig());
|
||||
$db = Database::getInstance();
|
||||
|
||||
// 1. Lister les départements importés
|
||||
echo "1. Départements importés avec succès:\n";
|
||||
$sql = "SELECT code_dept, nom_dept FROM x_departements_contours ORDER BY code_dept";
|
||||
$stmt = $db->query($sql);
|
||||
$imported = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
|
||||
echo " Total : " . count($imported) . " départements\n";
|
||||
|
||||
// 2. Vérifier spécifiquement le 06
|
||||
if (!isset($imported['06'])) {
|
||||
echo "\n ⚠️ Le département 06 n'est pas dans la base\n";
|
||||
}
|
||||
|
||||
// 3. Lire le fichier GeoJSON pour voir tous les départements
|
||||
$filePath = __DIR__ . '/docs/contour-des-departements.geojson';
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
echo "\n✗ Fichier non trouvé : $filePath\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "\n2. Analyse du fichier GeoJSON:\n";
|
||||
$json = json_decode(file_get_contents($filePath), true);
|
||||
|
||||
if (!$json || !isset($json['features'])) {
|
||||
echo " ✗ Erreur de lecture du fichier\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$totalInFile = count($json['features']);
|
||||
echo " Total dans le fichier : $totalInFile départements\n";
|
||||
|
||||
// 4. Identifier les départements manquants
|
||||
$missingDepts = [];
|
||||
$dept06Found = false;
|
||||
|
||||
foreach ($json['features'] as $feature) {
|
||||
$code = $feature['properties']['code'] ?? null;
|
||||
$nom = $feature['properties']['nom'] ?? null;
|
||||
|
||||
if ($code === '06') {
|
||||
$dept06Found = true;
|
||||
echo "\n3. Analyse du département 06:\n";
|
||||
echo " - Code : $code\n";
|
||||
echo " - Nom : $nom\n";
|
||||
echo " - Type de géométrie : " . ($feature['geometry']['type'] ?? 'inconnu') . "\n";
|
||||
|
||||
// Tester la conversion
|
||||
if (isset($feature['geometry'])) {
|
||||
$geometry = $feature['geometry'];
|
||||
$type = $geometry['type'] ?? null;
|
||||
|
||||
if ($type === 'MultiPolygon') {
|
||||
echo " - C'est un MultiPolygon avec " . count($geometry['coordinates']) . " polygones\n";
|
||||
|
||||
// Créer le WKT pour test
|
||||
$polygons = [];
|
||||
$totalPoints = 0;
|
||||
foreach ($geometry['coordinates'] as $i => $polygon) {
|
||||
$ring = $polygon[0];
|
||||
$totalPoints += count($ring);
|
||||
if ($i < 2) { // Afficher info des 2 premiers polygones
|
||||
echo " * Polygone " . ($i+1) . " : " . count($ring) . " points\n";
|
||||
}
|
||||
}
|
||||
echo " - Total de points : $totalPoints\n";
|
||||
|
||||
// Tester l'insertion
|
||||
echo "\n Test d'insertion du département 06...\n";
|
||||
try {
|
||||
// Construire le WKT MultiPolygon
|
||||
$polygons = [];
|
||||
$allPoints = [];
|
||||
|
||||
foreach ($geometry['coordinates'] as $polygon) {
|
||||
$ring = $polygon[0];
|
||||
$points = [];
|
||||
foreach ($ring as $point) {
|
||||
$points[] = $point[0] . ' ' . $point[1];
|
||||
$allPoints[] = $point;
|
||||
}
|
||||
$polygons[] = '((' . implode(',', $points) . '))';
|
||||
}
|
||||
|
||||
$wkt = 'MULTIPOLYGON(' . implode(',', $polygons) . ')';
|
||||
|
||||
// Calculer bbox
|
||||
$lats = array_map(function($p) { return $p[1]; }, $allPoints);
|
||||
$lngs = array_map(function($p) { return $p[0]; }, $allPoints);
|
||||
|
||||
// Tester si le polygone est valide
|
||||
$testSql = "SELECT ST_IsValid(ST_GeomFromText(:wkt, 4326)) as is_valid,
|
||||
ST_AsText(ST_GeomFromText(:wkt, 4326)) as geom_text";
|
||||
$testStmt = $db->prepare($testSql);
|
||||
$testStmt->execute(['wkt' => $wkt]);
|
||||
$result = $testStmt->fetch();
|
||||
|
||||
if ($result['is_valid']) {
|
||||
echo " ✓ Géométrie valide\n";
|
||||
|
||||
// Essayer l'insertion
|
||||
$insertSql = "INSERT INTO x_departements_contours
|
||||
(code_dept, nom_dept, contour, bbox_min_lat, bbox_max_lat, bbox_min_lng, bbox_max_lng)
|
||||
VALUES
|
||||
(:code, :nom, ST_GeomFromText(:polygon, 4326), :min_lat, :max_lat, :min_lng, :max_lng)";
|
||||
|
||||
$insertStmt = $db->prepare($insertSql);
|
||||
$insertStmt->execute([
|
||||
'code' => '06',
|
||||
'nom' => $nom,
|
||||
'polygon' => $wkt,
|
||||
'min_lat' => min($lats),
|
||||
'max_lat' => max($lats),
|
||||
'min_lng' => min($lngs),
|
||||
'max_lng' => max($lngs)
|
||||
]);
|
||||
|
||||
echo " ✓ Insertion réussie!\n";
|
||||
|
||||
} else {
|
||||
echo " ✗ Géométrie invalide\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo " ✗ Erreur : " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
} elseif ($type === 'Polygon') {
|
||||
echo " - C'est un Polygon simple\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($code && !isset($imported[$code])) {
|
||||
$missingDepts[$code] = $nom;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$dept06Found) {
|
||||
echo "\n⚠️ Le département 06 n'est pas dans le fichier GeoJSON!\n";
|
||||
}
|
||||
|
||||
// 5. Lister tous les départements manquants
|
||||
echo "\n4. Départements manquants:\n";
|
||||
ksort($missingDepts);
|
||||
foreach ($missingDepts as $code => $nom) {
|
||||
echo " - $code : $nom\n";
|
||||
}
|
||||
|
||||
echo "\n5. Résumé:\n";
|
||||
echo " - Dans le fichier : $totalInFile départements\n";
|
||||
echo " - Importés : " . count($imported) . " départements\n";
|
||||
echo " - Manquants : " . count($missingDepts) . " départements\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Erreur : " . $e->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user