Plotting GPS info with Ruby
Asked Answered
L

6

5

I'm looking for ways to programmatically convert my GPS logs to images and would like to do this in Ruby... if that's an acceptable tool. I have no GIS background whatsoever but as a programmer i think it's an interesting problem to look at.

Here is what I have come up with so far. First you'll need some kind of graphing library. I went for gnuplot as I found a Ruby binding for that one but R seems hot these days. I created a small script that converts a GPX file and feeds the data to gnuplot resulting in something like this: alt text http://dl.dropbox.com/u/45672/gpslog.png

This looks fine but gnuplot seems really a tool to create graphs, not spatial data. Is this the way to do it or are there much better solutions available?

Here is another example, any idea how you build stuff like this?

Longways answered 14/7, 2010 at 22:29 Comment(2)
What do the GPS logs look like? Do you have lat/lon info?Miranda
I'm using GPX files so yes they have lat/lon info. I suppose you can convert a file to one format or another before plotting.Longways
S
4

Answer to First Question

Since you stated that you "would like to do this in Ruby...if that's an acceptable tool", I'll go out on a limb and assume that you might be open to a non-Ruby solution if it meets all of your other requirements.

I would recommend Python primarily because in the first chapter of Beginning Python Visualization, Shai Vaingast—the author—goes through an example of reading in GPS data from a GPS receiver and then plots the results. If you're open to a Python-based solution, this book would be a great resource.

Here are the Python packages that are used to read and plot the GPS data:

  • pySerial to read the GPS data in from the serial port
  • matplotlib to plot the data. "matplotlib is a library for making 2D plots of arrays in Python. Although it has its origins in emulating the MATLAB® graphics commands, it is independent of MATLAB, and can be used in a Pythonic, object oriented way."

Here's an example figure created by Shai Vaingast showing off a few of the different capabilities of matplotlib for plotting GPS data.

alt text

If you are not open to a Python solution, and would prefer Ruby—for whatever reason—I understand. I tried to search for an equivalent of matplotlib in Ruby, but I didn't find an equivalent package.

Answer to Last Question

Here is another example, any idea how you build stuff like this?

Looking at the lower, right-hand corner, it appears that DISLIN was used to create that image. While DISLIN is available for quite a few programming languages, the DISLIN software requirements page does not show that Ruby is supported.

alt text

According to the DISLIN website,

DISLIN is a high-level plotting library for displaying data as curves, polar plots, bar graphs, pie charts, 3D-color plots, surfaces, contours and maps.

The software is available for several C, Fortran 77 and Fortran 90/95 compilers on the operating systems UNIX, Linux, FreeBSD, OpenVMS, Windows, Mac OSX and MS-DOS. DISLIN programs are very system-independent, they can be ported from one operating system to another without any changes.

For some operating systems, the programming languages Perl, Python, Java and the C/C++ interpreter Ch are also supported by DISLIN. The DISLIN interpreter DISGCL is availble for all supported operating systems. See a complete list of the supported operating systems and compilers.

Streamlet answered 10/9, 2010 at 1:12 Comment(0)
U
1

Do you really want images, or just a way to visualize the data? How about using the google maps api?

Check out this link:

http://google-dox.net/O.Reilly-Google.Maps.Hacks/0596101619/googlemapshks-CHP-4-SECT-10.html

Unblinking answered 14/7, 2010 at 23:5 Comment(1)
Thanks daryn but yes, I do want images. I don't like to use Google Maps as I don't like the restrictions (e.g. you can't remove the logo or copyright info) and I want to learn to plot these things myself, that's the goal.Longways
S
1

I think that using gnuplot from any programming language is a good starting approach.

However, I strongly suggest adding the set size ratio -1 gnuplot command somewhere in your code, as this will make the x and y axis scales equal in the plot, which is extremely important.

You could also augment the line with very small point markers equally spaced in time (assuming you have time information in your data, or at least you know that rows are sampled at regular time intervals), so you get a feel of the speed of the movement, which is otherwise lost (i.e., large-spaced point markers on the line mean faster movement). Obviously you should pick a time interval between point markers that makes them appropriately spaced, or compute such time interval automatically: i.e. by computing the length of your curve, converting it in pixel units, and dividing by anything between 10 and 100, to get the total number of points you want to place. The time interval is then given by the total time of the track divided by such number of points. This should work robustly for reasonably regular movements.

Another option is to use a different charting system than gnuplot, which is powerful but a bit old. Options known to me include:

  • gruff, which is for ruby but seems to miss 2D plotting abilities (which is an obvious requirement).
  • XML/SWF Charts, which is powerful and flexible, but commercial. In this case, you would use ruby or any other programming language to generate an XML file which then gets interpreted to an interactive graph.
  • Google Chart API, which can return chart images over the web, forging an appropriate GET or POST request in your code. In this case, you are intersted in the lxy chart type, possibly compounded with a scatter chart for the point markers.

The third option seems the most fun.

Submission answered 9/9, 2010 at 9:24 Comment(2)
Thanks, this is the most complete answer so far. The first and second options are a no-go for me (for the reasons you listed) so that leaves Google Chart. Sadly enough Google Chart still doesn't give me the flexibility I'm looking for. These things can't by done by Google Charts for example: lvzc.be/charronline/igc/2010/1095ljd71.pngLongways
You are right, I assumed that making a compound chart including a map and an xyline was possible using google charts but apparently it is not. What a pity! However, i'm pretty sure it could be done using some sort of bitmap background, or using a different line for representing the map itself. I see that DISLIN, mentioned in another comment, is an interesting option I was unaware of. I would also add the Matlab Mapping Toolbox, which is probably one of the most powerful and flexible options for this tasks, but is commercial and probably very expensive.Submission
K
1

Maybe you have heard of Processing already but have you heard of Ruby-Processing ?

From the Ruby-Processing readme:

Ruby-Processing is a Ruby wrapper for the Processing code art framework.

If some quality time with Ruby is your idea of a pleasant afternoon, or you
harbor ambitions of entering the fast-paced and not altogether cutthroat world of Code Art, then Ruby-Processing is probably something you should try on for size.

Processing is an MIT-developed framework for making little code artifacts, animations, visualizations, and the like, developed originally by Ben Fry and Casey Reas, supported by a small army of open-source contributors.
Processing has become a sort of standard for visually-oriented programming, strongly influencing the designs of Nodebox, Shoes, Arduino, and other kindred projects

Kerin answered 9/9, 2010 at 23:19 Comment(0)
S
1

GDAL is very popular Open Source GIS kit, there are GDAL Ruby bindings. If you want map data, open street map is very useful. Combined plotting of OSM and the GPS will give pretty nice results. GDAL/OGR Api tutorial is here.

Snuffbox answered 10/9, 2010 at 12:13 Comment(0)
G
0

If you want to look more into R, there are Ruby bindings for that too, but there has been no activity on the project for over a year:

http://github.com/alexgutteridge/rsruby

Gripper answered 5/9, 2010 at 16:7 Comment(1)
Thanks Michael, I'll have a look at R. Any tutorials for a GIS n00b somewhere?Longways

© 2022 - 2024 — McMap. All rights reserved.