Skip to content

Commit

Permalink
Improve README re initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
niborg committed Jul 27, 2024
1 parent 6137069 commit fde464b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
## What It Does

This library reads GPX files and provides an API for reading and manipulating
the data as objects. For more info on the GPX format, see
the data as objects. For more info on the GPX format, see
http://www.topografix.com/gpx.asp.

In addition to parsing GPX files, this library is capable of converting
Magellan NMEA files to GPX, converting GeoJSON data to GPX, and writing
new GPX files. It can crop and delete rectangular areas within a file,
new GPX files. It can crop and delete rectangular areas within a file,
and it also calculates some meta-data about the tracks and points in a file (such as distance, duration, average speed, etc).

## Requirements
Expand All @@ -20,12 +20,23 @@ and it also calculates some meta-data about the tracks and points in a file (suc
- As of `1.0.0`, `gpx` requires at least Ruby 2.2 to run.

## Installation

Add to your gemfile:

```
gem 'gpx'
```

## Examples

Initialize a `GPXFile` object with either a file-like object or a string representation:

```ruby
gpx = GPX::GPXFile.new(:gpx_file => string_io) # Anything that responds to `read`
gpx = GPX::GPXFile.new(:gpx_file => path_to_a_file)
gpx = GPX::GPXFile.new(:gpx_data => some_string)
```

Reading a GPX file, and cropping its contents to a given area:

```ruby
Expand All @@ -36,6 +47,7 @@ gpx.write(filename) # Save it
```

Converting a Magellan track log to GPX:

```ruby
if GPX::MagellanTrackLog::is_magellan_file?(filename)
GPX::MagellanTrackLog::convert_to_gpx(filename, "#{filename}.gpx")
Expand All @@ -44,6 +56,7 @@ end

Converting GeoJSON data to GPX can be achieved by providing a
file path, file, or the data in string format:

```ruby
# Converting from a file name
gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: 'mygeojsonfile.json')
Expand All @@ -67,6 +80,7 @@ gpx_file = GPX::GeoJSON.convert_to_gpx(
```

Exporting an ActiveRecord to GPXFile (as Waypoints)

```ruby
#
# Our active record in this example is called stop
Expand Down Expand Up @@ -111,12 +125,11 @@ Mime::Type.register "application/gpx+xml", :gpx

You have a complete example on how to create a gpx file from scratch on `tests/output_text.rb`.


## Notes

This library was written to bridge the gap between my Garmin Geko
and my website, WalkingBoss.org (RIP). For that reason, it has always been more of a
work-in-progress than an attempt at full GPX compliance. The track side of the
and my website, WalkingBoss.org (RIP). For that reason, it has always been more of a
work-in-progress than an attempt at full GPX compliance. The track side of the
library has seen much more use than the route/waypoint side, so if you're doing
something with routes or waypoints, you may need to tweak some things.

Expand All @@ -126,7 +139,7 @@ working with tracks from several days or weeks.

Finally, it should be noted that none of the distance/speed calculation or
crop/delete code has been tested under International Date Line-crossing
conditions. That particular part of the code will likely be unreliable if
conditions. That particular part of the code will likely be unreliable if
you're zig-zagging across 180 degrees longitude routinely.

## License
Expand Down

0 comments on commit fde464b

Please sign in to comment.