简体   繁体   English

您会为python推荐哪个gps库?

[英]Which gps library would you recommend for python?

I'm looking for a free library for python that can calculate your direction and your speed from GPS coordinates and maybe can calculate if you are in some boundaries or things like this.我正在寻找一个免费的 python 库,它可以根据 GPS 坐标计算你的方向和速度,也许可以计算你是否处于某些边界或类似的东西。

Are there Libraries that you know and that worked well for you?是否有您知道并且对您很有效的库?

Edit: Ok it seems I have to specify this a little bit.编辑:好的,看来我必须稍微说明一下。 We are using python on a linux machine and getting the data from the gpsd.我们在 linux 机器上使用 python 并从 gpsd 获取数据。 So I hope there is no need for a speciel library for only talking to the device.所以我希望不需要专门的库来只与设备交谈。 What I'm looking for is python code doing some basic calculations with the data.我正在寻找的是 python 代码对数据进行一些基本计算。 Such as comparing the last positions and calculate speed and direction.例如比较最后的位置并计算速度和方向。

Apparently the python module that comes with gpsd is the best module to go with for us.显然,gpsd 附带的 python 模块是我们最好的模块。 For a start look开始看here这里(site redirects to spam). (网站重定向到垃圾邮件)。

The gps module coming with the gpsd has some very useful functions. gpsd 附带的 gps 模块有一些非常有用的功能。 The first one is getting the data from gpsd and transforming those data in a usable data structure.第一个是从 gpsd 获取数据并将这些数据转换为可用的数据结构。 Then the moduls give you access to your speed, and your current heading relative to north.然后模块让您可以访问您的速度,以及您当前相对于北方的航向。 Also included is a function for calculating the distance between two coordinates on the earth taking the spherical nature of earth into account.还包括一个函数,用于计算地球上两个坐标之间的距离,同时考虑到地球的球形特性。

The functions that are missing for our special case are:我们的特殊情况缺少的功能是:

  • Calculating the heading between to points.计算点之间的航向。 Means I am at point a facing north to which degree do I have to turn to face the point I want to navigate to.意味着我在点 a 朝北,我必须转向哪个角度才能面对我想要导航到的点。

  • Taking the data of the first function and our current heading to calculate a turn in degrees that we have to do to face a desired point (not a big deal because it is mostly only a subtraction)使用第一个函数的数据和我们当前的航向来计算我们面对所需点必须做的转角(没什么大不了的,因为它主要只是减法)

The biggest problem for working with this library is that it is mostly a wrapper for the gpsd so if you are programming on a different OS then you gpscode should work on like Windows or MacOS you are not able to run the code or to install the module.使用这个库的最大问题是它主要是 gpsd 的包装器,所以如果你在不同的操作系统上编程,那么你的 gpscode 应该像 Windows 或 MacOS 一样工作,你无法运行代码或安装模块.

I'm not sure I understand your exact requirements, but, depending on your device &c, there seem to be many possible candidates, such as:我不确定我是否了解您的确切要求,但是,根据您的设备和 c,似乎有很多可能的候选者,例如:

If what you mean is that you've already obtained the GPS' unit output and just need to parse it &c, I suspect that one or more of the above examples (which unfortunately I have not tried) will contain well-isolated modules for that task, which, depending on licensing conditions, you could repurpose;如果你的意思是你已经获得了 GPS 的单元输出并且只需要解析它 &c,我怀疑上面的一个或多个示例(不幸的是我没有尝试过)将包含隔离良好的模块任务,根据许可条件,您可以重新调整用途; this SO question might also help if that's what you're doing.如果这就是你正在做的, 这个问题也可能会有所帮助。

The book "Beginning Python Visualization" includes just such an example - parsing GPS data and inferring speed and location from it. “Beginning Python Visualization”一书就包含了这样一个例子——解析 GPS 数据并从中推断速度和位置。 Its source code is available online at http://www.apress.com/其源代码可在http://www.apress.com/在线获得

The GPS sentences that you receive from a GPS device are pretty easy to decode, and this looks like a fun project.您从 GPS 设备接收到的 GPS 语句非常容易解码,这看起来是一个有趣的项目。 I'm not sure what you get from gspd, but if it's these sentences, I actually had to do something like this for school a few weeks ago (but in LabView):我不确定你从 gspd 得到了什么,但如果是这些句子,我实际上不得不在几周前为学校做这样的事情(但在 LabView 中):

$GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx

