/** * csv_to_geojson.ts * * Convertir un fichier CSV en GeoJSON, en précisant les colonnes latitude et longitude * * Utilisation: * * npx ts-node csv_to_geojson.ts -d etalab_data/panneaux -f panneaux_limite_de_vitesse_fr_panoramax_detections.csv --latColumn 'GPSLatitude' --lonColumn 'GPSLongitude' -h * */ import fs, { writeFile } from 'fs'; import path from 'path'; import minimist from 'minimist'; import { csvToGeoJSON, checkFile, countGeoJSONFeatures } from './csv_to_geojson.utils'; import { CSVConversionOptions } from './csv_to_geojson.utils'; // config des arguments de conversion const args = minimist(process.argv.slice(2), { alias: { dir: 'd', // dossier source file: 'f', // fichier source latColumn: 'lat', // colonne latitude lonColumn: 'lon', // colonne longitude wktColumn: 'wkt', // Nouvelle alias pour la colonne WKT hasHeaders: 'h', // headers présents }, default: { hasHeaders: true, }, }); checkFile(args); let geojsonContent = csvToGeoJSON(args); // Construire le chemin de sortie dans le même dossier que le fichier source const outputPath = path.join(args.dir, `${args.file}.geojson`); // Écrire le fichier GeoJSON fs.writeFileSync(outputPath, JSON.stringify(geojsonContent, null, 2)); console.log(`Fichier GeoJSON créé: ${outputPath}`); countGeoJSONFeatures(args);