From fde464bc11613233147be14e842cf7470b26c3bd Mon Sep 17 00:00:00 2001 From: Nick Knipe Date: Fri, 26 Jul 2024 21:03:53 -0700 Subject: [PATCH] Improve README re initialization --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bca713b..f6b2b24 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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") @@ -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') @@ -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 @@ -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. @@ -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