convert kartaview txt to gpx trace
This commit is contained in:
parent
8426b17cca
commit
fe5dc02ff5
|
@ -0,0 +1,50 @@
|
||||||
|
<?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.61844552" lon="2.12523291">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61843896" lon="2.12523893">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61843074" lon="2.12524569">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61842333" lon="2.12525403">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61842045" lon="2.12526892">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61842059" lon="2.12528606">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.6184195" lon="2.12530535">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61841833" lon="2.12532048">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61841874" lon="2.1253338">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61841782" lon="2.12534683">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61841239" lon="2.1253613">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61840633" lon="2.12537593">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61839901" lon="2.12539011">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61839192" lon="2.1254007">
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="48.61838873" lon="2.12540309">
|
||||||
|
</trkpt>
|
||||||
|
</trkseg>
|
||||||
|
</trk>
|
||||||
|
</gpx>
|
|
@ -3,48 +3,56 @@
|
||||||
conversion de données exif
|
conversion de données exif
|
||||||
**/
|
**/
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
|
// @ts-ignore
|
||||||
|
import path from "node:path";
|
||||||
|
import minimist from 'minimist';
|
||||||
|
|
||||||
const dossier_photo: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/2785606"
|
// configs
|
||||||
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 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 gpxData: any = {}
|
||||||
let tableKartaviewTrace = []
|
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() {
|
||||||
|
|
||||||
let track_points;
|
let track_points: string = '';
|
||||||
// TODO build track points
|
// TODO build track points
|
||||||
tableKartaviewTrace.forEach((elem: any) => {
|
tableKartaviewTrace.forEach((elem: any) => {
|
||||||
track_points = track_points + '<trkpt lat="' + elem[1] + '" lon="' + elem[1] + ">\n'
|
track_points = `${track_points}<trkpt lat="${elem[0]}" lon="${elem[1]}">
|
||||||
|
</trkpt>
|
||||||
|
`
|
||||||
})
|
})
|
||||||
|
|
||||||
let content = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n' +
|
let content = `<?xml version='1.0' encoding='UTF-8'?>
|
||||||
'<gpx version="1.1" creator="JOSM GPX export" xmlns="http://www.topografix.com/GPX/1/1"\n' +
|
<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"\n' +
|
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">\n' +
|
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
||||||
' <metadata>\n' +
|
<metadata>
|
||||||
' <desc>trace_gpx_de_demo</desc>\n' +
|
<desc>trace_gpx_de_demo</desc>
|
||||||
' <author>\n' +
|
<author>
|
||||||
' <name>somebody</name>\n' +
|
<name>somebody</name>
|
||||||
' </author>\n' +
|
</author>
|
||||||
' <copyright author="somebody">\n' +
|
<copyright author="somebody">
|
||||||
// ' <year>2022</year>\n' +
|
<year>2023</year>
|
||||||
' <license>https://creativecommons.org/licenses/by-sa/2.5</license>\n' +
|
<license>https://creativecommons.org/licenses/by-sa/2.5</license>
|
||||||
' </copyright>\n' +
|
</copyright>
|
||||||
' <keywords>nada</keywords>\n' +
|
<keywords>nada</keywords>
|
||||||
// ' <time>2022-01-20T21:35:02.039062Z</time>\n' +
|
</metadata>
|
||||||
// ' <bounds minlat="48.6835305" minlon="2.1368623" maxlat="48.68647" maxlon="2.1427953"/>\n' +
|
<trk>
|
||||||
' </metadata>\n' +
|
<trkseg>
|
||||||
// ' <wpt lat="48.686470006111435" lon="2.139083136320114">\n' +
|
${track_points}
|
||||||
// ' </wpt>\n' +
|
</trkseg>
|
||||||
' <trk>\n' +
|
</trk>
|
||||||
' <trkseg>\n' +
|
</gpx>`
|
||||||
track_points +
|
|
||||||
// ' <trkpt lat="48.68359424514746" lon="2.141218174695969">\n' +
|
|
||||||
' </trkpt>\n' +
|
|
||||||
' </trkseg>\n' +
|
|
||||||
' </trk>\n' +
|
|
||||||
'</gpx>'
|
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -59,14 +67,15 @@ function openGPX(filepath: any) {
|
||||||
const gpx_content = data;
|
const gpx_content = data;
|
||||||
let lines = gpx_content.split('\n')
|
let lines = gpx_content.split('\n')
|
||||||
console.log('lines.length', lines.length)
|
console.log('lines.length', lines.length)
|
||||||
|
|
||||||
|
// loop on all lines, only take the lines that contain :g:
|
||||||
lines.forEach((elem: any) => {
|
lines.forEach((elem: any) => {
|
||||||
if (elem.indexOf(":g:") > -1) {
|
if (elem.indexOf(":g:") > -1) {
|
||||||
|
// do stuff on gpxData to enrich it
|
||||||
let boom = elem.split(':')
|
let boom = elem.split(':')
|
||||||
let gpsmodel = boom[2]
|
let gpsmodel = boom[2]
|
||||||
let gps = gpsmodel.split(';')
|
let gps = gpsmodel.split(';')
|
||||||
tableKartaviewTrace.push(gps)
|
tableKartaviewTrace.push(gps)
|
||||||
// console.log('boom', boom)
|
|
||||||
// console.log('gps', gps)
|
|
||||||
let date = new Date(boom[0] * 1000)
|
let date = new Date(boom[0] * 1000)
|
||||||
console.log('*', date, gps[0], gps[1])
|
console.log('*', date, gps[0], gps[1])
|
||||||
|
|
||||||
|
@ -74,21 +83,42 @@ function openGPX(filepath: any) {
|
||||||
})
|
})
|
||||||
let content_gpx = makeGpxFromKartaview()
|
let content_gpx = makeGpxFromKartaview()
|
||||||
|
|
||||||
// writeFile('./output.gpx', content_gpx)
|
writeFile('' + sequence_name + '_trace.gpx', content_gpx)
|
||||||
// console.log('gpx_content', gpx_content)
|
// 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 cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd())
|
||||||
let listOfFiles: any = []
|
|
||||||
return listOfFiles
|
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) {
|
function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) {
|
||||||
|
@ -99,6 +129,22 @@ function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
openGPX(file_gpx)
|
||||||
let listOfFiles: any = getAllFilesInFolder(dossier_photo)
|
let listOfFiles: any = getAllFilesInFolder(dossier_photo)
|
||||||
|
|
||||||
console.log('listOfFiles', listOfFiles)
|
console.log('listOfFiles', listOfFiles)
|
||||||
|
|
Loading…
Reference in New Issue