scripts/kartaview_exif_mapper/main.ts

105 lines
3.6 KiB
TypeScript

/**
conversion de données gpx
conversion de données exif
**/
import * as fs from 'node:fs';
const dossier_photo: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/2785606"
const file_gpx: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/metadata_file/3596249/3596249_d875a_60a0f9bf38f99.txt"
let gpxData: any = {}
let tableKartaviewTrace = []
function makeGpxFromKartaview() {
let track_points;
// TODO build track points
tableKartaviewTrace.forEach((elem: any) => {
track_points = track_points + '<trkpt lat="' + elem[1] + '" lon="' + elem[1] + ">\n'
})
let content = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n' +
'<gpx version="1.1" creator="JOSM GPX export" xmlns="http://www.topografix.com/GPX/1/1"\n' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n' +
' xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n' +
' <metadata>\n' +
' <desc>trace_gpx_de_demo</desc>\n' +
' <author>\n' +
' <name>somebody</name>\n' +
' </author>\n' +
' <copyright author="somebody">\n' +
// ' <year>2022</year>\n' +
' <license>https://creativecommons.org/licenses/by-sa/2.5</license>\n' +
' </copyright>\n' +
' <keywords>nada</keywords>\n' +
// ' <time>2022-01-20T21:35:02.039062Z</time>\n' +
// ' <bounds minlat="48.6835305" minlon="2.1368623" maxlat="48.68647" maxlon="2.1427953"/>\n' +
' </metadata>\n' +
// ' <wpt lat="48.686470006111435" lon="2.139083136320114">\n' +
// ' </wpt>\n' +
' <trk>\n' +
' <trkseg>\n' +
track_points +
// ' <trkpt lat="48.68359424514746" lon="2.141218174695969">\n' +
' </trkpt>\n' +
' </trkseg>\n' +
' </trk>\n' +
'</gpx>'
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)
lines.forEach((elem: any) => {
if (elem.indexOf(":g:") > -1) {
let boom = elem.split(':')
let gpsmodel = boom[2]
let gps = gpsmodel.split(';')
tableKartaviewTrace.push(gps)
// console.log('boom', boom)
// console.log('gps', gps)
let date = new Date(boom[0] * 1000)
console.log('*', date, gps[0], gps[1])
}
})
let content_gpx = makeGpxFromKartaview()
// writeFile('./output.gpx', content_gpx)
// console.log('gpx_content', gpx_content)
})
// loop on all lines, only take the lines that contain :g:
// do stuff on gpxData to enrich it
}
function writeFile(name, content) {
console.log('name,content', name, content)
fs.writeFileSync(name,content)
}
function getAllFilesInFolder(folderPath: any) {
let listOfFiles: any = []
return listOfFiles
}
function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) {
listOfFiles.forEach((elem: any) => {
// find corresponding timestamp
// add exif info
// save file
})
}
openGPX(file_gpx)
let listOfFiles: any = getAllFilesInFolder(dossier_photo)
console.log('listOfFiles', listOfFiles)