使用 Ruby 绘制 GPS 信息

发布于 2024-09-09 17:03:06 字数 758 浏览 2 评论 0 原文

我正在寻找以编程方式将 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

久而酒知 2024-09-16 17:03:06

第一个问题的回答

既然你说你“想用 Ruby 来做这件事......如果这是一个可以接受的工具”,我会冒险假设你可能愿意一个非 Ruby 解决方案(如果它满足您的所有其他要求)。

我会推荐 Python 主要是因为在 开始 Python 可视化,作者 Shai Vaingast 介绍了从 GPS 接收器读取 GPS 数据的示例然后绘制结果。如果您愿意接受基于 Python 的解决方案,这本书将是一个很好的资源。

以下是用于读取和绘制 GPS 数据的 Python 包:

  • pySerial 读取 GPS 数据从串行端口
  • matplotlib 绘制数据。 “matplotlib 是一个用 Python 绘制二维数组图的库。尽管它起源于模拟 MATLAB ® 图形命令,它独立于 MATLAB,并且可以以 Pythonic、面向对象的方式使用。”

下面是 Shai Vaingast 创建的示例图,展示了 matplotlib 用于绘制 GPS 数据的一些不同功能。

alt text

如果您不接受 Python 解决方案,并且出于某种原因更喜欢 Ruby,我理解。我尝试在 Ruby 中搜索 matplotlib 的等效包,但没有找到等效的包。

回答最后一个问题

这是另一个示例,知道如何构建东西像这样吗?

查看右下角,似乎是使用 DISLIN 创建的图像。虽然 DISLIN 可用于多种编程语言,但DISLIN 软件要求页面没有显示支持 Ruby。

alt text

根据DISLIN 网站,

DISLIN 是一个高级绘图库,用于将数据显示为曲线、极坐标图、条形图、饼图、3D 彩色图、曲面、等值线和地图。

该软件可用于 UNIX、Linux、FreeBSD、OpenVMS、Windows、Mac OSX 和 MS-DOS 操作系统上的多种 C、Fortran 77 和 Fortran 90/95 编译器。 DISLIN 程序非常独立于系统,它们可以从一个操作系统移植到另一个操作系统而无需任何更改。

对于某些操作系统,DISLIN 还支持编程语言 Perl、Python、Java 和 C/C++ 解释器 Ch。 DISLIN 解释器 DISGCL 适用于所有支持的操作系统。查看支持的操作系统和编译器的完整列表。

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.

月亮坠入山谷 2024-09-16 17:03:06

您真的想要图像,还是只是一种可视化数据的方法?使用谷歌地图 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

另类 2024-09-16 17:03:06

我认为使用任何编程语言的 gnuplot 都是一个很好的起始方法。

不过,我强烈建议在代码中的某处添加 set size Ratio -1 gnuplot 命令,因为这将使绘图中的 x 轴和 y 轴比例相等,这一点非常重要。

您还可以使用时间上等距的非常小的点标记来增强该线(假设您的数据中有时间信息,或者至少您知道以规则的时间间隔对行进行采样),这样您就可以感受到行的速度运动,否则就会丢失(即,线上的大间距点标记意味着更快的运动)。显然,您应该选择点标记之间的时间间隔,使它们适当间隔,或者自动计算这样的时间间隔:即通过计算曲线的长度,将其转换为像素单位,然后除以 10 到 100 之间的任何值,以获得您要放置的总点数。然后,时间间隔由轨道的总时间除以这​​些点数得出。这对于相当规律的运动应该是有效的。

另一种选择是使用与 gnuplot 不同的图表系统,它功能强大但有点旧。我知道的选项包括:

  • gruff,它适用于 ruby​​,但似乎缺少 2D 绘图功能(这是一个明显的要求)。
  • XML/SWF Charts,功能强大且灵活,但商业化。在这种情况下,您将使用 ruby​​ 或任何其他编程语言生成 XML 文件,然后将其解释为交互式图表。
  • Google Chart API,它可以通过网络返回图表图像,从而形成适当的图表代码中的 GET 或 POST 请求。在本例中,您对 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:

  • 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.

何以笙箫默 2024-09-16 17:03:06

也许您已经听说过处理,但您听说过Ruby 处理 ?

来自Ruby-Processing自述文件:

Ruby-Processing 是处理代码艺术框架的 Ruby 包装器。

如果您愿意与 Ruby 共度美好时光
一个愉快的下午的想法,或者你
怀揣着进入的野心
快节奏但不完全
那么,Code Art 的残酷世界
Ruby-Processing 可能是这样的
您应该试穿尺寸。

处理是麻省理工学院开发的
编写少量代码的框架
文物、动画、
可视化等,
最初由 Ben Fry 和
凯西·雷斯 (Casey Reas),由一支小规模军队支持
开源贡献者。
加工已成为一种
视觉导向标准
编程,强烈影响
Nodebox、Shoes 的设计,
Arduino 和其他类似项目

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

長街聽風 2024-09-16 17:03:06

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.

通知家属抬走 2024-09-16 17:03:06

如果您想更多地了解 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文