/** conversion de données gpx conversion de données exif **/ import * as fs from 'node:fs'; // @ts-ignore import path from "node:path"; import minimist from 'minimist'; // configs let sequence_name: string = '3596977' const dossier_photo: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/" + sequence_name let dossier_gpx: string = "." const file_gpx: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/metadata_file/" + sequence_name + "/3596249_d875a_60a0f9bf38f99.txt" let gpxData: any = {} let tableKartaviewTrace: any = [] let mini_arguments :any = minimist(process.argv.slice(2)) console.log('mini_arguments', mini_arguments) if(mini_arguments['sequence']){ sequence_name = mini_arguments['sequence'] } function makeGpxFromKartaview() { let track_points: string = ''; // TODO build track points tableKartaviewTrace.forEach((elem: any) => { track_points = `${track_points} ` }) let content = ` trace_gpx_de_demo somebody 2023 https://creativecommons.org/licenses/by-sa/2.5 nada ${track_points} ` return content; } function openGPX(filepath: any) { fs.readFile(filepath, 'utf8', (err, data) => { if (err) { throw err; } const gpx_content = data; let lines = gpx_content.split('\n') console.log('lines.length', lines.length) // loop on all lines, only take the lines that contain :g: lines.forEach((elem: any) => { if (elem.indexOf(":g:") > -1) { // do stuff on gpxData to enrich it let boom = elem.split(':') let gpsmodel = boom[2] let gps = gpsmodel.split(';') tableKartaviewTrace.push(gps) let date = new Date(boom[0] * 1000) console.log('*', date, gps[0], gps[1]) } }) let content_gpx = makeGpxFromKartaview() writeFile('' + sequence_name + '_trace.gpx', content_gpx) // console.log('gpx_content', gpx_content) }) } let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) let expandedFileList: any = [] /** * get a list of all files in a path * @param folderPath */ function getAllFilesInFolder(folderPath: string) { let filesList: any = [] fs.readdir(folderPath, (err, filesList) => { if (err) throw err console.log('readSubdirectories - files', filesList) filesList.forEach((subDirOrFile) => { const newFullPath = cwd + '/' + subDirOrFile if (fs.existsSync(newFullPath)) { const s = fs.statSync(newFullPath) if (s.isFile()) { expandedFileList.push(cwd + '/' + subDirOrFile) } } }) return filesList; }) } function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) { listOfFiles.forEach((elem: any) => { // find corresponding timestamp // add exif info // save file }) } function writeFile(fileName: string, fileContent: any) { console.log('write file', fileName) return fs.writeFile( `${dossier_gpx}/${fileName}`, fileContent, 'utf8', (err) => { if (err) { console.log(`Error writing file: ${err}`) } } ) } openGPX(file_gpx) let listOfFiles: any = getAllFilesInFolder(dossier_photo) console.log('listOfFiles', listOfFiles)