hhmmss.ss = UTC of position 
llll.ll = latitude of position
a = N or S
yyyyy.yy = Longitude of position
a = E or W 
x = GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix) 
xx = number of satellites in use 
x.x = horizontal dilution of precision 
x.x = Antenna altitude above mean-sea-level
M = units of antenna altitude, meters 
x.x = Geoidal separation
M = units of geoidal separation, meters 
x.x = Age of Differential GPS data (seconds) 
xxxx = Differential reference station ID 

So you could just do a gpsstring.split(',') and you'll get an array of all elements which you can then parse.所以你可以只做一个 gpsstring.split(',') ,你会得到一个所有元素的数组,然后你可以解析这些元素。 To see more about these sentences (there are others I think for speed and direction), click here .要查看有关这些句子的更多信息(我认为还有其他关于速度和方向的句子),请单击此处

For example, to get the approximate distance between two points you can use the Haversine Formula :例如,要获得两点之间的近似距离,您可以使用Haversine 公式

distance=R*2*asin(sqrt((sin((lat1-lat2)/2))**2
               +cos(lat1)*cos(lat2)*(sin((long1-long2)/2))**2))

Where R is the radius of the Earth in the unit of measurement you want to get your result in (for example R=6372km).其中 R 是地球的半径,采用您想要得到的测量单位(例如 R=6372km)。 That actual line is taken from the LabView program I had lying around, but the syntax is pretty similar to Python's (maybe check the division operator, you might want to do "from future import division".该实际行取自我闲逛的 LabView 程序,但语法与 Python 非常相似(也许检查除法运算符,您可能想要执行“从未来导入除法”。

Also, lat1, lat2, long1 and long2 have to be expressed in radians.此外,lat1、lat2、long1 和 long2 必须以弧度表示。 The format you're getting them in is pretty strange (hhmm.ff, where ff are fractions of minutes, so they go from 0 to 99 instead of 0 to 59 (as seconds)).您获取它们的格式非常奇怪(hhmm.ff,其中 ff 是分钟的分数,因此它们从 0 到 99 而不是 0 到 59(以秒为单位))。

The code I used for that is:我为此使用的代码是:

h=floor(x/100);
m=floor(x-(h*100));
s=(x-floor(x))*60;
deg=sgn*(h+(m/60)+(s/3600));
rad=deg*pi/180;

Where sign is 1 for North and East, and -1 for South and East.其中,北和东的符号为 1,南和东的符号为 -1。 Again, watch out for division.再次,注意分裂。

Checking boundaries is I think the easiest part.检查边界是我认为最简单的部分。 If you've already got the positions in radians or degrees, you can just check if latitude is between two lat boundaries, and do the same for longitude.如果您已经获得了弧度或度数的位置,则可以检查纬度是否在两个纬度边界之间,并对经度执行相同操作。

Write a wrapper around everything, and you've got your GPS library :)为所有内容编写一个包装器,您就拥有了 GPS 库:)

Most good GPS units (we use Oncore M12M) will actually give you, as output, your velocity and heading.大多数优秀的 GPS 装置(我们使用 Oncore M12M)实际上会为您提供速度和航向作为输出。 I would first check your GPS receiver's documentation to see if this information is already being sent, or if such a message can be enabled.我会首先检查您的 GPS 接收器的文档,看看是否已经发送了此信息,或者是否可以启用此类消息。 In my experience, this data is usually part of the standard telemetry a receiver will give you.根据我的经验,这些数据通常是接收器将为您提供的标准遥测数据的一部分。

If that doesn't work, I think your best bet is using the details of WGS-84 (the GPS coordinate system) to obtain an actual (x,y,z) coordinate and then difference it with the next one to find your heading and take the magnitude of the difference over the time interval to find your velocity.如果这不起作用,我认为最好的办法是使用 WGS-84(GPS 坐标系)的详细信息来获取实际的 (x,y,z) 坐标,然后将其与下一个坐标进行区分以找到您的航向并在时间间隔内计算差异的大小以找到您的速度。 Some details here: http://topex.ucsd.edu/geodynamics/14gravity1_2.pdf这里有一些细节: http : //topex.ucsd.edu/geodynamics/14gravity1_2.pdf

If you really want a package that does all this, I think pyEphem is pretty good, although I think you might save a little time searching and gain some good knowledge by writing it yourself.如果你真的想要一个可以完成所有这些的包,我认为 pyEphem 非常好,尽管我认为你可以通过自己编写它来节省一些搜索时间并获得一些好的知识。

(Sorry if unhelpful, first time poster, still learning how to stack overflow) (对不起,如果没有帮助,第一次发帖,仍在学习如何堆栈溢出)

我发现gpsd-py3 库对您描述的任务非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM