From 4fcf19632f2ee64e72ed1beadfd52e3c773fd73c Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 14 Aug 2023 10:33:57 +0200 Subject: [PATCH] convert all kartaview txt to gpx from folder list --- kartaview_exif_mapper/3596977_trace.gpx | 285 ++++++++++++++++++++++++ kartaview_exif_mapper/README.md | 4 +- kartaview_exif_mapper/main.ts | 119 +++++++--- 3 files changed, 375 insertions(+), 33 deletions(-) create mode 100644 kartaview_exif_mapper/3596977_trace.gpx diff --git a/kartaview_exif_mapper/3596977_trace.gpx b/kartaview_exif_mapper/3596977_trace.gpx new file mode 100644 index 00000000..fc2a78ef --- /dev/null +++ b/kartaview_exif_mapper/3596977_trace.gpx @@ -0,0 +1,285 @@ + + + + trace_gpx_de_demo + + somebody + + + 2023 + https://creativecommons.org/licenses/by-sa/2.5 + + nada + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kartaview_exif_mapper/README.md b/kartaview_exif_mapper/README.md index b2d1ff5a..a00ad1e4 100644 --- a/kartaview_exif_mapper/README.md +++ b/kartaview_exif_mapper/README.md @@ -2,9 +2,11 @@ Mapper les données exif des photos exportées de kartaview. +# installation +utiliser `npm i` # mode d'action -configurer le dossier en argument +configurer le dossier en argument dans le script, ou bien lancer celui ci avec l'argument folder. ```bash ts-node main.ts --folder=/folder/path diff --git a/kartaview_exif_mapper/main.ts b/kartaview_exif_mapper/main.ts index 7f24070c..add3e9fc 100644 --- a/kartaview_exif_mapper/main.ts +++ b/kartaview_exif_mapper/main.ts @@ -5,25 +5,60 @@ import * as fs from 'node:fs'; // @ts-ignore import path from "node:path"; +// @ts-ignore 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 folders_list_txt: any = ["3596249", + // "3596253", "3596977", + // "3675557", "3675577", "3716345", "4456921", "4457241", "4457257", "4457273", "4457289", "4457689", "4457705", "4539913", "4539929", "4539945", "4559529", + // "4559545", "4559561", "4559577", "4559593", "4559609", "4559625", "4559641", "4559657", "4559673", "4559689", "4559705", "4559721", "4559737", "4559753", + // "4559769", "4559785", "4559801", "4559817", "4559833", "4559849", "4559865", "4904153", "4904233", "4904249", "4904265", "4904281", "4904297", "4904313", + // "4904329", "4904345", "4904361", "4904377", "4904393", "5192937", "5193161", "5193177", "5193193", "5193209", "5193225", "5193321", "5193337", "5193417", + // "5193433", "5193449", "5201385", "5213385", "5213481", "5213529", "5234665", "5234857", "5234889", "5235001", "5324265", "5775977", "5775993", "5776009", + // "5776025", "6081417", "6081433", "6081449", "6081465", "6081689", "6081705", "6092281", "6092313", "6101305", "6102457", "6102473", "6102489", "6102521", + // "6102537", "6102569", "6127433", "6133465", "6242729", "6329129", "6329177", "6329241", "6329305", "6329321", "6738633", "6738809", "6738953", "6752761", + // "6752889", "6752905", "6752921", "6752937", "6752953", "6760985", "6761049", "6761289", "6794633", "7325929", "7326457", "7328265", "7330009", "7330025", + // "7330041", + "7330057"] +let folder = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/" 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 file_gpx: string = "3596249_d875a_60a0f9bf38f99.txt" + +let mini_arguments: any = minimist(process.argv.slice(2)) +console.log('mini_arguments', mini_arguments) + +if (mini_arguments['sequence']) { + sequence_name = mini_arguments['sequence'] +} +if (mini_arguments['folder']) { + folder = mini_arguments['folder'] +} +if (mini_arguments['gpx-output']) { + dossier_gpx = mini_arguments['gpx-output'] +} +if (mini_arguments['gpx-input']) { + file_gpx = mini_arguments['gpx-input'] +} + + +let dossier_photo: string = folder + "photo" +let dossier_gpx_input: string = folder + "metadata_file" +let path_gpx_input: string = dossier_gpx_input + "/" + sequence_name + "/" + file_gpx + +if (mini_arguments['gpx-input-path']) { + path_gpx_input = mini_arguments['gpx-input-path'] +} + 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() { +function makeGpxFromKartaview(tableKartaviewTrace: any) { + console.log('make gpx') let track_points: string = ''; // TODO build track points tableKartaviewTrace.forEach((elem: any) => { @@ -58,8 +93,9 @@ function makeGpxFromKartaview() { } -function openGPX(filepath: any) { - +function openKartaviewTxtGPX(filepath + : any) { + console.log('filepath', filepath) fs.readFile(filepath, 'utf8', (err, data) => { if (err) { throw err; @@ -68,6 +104,8 @@ function openGPX(filepath: any) { let lines = gpx_content.split('\n') console.log('lines.length', lines.length) + let tableKartaviewTrace: any = []; + // loop on all lines, only take the lines that contain :g: lines.forEach((elem: any) => { if (elem.indexOf(":g:") > -1) { @@ -81,7 +119,7 @@ function openGPX(filepath: any) { } }) - let content_gpx = makeGpxFromKartaview() + let content_gpx = makeGpxFromKartaview(tableKartaviewTrace) writeFile('' + sequence_name + '_trace.gpx', content_gpx) // console.log('gpx_content', gpx_content) @@ -97,28 +135,27 @@ let expandedFileList: any = [] * get a list of all files in a path * @param folderPath */ -function getAllFilesInFolder(folderPath: string) { +async function getAllFilesInFolder(folderPath: string) { let filesList: any = [] - fs.readdir(folderPath, (err, filesList) => { - if (err) throw err + console.log('reading folder ', folderPath) + filesList = fs.readdirSync(folderPath); + // console.log('readSubdirectories - files', folderPath, filesList.length) - console.log('readSubdirectories - files', filesList) + // filesList.forEach((subDirOrFile:any) => { + // const newFullPath = cwd + '/' + subDirOrFile + // + // if (fs.existsSync(newFullPath)) { + // const s = fs.statSync(newFullPath) + // + // if (s.isFile()) { + // expandedFileList.push(cwd + '/' + subDirOrFile) + // console.log('add file', cwd + '/' + subDirOrFile) + // } + // } + // }) + return 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) { @@ -144,7 +181,25 @@ function writeFile(fileName: string, fileContent: any) { } -openGPX(file_gpx) -let listOfFiles: any = getAllFilesInFolder(dossier_photo) +async function getGPXAndEnrichExifOfPhotosInFolder(sequence_number: string) { + + // get metadata txt file in metadata folder + getAllFilesInFolder(dossier_gpx_input + '/' + sequence_number) + .then(listOfFiles => { + // let listOfFiles: any = getAllFilesInFolder(dossier_gpx_input+ '/' + sequence_number ) + console.log('listOfFiles', listOfFiles) + listOfFiles?.forEach((file: string) => { + openKartaviewTxtGPX(dossier_gpx_input + '/' + sequence_number + '/' + file) + }) + }, err => { + throw new Error(err) + }) + + + // let listOfFiles: any = getAllFilesInFolder(dossier_photo + '/' + sequence_number) +} + +folders_list_txt.forEach((elem: string) => { + getGPXAndEnrichExifOfPhotosInFolder(elem) +}) -console.log('listOfFiles', listOfFiles)