我正在寻找以编程方式将 GPS 日志转换为图像的方法,并希望在 Ruby 中执行此操作...如果这是一个可接受的工具的话。我没有任何 GIS 背景,但作为一名程序员,我认为这是一个值得关注的有趣问题。
这是我到目前为止所想到的。首先,您需要某种图形库。我选择了 gnuplot 因为我发现了 Ruby 绑定 ,但 R 似乎这几天很热。我创建了一个小脚本,用于转换 GPX 文件并将数据提供给 gnuplot,结果如下: alt text http://dl.dropbox.com/u/45672/gpslog.png
这看起来不错,但 gnuplot 似乎确实是一个创建图形的工具,而不是空间数据。这是这样做的方法还是有更好的解决方案可用?
这是另一个 示例,知道如何构建这样的东西吗?
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?
发布评论
评论(6)
第一个问题的回答
既然你说你“想用 Ruby 来做这件事......如果这是一个可以接受的工具”,我会冒险假设你可能愿意一个非 Ruby 解决方案(如果它满足您的所有其他要求)。
我会推荐 Python 主要是因为在 开始 Python 可视化,作者 Shai Vaingast 介绍了从 GPS 接收器读取 GPS 数据的示例然后绘制结果。如果您愿意接受基于 Python 的解决方案,这本书将是一个很好的资源。
以下是用于读取和绘制 GPS 数据的 Python 包:
下面是 Shai Vaingast 创建的示例图,展示了 matplotlib 用于绘制 GPS 数据的一些不同功能。
如果您不接受 Python 解决方案,并且出于某种原因更喜欢 Ruby,我理解。我尝试在 Ruby 中搜索 matplotlib 的等效包,但没有找到等效的包。
回答最后一个问题
查看右下角,似乎是使用 DISLIN 创建的图像。虽然 DISLIN 可用于多种编程语言,但DISLIN 软件要求页面没有显示支持 Ruby。
根据DISLIN 网站,
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:
Here's an example figure created by Shai Vaingast showing off a few of the different capabilities of matplotlib for plotting GPS data.
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
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.
According to the DISLIN website,
您真的想要图像,还是只是一种可视化数据的方法?使用谷歌地图 API 怎么样?
查看此链接:
http://google-dox.net/O.Reilly-Google.Maps.Hacks/0596101619/googlemapshks-CHP-4-SECT-10.html
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
我认为使用任何编程语言的 gnuplot 都是一个很好的起始方法。
不过,我强烈建议在代码中的某处添加
set size Ratio -1
gnuplot 命令,因为这将使绘图中的 x 轴和 y 轴比例相等,这一点非常重要。您还可以使用时间上等距的非常小的点标记来增强该线(假设您的数据中有时间信息,或者至少您知道以规则的时间间隔对行进行采样),这样您就可以感受到行的速度运动,否则就会丢失(即,线上的大间距点标记意味着更快的运动)。显然,您应该选择点标记之间的时间间隔,使它们适当间隔,或者自动计算这样的时间间隔:即通过计算曲线的长度,将其转换为像素单位,然后除以 10 到 100 之间的任何值,以获得您要放置的总点数。然后,时间间隔由轨道的总时间除以这些点数得出。这对于相当规律的运动应该是有效的。
另一种选择是使用与 gnuplot 不同的图表系统,它功能强大但有点旧。我知道的选项包括:
lxy
图表类型感兴趣,可能与 点标记的散点图。第三个选项似乎最有趣。
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:
lxy
chart type, possibly compounded with a scatter chart for the point markers.The third option seems the most fun.
也许您已经听说过处理,但您听说过Ruby 处理 ?
Maybe you have heard of Processing already but have you heard of Ruby-Processing ?
GDAL是非常流行的开源GIS工具包,有GDALRuby 绑定。如果您想要地图数据,开放街道地图非常有用。 OSM 和 GPS 的组合绘图将给出非常好的结果。 GDAL/OGR Api 教程在这里。
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.
如果您想更多地了解 R,也有 Ruby 绑定,但该项目已经一年多没有活动了:
http://github.com/alexgutteridge/rsruby
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