Which gps library would you recommend for python?

痞子三分冷 提交于 2019-12-04 07:56:06

问题


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.

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. 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. Such as comparing the last positions and calculate speed and direction.


回答1:


Apparently the python module that comes with gpsd is the best module to go with for us. For a start look here (site redirects to spam).

The gps module coming with the gpsd has some very useful functions. The first one is getting the data from gpsd and transforming those data in a usable data structure. 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.

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




回答2:


I'm not sure I understand your exact requirements, but, depending on your device &c, there seem to be many possible candidates, such as:

  • S60 GPS Info Viewer
  • pygarmin
  • pygps (mirror)

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; this SO question might also help if that's what you're doing.




回答3:


The book "Beginning Python Visualization" includes just such an example - parsing GPS data and inferring speed and location from it. Its source code is available online at http://www.apress.com/




回答4:


The GPS sentences that you receive from a GPS device are pretty easy to decode, and this looks like a fun project. 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):

$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. 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:

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). 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".

Also, lat1, lat2, long1 and long2 have to be expressed in radians. 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)).

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. 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 :)




回答5:


Most good GPS units (we use Oncore M12M) will actually give you, as output, your velocity and heading. 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. 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. Some details here: 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.

(Sorry if unhelpful, first time poster, still learning how to stack overflow)



来源:https://stackoverflow.com/questions/953701/which-gps-library-would-you-recommend-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!