JuanIrache / gopro-telemetry

Reads telemetry from the GPMF track in GoPro cameras (Hero5 and later) and converts it to multiple formats
https://tailorandwayne.com/gopro-telemetry-extractor/
MIT License
310 stars 56 forks source link

KML & GPX presets- invalid characters #181

Closed barney2074 closed 1 year ago

barney2074 commented 1 year ago

Hello,

Firstly- thank you for gopro-telemetry- I'm only getting started, but it seems very useful

When using the gpx & kml presets, the output contains invalid characters- for example in the KML file, \n and \ characters image

I can fix this by post-processing the output files, but how can I prevent this from occurring ?

thanks

Andrew

JuanIrache commented 1 year ago

Hi. I'm glad you find the module useful.

\n are line breaks. I don't think they should be considered invalid, even if the typical line breaks are not the same on all operating systems. If you think this is wrong, can you provide more context?

Thank you

barney2074 commented 1 year ago

Hi @JuanIrache

Yes, I realise they are line breaks (and fairly easy to clean up)- but applications such as Google Earth or QGIS will not open the KML or GPX files- with errors of incorrect format/syntax

thanks

Andrew

JuanIrache commented 1 year ago

Are line breaks incorrect in GPX files?

barney2074 commented 1 year ago

Hi @JuanIrache

I've played around with it some more, and tested the other presets. It seems that the presets other than geojson and mgjson give me literal newline (\n) and backslash characters in the outputs i.e geojson and mgjson are ok

I was originally running on a Ubuntu machine, but I've also tested on a Windows machine & it behaves the same

I've had a look at the code & would guess that something like this part of toCsv.js might have something to do with it ? image

Andrew

JuanIrache commented 1 year ago

That is indeed where new lines are created. What I don't see is why a GPX file should not have new lines. Could you provide context for that?

On Wed, 2 Nov 2022 at 00:33, barney2074 @.***> wrote:

Hi @JuanIrache https://github.com/JuanIrache

I've played around with it some more, and tested the other presets. It seems that the presets other than geojson and mgjson give me literal newline (\n) and backslash characters in the outputs i.e geojson and mgjson are ok

I was originally running on a Ubuntu machine, but I've also tested on a Windows machine & it behaves the same

I've had a look at the code & would guess that something like this part of toCsv.js might have something to do with it ? [image: image] https://user-images.githubusercontent.com/25944617/199361442-30ef1403-a2fa-4ddb-b2ac-396edb3ccd6e.png

Andrew

— Reply to this email directly, view it on GitHub https://github.com/JuanIrache/gopro-telemetry/issues/181#issuecomment-1299356468, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIX772ZAGEHLO7TWING3TDWGGSGDANCNFSM6AAAAAARTUS6J4 . You are receiving this because you were mentioned.Message ID: @.***>

barney2074 commented 1 year ago

Hi @JuanIrache

I'm not sure if I'm missing something- but the problem (for me at least) is that the output contains literal \n characters (not new lines)

So for instance- a CSV file looks like this image

thanks for your help- I can easily fix this after the files have been generated

Andrew

JuanIrache commented 1 year ago

I see. Maybe the module is escaping those special characters under certain circumstances? It does not seem to happen on my end, but we can leave this open to keep an eye on it

barney2074 commented 1 year ago

Thanks Juan Let me know if there is anything I can help with to replicate or solve the issue

(I don't have any JS skills to speak of)

Andrew

forna commented 1 year ago

Looking at the first screenshot, in addition to the \n you also have the escaped quotes \" It means you are using JSON.stringify to save the GPX data. However the GPX is in XML, not JSON, so it is incorrect to use the JSON.stringify.

While for full telemetry it looks like this (notice the fs.writeFileSync with JSON.stringify):

gpmfExtract(file)
    .then(extracted => {
        goproTelemetry(extracted, {}, telemetry => {
            fs.writeFileSync('full-telemetry.json', JSON.stringify(telemetry));
            console.log('Telemetry saved as JSON');
        });
    })
    .catch(error => console.error(error));

For the GPX it looks like this (no JSON.stringify):

gpmfExtract(file)
    .then(extracted => {
        goProTelemetry(extracted, {
            preset: 'gpx'
        }, telemetry => {
            fs.writeFileSync( 'gps-only.gpx', telemetry);
            console.log('GPS saved as GPX');
        });
    })
    .catch(error => console.error(error));