Coder Social home page Coder Social logo

nidhaloff / gpx-converter Goto Github PK

View Code? Open in Web Editor NEW
66.0 8.0 18.0 295 KB

python package for manipulating gpx files and easily converting gpx to other different formats

Home Page: https://gpx-converter.readthedocs.io/en/latest/

License: MIT License

Makefile 6.57% Python 93.43%
gpx gpx-files gpx-parser gpx-format gpx-converter converter file-converter csv-parser csv-files csv-converter

gpx-converter's Introduction

gpx-converter

gpx-converter-icon

image

image

Documentation Status

PyPI - Wheel

image

PyPI - License

Twitter URL

GPX manipulation for humans

Python package for manipulating gpx files and easily convert gpx to other different formats.

When & Why

  • You need to convert GPX to other formats
  • You need to convert other formats like csv to GPX
  • You want to interpolate the GPX coordinates
  • High level of abstraction
  • Stable API
  • easy to use and to extend

Motivation

I decided to create this project because I had gpx data that I needed to manipulate. I searched for a python package for this but I did not find what I was looking for, therefore I created the gpx-converter package to make gpx files manipulation very easy. Furthermore, the package contains methods for applying interpolation on the gpx data. This feature was very helpful for me since I also needed to interpolate the gpx data and convert it to csv. Feel free to contribute or to give me feedback anytime :)

Features

  • Convert gpx files to other formats such as csv, numpy arrays, dataframes, excel and json
  • Convert csv files to gpx
  • Apply interpolation on the gpx data

Installation

$ pip install -U gpx-converter

Quick Usage

from gpx_converter import Converter

Just read the gpx to dictionary

dic = Converter(input_file='your_input.gpx').gpx_to_dictionary(latitude_key='latitude', longitude_key='longitude')
# now you have a dictionary and can access the longitudes and latitudes values from the keys
latitudes = dic['latitude']
longitudes = dic['longitude']

Convert GPX to other formats

  • Convert from gpx to csv:
Converter(input_file='your_input.gpx').gpx_to_csv(output_file='your_output.csv')
  • Convert from gpx to excel sheets:
Converter(input_file='your_input.gpx').gpx_to_excel(output_file='your_output.xlsx')
  • Convert from gpx to json:
