Skip to content

Instantly share code, notes, and snippets.

@habi
Created October 20, 2021 19:53
Show Gist options
  • Save habi/3cb1113e6115642e440de47f68092222 to your computer and use it in GitHub Desktop.
Save habi/3cb1113e6115642e440de47f68092222 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Quickly whip up a series of commands to split a humongous GPX file"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import glob"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"track = glob.glob('R*.gpx')[0]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RecordedTrack_Sept_19.gpx\n"
]
}
],
"source": [
"print(track)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Generate us a nice date range\n",
"# Nearly exactly copied from https://stackoverflow.com/a/1060330\n",
"from datetime import date, timedelta\n",
"\n",
"def daterange(start_date, end_date):\n",
" for n in range(int((end_date - start_date).days)):\n",
" yield start_date + timedelta(n)\n",
"\n",
"start_date = date(2021, 6, 10)\n",
"end_date = date(2021, 9, 25)\n",
"datelist = [single_date.strftime(\"%Y%m%d\") for single_date in daterange(start_date, end_date)]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import subprocess"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210610,stop=20210611 -o gpx -F 20210610.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210611,stop=20210612 -o gpx -F 20210611.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210612,stop=20210613 -o gpx -F 20210612.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210613,stop=20210614 -o gpx -F 20210613.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210614,stop=20210615 -o gpx -F 20210614.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210615,stop=20210616 -o gpx -F 20210615.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210616,stop=20210617 -o gpx -F 20210616.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210617,stop=20210618 -o gpx -F 20210617.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210618,stop=20210619 -o gpx -F 20210618.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210619,stop=20210620 -o gpx -F 20210619.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210620,stop=20210621 -o gpx -F 20210620.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210621,stop=20210622 -o gpx -F 20210621.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210622,stop=20210623 -o gpx -F 20210622.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210623,stop=20210624 -o gpx -F 20210623.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210624,stop=20210625 -o gpx -F 20210624.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210625,stop=20210626 -o gpx -F 20210625.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210626,stop=20210627 -o gpx -F 20210626.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210627,stop=20210628 -o gpx -F 20210627.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210628,stop=20210629 -o gpx -F 20210628.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210629,stop=20210630 -o gpx -F 20210629.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210630,stop=20210701 -o gpx -F 20210630.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210701,stop=20210702 -o gpx -F 20210701.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210702,stop=20210703 -o gpx -F 20210702.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210703,stop=20210704 -o gpx -F 20210703.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210704,stop=20210705 -o gpx -F 20210704.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210705,stop=20210706 -o gpx -F 20210705.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210706,stop=20210707 -o gpx -F 20210706.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210707,stop=20210708 -o gpx -F 20210707.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210708,stop=20210709 -o gpx -F 20210708.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210709,stop=20210710 -o gpx -F 20210709.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210710,stop=20210711 -o gpx -F 20210710.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210711,stop=20210712 -o gpx -F 20210711.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210712,stop=20210713 -o gpx -F 20210712.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210713,stop=20210714 -o gpx -F 20210713.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210714,stop=20210715 -o gpx -F 20210714.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210715,stop=20210716 -o gpx -F 20210715.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210716,stop=20210717 -o gpx -F 20210716.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210717,stop=20210718 -o gpx -F 20210717.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210718,stop=20210719 -o gpx -F 20210718.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210719,stop=20210720 -o gpx -F 20210719.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210720,stop=20210721 -o gpx -F 20210720.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210721,stop=20210722 -o gpx -F 20210721.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210722,stop=20210723 -o gpx -F 20210722.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210723,stop=20210724 -o gpx -F 20210723.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210724,stop=20210725 -o gpx -F 20210724.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210725,stop=20210726 -o gpx -F 20210725.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210726,stop=20210727 -o gpx -F 20210726.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210727,stop=20210728 -o gpx -F 20210727.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210728,stop=20210729 -o gpx -F 20210728.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210729,stop=20210730 -o gpx -F 20210729.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210730,stop=20210731 -o gpx -F 20210730.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210731,stop=20210801 -o gpx -F 20210731.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210801,stop=20210802 -o gpx -F 20210801.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210802,stop=20210803 -o gpx -F 20210802.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210803,stop=20210804 -o gpx -F 20210803.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210804,stop=20210805 -o gpx -F 20210804.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210805,stop=20210806 -o gpx -F 20210805.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210806,stop=20210807 -o gpx -F 20210806.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210807,stop=20210808 -o gpx -F 20210807.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210808,stop=20210809 -o gpx -F 20210808.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210809,stop=20210810 -o gpx -F 20210809.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210810,stop=20210811 -o gpx -F 20210810.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210811,stop=20210812 -o gpx -F 20210811.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210812,stop=20210813 -o gpx -F 20210812.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210813,stop=20210814 -o gpx -F 20210813.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210814,stop=20210815 -o gpx -F 20210814.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210815,stop=20210816 -o gpx -F 20210815.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210816,stop=20210817 -o gpx -F 20210816.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210817,stop=20210818 -o gpx -F 20210817.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210818,stop=20210819 -o gpx -F 20210818.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210819,stop=20210820 -o gpx -F 20210819.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210820,stop=20210821 -o gpx -F 20210820.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210821,stop=20210822 -o gpx -F 20210821.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210822,stop=20210823 -o gpx -F 20210822.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210823,stop=20210824 -o gpx -F 20210823.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210824,stop=20210825 -o gpx -F 20210824.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210825,stop=20210826 -o gpx -F 20210825.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210826,stop=20210827 -o gpx -F 20210826.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210827,stop=20210828 -o gpx -F 20210827.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210828,stop=20210829 -o gpx -F 20210828.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210829,stop=20210830 -o gpx -F 20210829.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210830,stop=20210831 -o gpx -F 20210830.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210831,stop=20210901 -o gpx -F 20210831.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210901,stop=20210902 -o gpx -F 20210901.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210902,stop=20210903 -o gpx -F 20210902.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210903,stop=20210904 -o gpx -F 20210903.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210904,stop=20210905 -o gpx -F 20210904.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210905,stop=20210906 -o gpx -F 20210905.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210906,stop=20210907 -o gpx -F 20210906.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210907,stop=20210908 -o gpx -F 20210907.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210908,stop=20210909 -o gpx -F 20210908.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210909,stop=20210910 -o gpx -F 20210909.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210910,stop=20210911 -o gpx -F 20210910.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210911,stop=20210912 -o gpx -F 20210911.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210912,stop=20210913 -o gpx -F 20210912.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210913,stop=20210914 -o gpx -F 20210913.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210914,stop=20210915 -o gpx -F 20210914.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210915,stop=20210916 -o gpx -F 20210915.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210916,stop=20210917 -o gpx -F 20210916.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210917,stop=20210918 -o gpx -F 20210917.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210918,stop=20210919 -o gpx -F 20210918.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210919,stop=20210920 -o gpx -F 20210919.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210920,stop=20210921 -o gpx -F 20210920.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210921,stop=20210922 -o gpx -F 20210921.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210922,stop=20210923 -o gpx -F 20210922.gpx -o gpx\n",
"gpsbabel -w -r -t -i gpx -f RecordedTrack_Sept_19.gpx -x track,merge,start=20210923,stop=20210924 -o gpx -F 20210923.gpx -o gpx\n"
]
}
],
"source": [
"for c,i in enumerate(datelist[:-1]):\n",
" command = \"gpsbabel -w -r -t -i gpx -f %s -x track,merge,start=%s,stop=%s -o gpx -F %s.gpx -o gpx\" % (\n",
" track,\n",
" datelist[c],\n",
" datelist[c +1],\n",
" datelist[c])\n",
" print(command)\n",
" #subprocess.check_output(command)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment