{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bbc19561-c6ac-451a-a164-197b74d2eda1",
   "metadata": {},
   "source": [
    "# Export track or track collection\n",
    "\n",
    "et *TrackWriter* pour stocker les données dans un fichier."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c701a910-68ad-4f03-bc5d-4d9d532b75dd",
   "metadata": {},
   "source": [
    "## As usual, let's start by defining our environment\n",
    "\n",
    "The first task is only useful for the online notebook and import the local tracklib code source. It's not necessary if tracklib is installed from PyPI."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d16b0999-919f-45db-a617-c942953c6e01",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# Import de tracklib\n",
    "module_path = os.path.abspath(os.path.join('../../../../..'))\n",
    "if module_path not in sys.path:\n",
    "    sys.path.append(module_path)\n",
    "\n",
    "# Import tracklib library\n",
    "import tracklib as tkl"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3cf518f-1c07-450e-845a-c8f6adec75d3",
   "metadata": {},
   "source": [
    "The following two imports are necessary for the tutorial:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a0c3db37-561c-43dd-b325-d1d1dc9c8bf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "840058f8-a043-4b35-95fb-797e56c632d0",
   "metadata": {},
   "source": [
    "## To export only the basics attributes of a track, position and timestamp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "94b29545-b6df-4b4f-aa07-8f6ff70b3118",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'resource_path' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m csvpath \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(\u001b[43mresource_path\u001b[49m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata/test/test_write_csv_minim.wkt\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m      2\u001b[0m tkl\u001b[38;5;241m.\u001b[39mTrackWriter\u001b[38;5;241m.\u001b[39mwriteToFile(track, csvpath, id_E\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m,id_N\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m,id_U\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m,id_T\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m3\u001b[39m,h\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m, separator\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m;\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'resource_path' is not defined"
     ]
    }
   ],
   "source": [
    "\n",
    "csvpath = os.path.join(resource_path, 'data/test/test_write_csv_minim.wkt')\n",
    "tkl.TrackWriter.writeToFile(track, csvpath, id_E=0,id_N=1,id_U=2,id_T=3,h=1, separator=\";\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5a1bd03-064a-4a16-b097-e1f4edbc2d2e",
   "metadata": {},
   "source": [
    "## To export basic attributes and analytical features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6b01c0e0-e3b4-4a66-96df-a29cc1b7f8f5",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'self' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m csvpath \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241m.\u001b[39mresource_path, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata/test/test_write_csv_2AF.wkt\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m      2\u001b[0m af_names \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mspeed\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mabs_curv\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m      3\u001b[0m TrackWriter\u001b[38;5;241m.\u001b[39mwriteToFile(track, csvpath, id_E\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m, id_N\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m, id_U\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m, id_T\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m3\u001b[39m, h\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m, \n\u001b[1;32m      4\u001b[0m                                separator\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m;\u001b[39m\u001b[38;5;124m\"\u001b[39m, af_names\u001b[38;5;241m=\u001b[39maf_names)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'self' is not defined"
     ]
    }
   ],
   "source": [
    "csvpath = os.path.join(self.resource_path, 'data/test/test_write_csv_2AF.wkt')\n",
    "af_names = ['speed', 'abs_curv']\n",
    "TrackWriter.writeToFile(track, csvpath, id_E=0, id_N=1, id_U=2, id_T=3, h=1, \n",
    "                               separator=\";\", af_names=af_names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57e42507-3dbc-4721-93ea-f1b9af126ae7",
   "metadata": {},
   "source": [
    "## Write one or many tracks in one or many GPX files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "61e01de4-267d-4fd4-80ca-726a7535f672",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'TrackWriter' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mTrackWriter\u001b[49m\u001b[38;5;241m.\u001b[39mwriteToGpx(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcollection, path\u001b[38;5;241m=\u001b[39mgpxpath, af\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, oneFile\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'TrackWriter' is not defined"
     ]
    }
   ],
   "source": [
    "TrackWriter.writeToGpx(self.collection, path=gpxpath, af=True, oneFile=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99250936-8578-47cc-821f-9e1a96606841",
   "metadata": {},
   "source": [
    "## Write in a KML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aa0f0b60-e50e-4178-a210-fee3a2252e48",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'self' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m kmlpath \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241m.\u001b[39mresource_path, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata/test/couplage.kml\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m      2\u001b[0m TrackWriter\u001b[38;5;241m.\u001b[39mwriteToKml(trace, path\u001b[38;5;241m=\u001b[39mkmlpath, \u001b[38;5;28mtype\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLINE\u001b[39m\u001b[38;5;124m\"\u001b[39m, af\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mspeed\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'self' is not defined"
     ]
    }
   ],
   "source": [
    "kmlpath = os.path.join(self.resource_path, 'data/test/couplage.kml')\n",
    "TrackWriter.writeToKml(trace, path=kmlpath, type=\"LINE\", af='speed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8113cc2-2895-4c1c-8316-f381fc4da312",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
