convert all kartaview txt to gpx from folder list

This commit is contained in:
Tykayn 2023-08-14 10:33:57 +02:00 committed by tykayn
parent fe5dc02ff5
commit 4fcf19632f
3 changed files with 375 additions and 33 deletions

View File

@ -0,0 +1,285 @@
<?xml version='1.0' encoding='UTF-8'?>
<gpx version="1.1" creator="JOSM GPX export" xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<desc>trace_gpx_de_demo</desc>
<author>
<name>somebody</name>
</author>
<copyright author="somebody">
<year>2023</year>
<license>https://creativecommons.org/licenses/by-sa/2.5</license>
</copyright>
<keywords>nada</keywords>
</metadata>
<trk>
<trkseg>
<trkpt lat="48.9760757" lon="5.2837955">
</trkpt>
<trkpt lat="48.9761821" lon="5.2835646">
</trkpt>
<trkpt lat="48.9762937" lon="5.2833336">
</trkpt>
<trkpt lat="48.9764095" lon="5.2831023">
</trkpt>
<trkpt lat="48.9765259" lon="5.2828705">
</trkpt>
<trkpt lat="48.9766367" lon="5.2826421">
</trkpt>
<trkpt lat="48.976748" lon="5.282415">
</trkpt>
<trkpt lat="48.9768572" lon="5.2821895">
</trkpt>
<trkpt lat="48.9769629" lon="5.2819665">
</trkpt>
<trkpt lat="48.9770629" lon="5.2817418">
</trkpt>
<trkpt lat="48.9771532" lon="5.2815162">
</trkpt>
<trkpt lat="48.9772359" lon="5.2812796">
</trkpt>
<trkpt lat="48.9773113" lon="5.2810391">
</trkpt>
<trkpt lat="48.9773801" lon="5.2807971">
</trkpt>
<trkpt lat="48.9774427" lon="5.280548">
</trkpt>
<trkpt lat="48.9774998" lon="5.280294">
</trkpt>
<trkpt lat="48.9775484" lon="5.2800364">
</trkpt>
<trkpt lat="48.9775899" lon="5.2797733">
</trkpt>
<trkpt lat="48.9776242" lon="5.279511">
</trkpt>
<trkpt lat="48.9776524" lon="5.2792392">
</trkpt>
<trkpt lat="48.9776768" lon="5.2789673">
</trkpt>
<trkpt lat="48.9776978" lon="5.2786939">
</trkpt>
<trkpt lat="48.9777191" lon="5.2784224">
</trkpt>
<trkpt lat="48.9777399" lon="5.2781475">
</trkpt>
<trkpt lat="48.9777616" lon="5.2778708">
</trkpt>
<trkpt lat="48.977783" lon="5.2775973">
</trkpt>
<trkpt lat="48.9778037" lon="5.2773249">
</trkpt>
<trkpt lat="48.9778264" lon="5.2770534">
</trkpt>
<trkpt lat="48.9778494" lon="5.2767802">
</trkpt>
<trkpt lat="48.977872" lon="5.2765085">
</trkpt>
<trkpt lat="48.9778957" lon="5.2762299">
</trkpt>
<trkpt lat="48.9779169" lon="5.2759548">
</trkpt>
<trkpt lat="48.9779308" lon="5.2756793">
</trkpt>
<trkpt lat="48.9779335" lon="5.2754074">
</trkpt>
<trkpt lat="48.977921" lon="5.2751415">
</trkpt>
<trkpt lat="48.9778942" lon="5.2748823">
</trkpt>
<trkpt lat="48.9778546" lon="5.2746289">
</trkpt>
<trkpt lat="48.9778063" lon="5.2743813">
</trkpt>
<trkpt lat="48.9777527" lon="5.2741352">
</trkpt>
<trkpt lat="48.9776945" lon="5.2738903">
</trkpt>
<trkpt lat="48.9776349" lon="5.2736486">
</trkpt>
<trkpt lat="48.9775754" lon="5.2734092">
</trkpt>
<trkpt lat="48.9775183" lon="5.2731735">
</trkpt>
<trkpt lat="48.9774671" lon="5.272945">
</trkpt>
<trkpt lat="48.9774221" lon="5.2727202">
</trkpt>
<trkpt lat="48.9773862" lon="5.2725172">
</trkpt>
<trkpt lat="48.9773624" lon="5.2723438">
</trkpt>
<trkpt lat="48.9773483" lon="5.2722029">
</trkpt>
<trkpt lat="48.9773455" lon="5.2720821">
</trkpt>
<trkpt lat="48.9773561" lon="5.2719812">
</trkpt>
<trkpt lat="48.9773829" lon="5.2718954">
</trkpt>
<trkpt lat="48.9774247" lon="5.2718299">
</trkpt>
<trkpt lat="48.9774748" lon="5.2717928">
</trkpt>
<trkpt lat="48.9775209" lon="5.2717893">
</trkpt>
<trkpt lat="48.9775536" lon="5.2718125">
</trkpt>
<trkpt lat="48.9775736" lon="5.2718468">
</trkpt>
<trkpt lat="48.9775789" lon="5.2718856">
</trkpt>
<trkpt lat="48.9775741" lon="5.2719243">
</trkpt>
<trkpt lat="48.9775665" lon="5.2719777">
</trkpt>
<trkpt lat="48.9775604" lon="5.2720426">
</trkpt>
<trkpt lat="48.9775567" lon="5.2721085">
</trkpt>
<trkpt lat="48.9775582" lon="5.2721715">
</trkpt>
<trkpt lat="48.9775617" lon="5.2722292">
</trkpt>
<trkpt lat="48.9775691" lon="5.2723102">
</trkpt>
<trkpt lat="48.9775791" lon="5.2723911">
</trkpt>
<trkpt lat="48.9775922" lon="5.2724777">
</trkpt>
<trkpt lat="48.9776097" lon="5.272564">
</trkpt>
<trkpt lat="48.9776292" lon="5.2726512">
</trkpt>
<trkpt lat="48.9776521" lon="5.272739">
</trkpt>
<trkpt lat="48.9776786" lon="5.2728245">
</trkpt>
<trkpt lat="48.9777074" lon="5.2729075">
</trkpt>
<trkpt lat="48.9777399" lon="5.2729877">
</trkpt>
<trkpt lat="48.9777742" lon="5.2730625">
</trkpt>
<trkpt lat="48.9778093" lon="5.2731309">
</trkpt>
<trkpt lat="48.9778446" lon="5.2731911">
</trkpt>
<trkpt lat="48.9778815" lon="5.273247">
</trkpt>
<trkpt lat="48.9779194" lon="5.2732988">
</trkpt>
<trkpt lat="48.9779607" lon="5.2733426">
</trkpt>
<trkpt lat="48.9780067" lon="5.2733753">
</trkpt>
<trkpt lat="48.9780545" lon="5.2733953">
</trkpt>
<trkpt lat="48.9781012" lon="5.2734012">
</trkpt>
<trkpt lat="48.9781446" lon="5.2733962">
</trkpt>
<trkpt lat="48.9781842" lon="5.2733891">
</trkpt>
<trkpt lat="48.9782183" lon="5.2733882">
</trkpt>
<trkpt lat="48.9782423" lon="5.2733884">
</trkpt>
<trkpt lat="48.9782736" lon="5.2733732">
</trkpt>
<trkpt lat="48.9783034" lon="5.2733528">
</trkpt>
<trkpt lat="48.9783227" lon="5.2732956">
</trkpt>
<trkpt lat="48.9783355" lon="5.2732123">
</trkpt>
<trkpt lat="48.9783437" lon="5.2731272">
</trkpt>
<trkpt lat="48.9783531" lon="5.2730413">
</trkpt>
<trkpt lat="48.9783588" lon="5.2729599">
</trkpt>
<trkpt lat="48.9783662" lon="5.2728808">
</trkpt>
<trkpt lat="48.9783728" lon="5.2728019">
</trkpt>
<trkpt lat="48.9783811" lon="5.2727227">
</trkpt>
<trkpt lat="48.9783909" lon="5.2726499">
</trkpt>
<trkpt lat="48.9783997" lon="5.2725754">
</trkpt>
<trkpt lat="48.9784055" lon="5.272502">
</trkpt>
<trkpt lat="48.9784124" lon="5.272442">
</trkpt>
<trkpt lat="48.9784181" lon="5.2723803">
</trkpt>
<trkpt lat="48.978423" lon="5.272323">
</trkpt>
<trkpt lat="48.9784291" lon="5.2722656">
</trkpt>
<trkpt lat="48.9784327" lon="5.2722096">
</trkpt>
<trkpt lat="48.9784379" lon="5.2721537">
</trkpt>
<trkpt lat="48.9784425" lon="5.2721015">
</trkpt>
<trkpt lat="48.9784467" lon="5.2720489">
</trkpt>
<trkpt lat="48.9784517" lon="5.2719976">
</trkpt>
<trkpt lat="48.9784569" lon="5.2719455">
</trkpt>
<trkpt lat="48.9784618" lon="5.2718997">
</trkpt>
<trkpt lat="48.9784649" lon="5.2718578">
</trkpt>
<trkpt lat="48.9784675" lon="5.2718061">
</trkpt>
<trkpt lat="48.9784734" lon="5.2717469">
</trkpt>
<trkpt lat="48.9784762" lon="5.2716951">
</trkpt>
<trkpt lat="48.9784665" lon="5.2716556">
</trkpt>
<trkpt lat="48.9784523" lon="5.2716313">
</trkpt>
<trkpt lat="48.9784389" lon="5.2716215">
</trkpt>
<trkpt lat="48.9784233" lon="5.2716033">
</trkpt>
<trkpt lat="48.9784147" lon="5.2715814">
</trkpt>
<trkpt lat="48.9784066" lon="5.2715507">
</trkpt>
<trkpt lat="48.9784025" lon="5.2715092">
</trkpt>
<trkpt lat="48.9783996" lon="5.2714638">
</trkpt>
<trkpt lat="48.9783991" lon="5.2714114">
</trkpt>
<trkpt lat="48.9784005" lon="5.2713548">
</trkpt>
<trkpt lat="48.9784008" lon="5.2712958">
</trkpt>
<trkpt lat="48.9783985" lon="5.2712511">
</trkpt>
<trkpt lat="48.9783952" lon="5.271218">
</trkpt>
<trkpt lat="48.9783917" lon="5.271193">
</trkpt>
<trkpt lat="48.9783887" lon="5.2711759">
</trkpt>
<trkpt lat="48.978387" lon="5.2711651">
</trkpt>
<trkpt lat="48.9783858" lon="5.2711565">
</trkpt>
<trkpt lat="48.9783856" lon="5.2711454">
</trkpt>
<trkpt lat="48.9783857" lon="5.2711282">
</trkpt>
</trkseg>
</trk>
</gpx>

View File

@ -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

View File

@ -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('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)
}
}
})
console.log('reading folder ', folderPath)
filesList = fs.readdirSync(folderPath);
// console.log('readSubdirectories - files', folderPath, filesList.length)
// 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;
})
}
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)