Converter(input_file='your_input.gpx').gpx_to_json(output_file='your_output.json)
  • Convert gpx file to dataframe:
df = Converter(input_file='your_input.gpx').gpx_to_dataframe()
  • Convert gpx file to numpy array:
np_array = Converter(input_file='your_input.gpx').gpx_to_numpy_array()

Now convert other formats to GPX

  • csv to gpx
Converter(input_file='your_input.csv').csv_to_gpx(lats_colname='column_name_of_latitudes',
                                                 longs_colname='column_name_of_longitudes',
                                                 output_file='your_output.gpx')
  • excel to gpx
Converter(input_file='your_input.xlsx').excel_to_gpx(lats_colname='column_name_of_latitudes',
                                                 longs_colname='column_name_of_longitudes',
                                                 output_file='your_output.gpx')
  • dataframe to gpx (notice that the method is static)
Converter.dataframe_to_gpx(input_df=your_df,
                           lats_colname='column_name_of_latitudes',
                           longs_colname='column_name_of_longitudes',
                           output_file='your_output.gpx')
  • json to gpx
Converter(input_file='your_input.json').json_to_gpx(input_df=your_df,
                                                   lats_colname='column_name_of_latitudes',
                                                   longs_colname='column_name_of_longitudes',
                                                   output_file='your_output.gpx')
  • Automate the conversion of multiple csv file to gpx:
Converter.convert_multi_csv_to_gpx(dirpath='your_directory/')
  • Apply spline interpolation on gpx file (you need to install scipy for this to work):
interpolated_coordinates = Converter.spline_interpolation(cv=your_array_of_control_vertices)

Usage from terminal

Alternatively you can use the gpx_converter directly from terminal. You just need to pass the function, input file and output file as arguments.

  • function: the conversion method you want to use. For example "gpx_to_csv"
  • input file: path to your input file
  • output file: path to your output file
$ gpx_converter --function "gpx_to_csv" --input_file "home/your_input.gpx" --output_file "home/your_output.csv"

or maybe you prefer the short version

$ gpx_converter -func "gpx_to_csv" -in "home/your_input.gpx" -out "home/your_output.csv"

Check this article to know more about gpx files and how to use the gpx-converter package. https://medium.com/p/57da00bd36fc/edit

Contributions

Contributions are always welcome. Make sure you check the guidlines first https://gpx-converter.readthedocs.io/en/latest/contributing.html

gpx-converter's People

Contributors

arthavruksha avatar dcamejo1 avatar dependabot[bot] avatar nidhaloff avatar riemerk avatar silakanveli avatar sirdrakeistda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpx-converter's Issues

elevation not extracted

  • gpx_converter version: 2.0.0
  • Python version: 3.9.13
  • Operating System: Mac OS Monterey 12.5

Description

I created a virtualmachine for my project and installed gpx-converter to convert gpx file to json. I tested it out on a gpx file I have and saw that the elevation is not being extracted. Here is a sample trackpoint, my usage, and my output.

Sample GPX

<trkseg>
      <trkpt lat="45.757796665" lon="-87.087254604">
        <ele>0</ele>
        <time>1970-01-01T00:00:00Z</time>
      </trkpt>
      <trkpt lat="45.757796665" lon="-87.087254604">
        <ele>0</ele>
        <time>1970-01-01T00:00:00Z</time>
      </trkpt>
      <trkpt lat="45.757796665" lon="-87.087254604">
        <ele>0</ele>
        <time>1970-01-01T00:00:00Z</time>
      </trkpt>
      <trkpt lat="45.757561031" lon="-87.087239819">
        <ele>0</ele>
        <time>1970-01-01T00:00:00Z</time>
      </trkpt>
      <trkpt lat="45.757561031" lon="-87.087239819">
        <ele>0</ele>
        <time>1970-01-01T00:00:00Z</time>
      </trkpt>
      ....
</trkseg>

Usage

(env) ➜ pip install gpx-converter
(env) ➜ gpx_converter -func "gpx_to_json" -in "test/ag.gpx" -out "out.json" 
conversion from gpx_to_json was done successfully
(env) ➜  cat out.json
// summarized output since its long
{
  "time": [],
  "latitude": [],
  "longitude": []
  // no elevation key
} 

I expected to see the elevation key with the data associated, but I did not. I also tried to set the key manually via args programmatically but that did not do it. Am I doing something wrong?

Uppercase File Extension Not Supported

  • gpx_converter version: 1.7.3
  • Python version: 3.8.10
  • Operating System: Windows 10

Description

It seems that the check for input_extension fails if your GPX file has an uppercase file extension.

What I Did

from gpx_converter import Converter

gpx_file = r"C:\Data\Test_GPS_Data.GPX"
Converter(input_file=gpx_file).gpx_to_dataframe()

Throws the following:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-d42e2417745d> in <module>
----> 1 Converter(input_file=gpx_file).gpx_to_dataframe()

~\AppData\Local\programs\Anaconda3\envs\gpx\lib\site-packages\gpx_converter\base.py in gpx_to_dataframe(self, lats_colname, longs_colname, times_colname, alts_colname)
     59         """
     60         if self.input_extension != ".gpx":
---> 61             raise TypeError(f"input file must be a GPX file")
     62 
     63         if not lats_colname or not longs_colname:

TypeError: input file must be a GPX file

But running the following works:

from gpx_converter import Converter

gpx_file = r"C:\Data\Test_GPS_Data.GPX"
Converter(input_file=gpx_file.lower()).gpx_to_dataframe()

Should be as easy as changing that extension check to:

 if self.input_extension.lower() != ".gpx":

Add time and altitude column

When you convert the gpx file to another format it does not include the time and altitude column of the gpx file. These are essential if you want to analyze your gpx file

add more tests

Description

This issue is great for new comers who want to join the project. You can write more tests to test the functionality. Feel free to work on this or discuss it with me

Feature Request: Extract more data

Description

It would be nice to get more data from GPX files. For example number of satellites and all data from the extension part.

This is an example for a gpx section with data which could be imported:

<trkseg>
  <trkpt lat="34.837636" lon="15.02789063">
   <time>2021-12-11T00:05:49Z</time>
   <ele>23.72</ele>
   <sat>11</sat>  
   <extensions>
     <speed>0.000</speed>
     <accuracy>25.73</accuracy>
     <batterylevel>35.00</batterylevel>
     <useragent>API/0.1.0</useragent>
   </extensions>
  </trkpt>

Thank you for your great work. I like this tool very much.

Maintainers/Collaborators needed

Description

Hi everyone,

Since I don't have much time to work further on the package, I would like to invite collaborators to maintain it. If anyone is interested, please contact me here and I would give you access to the repo

csv to gpx

  • gpx_converter version: 2.1.0
  • Python version: 3.11
  • Operating System: Windows 10

Description

I want to convert my data from csv to gpx as points.

I would need the gpx to be generated as individual points and not as a path.
Do you have something like this in the pipeline?

csv_to_gpx does not use elevation and time

  • gpx_converter version:
  • Python version:3.8
  • Operating System:Ubuntu20.04

Description

When converting csv_to_gpx only latitude and longitude are taking in consideration. What about elevation, time, extensions?

I see that when converting from gpx to csv those are taking in consideration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.