Code Monkey home page Code Monkey logo

gpxkit's Introduction

GPXKit

A library for parsing and exporting GPX files with no dependencies besides Foundation.


Features

  • Parsing GPX files into a track struct
  • Exporting a track to a GPX xml
  • Support for iOS, macOS & watchOS
  • Optionally removes date and time from exported GPX for keeping privacy
  • Combine support
  • Height Map, geo-bounds, distance, and elevation information for an imported track
  • Waypoint support
  • Test coverage
  • Climb detection
  • Grade segmentation
  • Support for Garmin trackpoint extensions

Installation

To use the GPXKit library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/mmllr/GPXKit", from: "2.0.4")

Usage examples

Importing a track

import GPXKit

let parser = GPXFileParser(xmlString: xml)
    switch parser.parse() {
    case .success(let track):
        doSomethingWith(track)
    case .failure(let error):
        parseError = error
    }
...
func doSomethingWith(_ track: GPXTrack) {
    let formatter = MeasurementFormatter()
    formatter.unitStyle = .short
    formatter.unitOptions = .naturalScale
    formatter.numberFormatter.maximumFractionDigits = 1
    let trackGraph = track.graph
    print("Track length: \(formatter.string(from: Measurement<UnitLength>(value: trackGraph.distance, unit: .meters)))")
    print("Track elevation: \(formatter.string(from: Measurement<UnitLength>(value: trackGraph.elevationGain, unit: .meters)))")
    
    for point in track.trackPoints {
        print("Lat: \(point.coordinate.latitude), lon: \(point.coordinate.longitude)")
    }
}

Exporting a track

import GPXKit
let track: GPXTrack = ...
let exporter = GPXExporter(track: track, shouldExportDate: false)
print(exporter.xmlString)

Combine integration

import Combine
import GPXKit

let url = /// url with gpx
GPXFileParser.load(from: url)
   .publisher
   .map { track in
      // do something with parsed track 
   }

See tests for more usage examples.

Climb detection

To detect climbs in a track, use the TrackGraphs climb(epsilon:minimumGrade:maxJoinDistance:) method which returns an array of Climb values for given filter parameters.

let track: GPXTrack = ...
let climbs = track.graph.climbs(epsilon: 4.0, minimumGrade: 3.0, maxJoinDistance: 0.0)
// climbs is an array of `Climb` values, describing each climb (start, end, elevation, grade, FIETS score and so on...).

Documentation

Project documentation is available at GitHub Pages

Run the following commands from the projects root to generate the documentation:

[sudo] gem install jazzy
jazzy

Browse the documentation under the doc folder.

Contributing

Contributions to this project will be more than welcomed. Feel free to add a pull request or open an issue. If you require a feature that has yet to be available, do open an issue, describing why and what the feature could bring and how it would help you!

gpxkit's People

Contributors

mmllr avatar ricobeck avatar lamprechts avatar

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.