[Tasker] Remove timestamps from GPX files

Started by Tapio, November 14, 2021, 18:09:56

0 Members and 2 Guests are viewing this topic.

Tapio

With the following Tasker task you can remove all timestamps from GPX files, a privacy option. Locus does only export GPX with timestamps.
Backup your files. It's not too thoroughly tested.

https://taskernet.com/shares/?user=AS35m8kdDIMDeveQcQfRglam%2Fah1mTW%2FWcg05FZ39c0i1q%2F77iY3E7cIwxCkXqJTaTA%3D&id=Task%3ARemoveTimestampsGPX
Tapiola MFV4+ theme for OAM Maps:
Discuss - Releases - DL latest - Install latest

Andrew Heard

I see the main processing is done via the line
sed -i -z 's;[\s\t]*&lt;time&gt;[^&lt;]*&lt;/time&gt;[^&lt;]*;;g' '%file'</Str>
very clever. Thanks for sharing @tapio.
LM4.26.3.1 RC10 GOLD user ID:c7d47597a
  •  

ColdAutumn

Quote from: tapio on November 14, 2021, 18:09:56
With the following Tasker task you can remove all timestamps from GPX files, a privacy option. Locus does only export GPX with timestamps.
Backup your files. It's not too thoroughly tested.

https://taskernet.com/shares/?user=AS35m8kdDIMDeveQcQfRglam%2Fah1mTW%2FWcg05FZ39c0i1q%2F77iY3E7cIwxCkXqJTaTA%3D&id=Task%3ARemoveTimestampsGPX

Do we need to install another app?
Sorry and many thanks.
  •  
    The following users thanked this post: Tapio

Tapio

#3
Yes, this is a Tasker script. Tasker is an Android automation app. Look for it in the PlayStore.
Tapiola MFV4+ theme for OAM Maps:
Discuss - Releases - DL latest - Install latest
  •  

lor74cas

Quote from: tapio on November 15, 2021, 10:30:50
Quote from: Andrew Heard on November 14, 2021, 22:01:57I see the main processing is done via the line
sed -i -z 's;[\s\t]*<time>[^<]*</time>[^<]*;;g'
Thx. Yeah, even if you're good at regex, sed is always tricky; it's especially the CRLF treatment of it, so I was happy about the -z option. Took me a while. The greedy matching of regex and multiple occurences of the same tags is also a thing always...
Just wanted to create a basic task. GPX files sometimes differ, e.g. some apps create a more flat output with nested xml tags and one trkpt per line...

Your next posting will be #1000 :)
Hello tapio,
I am recently trying to improve my knowledge of regexp and I would like to understand a couple of things about your method.
You have chosen to replace the text with null instead of deleting the row, for what reason?
The search for the entire line containing the time tag would be done with:
^ \ s * <time. * / time> $
while you use
[\ s \ t] * <time> [^ <] * </time> [^ <] *
\ s should ensure that both spaces and tabs are captured
then I see that you wanted to exclude any internal and external tags with [^ <], but I have not found any gpx exported from locus with these characteristics.
Mine is not a criticism, I'm just trying to understand why you made these choices out of pure curiosity and desire to learn.
Locus Map 4
Locus Map for Garmin
Locus Tasker
  •  

Tapio

#5
Ugh, I need to look again. Just some related thoughts I hope:

a) I didn't only have Locus GPX in mind. Some other apps were in use as well, they create different xml formats. Replace with NULL? Do I leave an ugly empty line? May need to look at it again.
b) time xml tag may be stretched over multiple lines.
c) I think with the exclusion of the bracket I prevented greedy matching. Keep in mind Regex matches greedy. a.*b matches until the last "b": 1234abcdgebabbbgggchbdkj - i.e. in GPX it would match from first <time> until the last </time> it can find. This would effectively delete most of the gpx - this is also because sed -z in a way flattens the whole file to one line (otherwise, in the default line-by-line style of sed, regex wouldn't work for xml tag structures IMO)
d) As for the tab I probably was just lazy to look into docs, wasn't sure about it being included in \s, thanks for the info
Tapiola MFV4+ theme for OAM Maps:
Discuss - Releases - DL latest - Install latest
  •  

lor74cas

Quote from: tapio on January 07, 2022, 11:35:23
Ugh, I need to look again. Just some related thoughts I hope:

a) I didn't only have Locus GPX in mind. Some other apps were in use as well, they create different xml formats. Replace with NULL? Do I leave an ugly empty line? May need to look at it again.
b) time xml tag may be stretched over multiple lines.
c) I think with the exclusion of the bracket I prevented greedy matching. Keep in mind Regex matches greedy. a.*b matches until the last "b": 1234abcdgebabbbgggchbdkj - i.e. in GPX it would match from first <time> until the last </time> it can find. This would effectively delete most of the gpx - this is also because sed -z in a way flattens the whole file to one line (otherwise, in the default line-by-line style of sed, regex wouldn't work for xml tag structures IMO)
d) As for the tab I probably was just lazy to look into docs, wasn't sure about it being included in \s, thanks for the info
a) I understand, I associate gpx with locus without thinking that there are other apps  :D
Replace with NULL? sed -i -z 's;[\s\t]*<time>[^<]*</time>[^<]*;;g' sed 's for substitution; regexp for search; text to replace with; g greedy operator' the null in this case is between ;;
b) do you have an example?
c) so you use this method because of the -z parameter, this part is also not clear to me, do you have a file example for which the -z parameter is needed?
Never using the -z parameter makes it harder for me to interpret your regexp, do you have an example file that made it necessary for you to use it?
d) Sometimes being a beginner like me is an advantage because without documentation you do nothing  ;D

Thanks for the comprehensive answers, you are very kind as always

Locus Map 4
Locus Map for Garmin
Locus Tasker
  •  

Tapio

b) As for the time tag, it is unlikely that it is spread over 3 lines. Just possible. It's just in oder to be safe. In another script, I delete trkpt tags. Those are most likely spread over multiple lines.
c) That's the point. -z kind of flattens to one line. Allowing analysis over (in the source) multiple lines. Usually sed operates per line. Then you can not match from xml tag start to xml tag end if tag start and tag end are in multiple lines.
Tapiola MFV4+ theme for OAM Maps:
Discuss - Releases - DL latest - Install latest
  •  
    The following users thanked this post: lor74cas

0709

Learn & understand Tasker ?
Fine. Roger.

Remove gpx timestamps ?
Method:

Sync gpx files by dropbox.
Use the (pc) gpx editor.
Show trackpoints display.
Right click column timestamps.
Select remove timestamps.
Save the gpx file. Done.
Locus Pro Classic 3.70.11 - Locus map 4.25.1.3 BETA
  •  

Tapio

#9
With this script I stay on Android and remove timestamps from all gpx files in a folder. Select dir, wait, done.
Tapiola MFV4+ theme for OAM Maps:
Discuss - Releases - DL latest - Install latest
  •  

0709

QuoteTasker ?  Fine. Roger
I don't use Tasker anyway.
Therefore this alternative.
Multiple choice is nice, isn't it?
That is all. Roger?

Locus Pro Classic 3.70.11 - Locus map 4.25.1.3 BETA
  •  
    The following users thanked this post: Tapio