https://github.com/rccoop/rcgpx
A library for reading/writing GPX files in Swift
https://github.com/rccoop/rcgpx
gpx gpx-files swift waypoints
Last synced: 8 months ago
JSON representation
A library for reading/writing GPX files in Swift
- Host: GitHub
- URL: https://github.com/rccoop/rcgpx
- Owner: RCCoop
- License: mit
- Created: 2021-07-09T20:11:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-28T21:01:06.000Z (about 3 years ago)
- Last Synced: 2024-12-01T06:09:57.210Z (over 1 year ago)
- Topics: gpx, gpx-files, swift, waypoints
- Language: Swift
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RCGPX

[](https://swiftpackageindex.com/RCCoop/RCGPX)
[](https://swiftpackageindex.com/RCCoop/RCGPX)
A simple library for reading & writing GPX tracks and waypoints in Swift, specifically designed for simplicity and ease of use.
# Index
- [Installation](#installation)
- [GPXDocument](#gpxdocument)
- [GPX Types](#gpx-types)
- [Reading GPX Files](#reading-gpx-files)
- [Writing GPX Files](#writing-gpx-files)
- [Dependencies](#dependencies)
# Installation
Swift Package Manager:
```
.package(url: "https://github.com/RCCoop/RCGPX.git", .upToNextMajor(from: "1.0.0"))
```
# GPXDocument
The root of a GPX file is represented by the `GPXDocument` struct, which is used as a container for any number of waypoints and tracks.
When creating a GPXDocument from scratch (rather than reading from an existing file), you may optionally add a name for the person or program that created the file, as well as the arrays of tracks and waypoints.
```swift
public struct GPXDocument {
public var creator: String?
public var waypoints: [GPXWaypoint]
public var tracks: [GPXTrack]
public var routes: [GPXRoute]
}
```
# GPX Types
- GPXTrack
- .Segment
- .Point
- GPXRoute
- .Point
- GPXWaypoint
# Reading GPX Files
```swift
let fileUrl = ...
let fileData = try Data(contentsOf: fileUrl)
let gpxString = try? String(contentsOf: fileUrl, encoding: .utf8)
let documentFromData = try? GPXDocument(fileData)
let documentFromFileUrl = try? GPXDocument(fileUrl)
let documentFromString = try? GPXDocument(gpxString)
```
# Writing GPX Files
```swift
let gpxDoc = GPXDocument(...)
let asData = gpxDoc.gpxData()
let asString = gpxDoc.gpxString()
```
## Dependencies
- [AEXML](https://github.com/tadija/AEXML) for reading and writing XML files