Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting GPS info with Ruby

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?

like image 319
Cimm Avatar asked Jul 14 '10 22:07

Cimm


4 Answers

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.

like image 128
Matthew Rankin Avatar answered Oct 08 '22 22:10

Matthew Rankin


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

like image 41
daryn Avatar answered Oct 08 '22 23:10

daryn


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.

like image 45
Lale Avatar answered Oct 09 '22 00:10

Lale


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.

like image 1
whatnick Avatar answered Oct 08 '22 22:10

whatnick