0

I am working on a project where I save the Latitude and Longuite of a vehicle each an interval. I have also a route saved as an array of gps coordinates. So I would like to know if there is some library, that helps me to know if a point is inside the rout and other basic calculations with the coordinates as distance calculations for ex. Any tool an any language helps!

  • I think it helps to see it not as a GPS problem, but as a GIS analysis problem. What technologies are you using in your project? – elrobis Mar 09 '16 at 14:24
  • Well I collect the gps data with a rasperry pi in a txt file, then I need to analyse them in a PC (I think Windows). I want to develop a GUI to give some specific results based on the analisys I explained in the description – Wladimir Dlc R Mar 09 '16 at 14:29
  • which programming language do you prefer? – AlexWien Mar 10 '16 at 13:13

1 Answers1

1

Based on your comment, since you're not building a typical internet map, I might recommend you use a combination of Python and the Shapely library. You can see some nice examples on this post over at GIS.SE.

GIS Analyses: Geometry Types, Buffering, Intersection, etc.

In order to treat several individual Lat/Long positions as a "route", you'll need to format them as points in a LineString geometry type. Also beware: In most GIS software, points are arranged as X,Y. That means you'll be adding your points as Long,Lat. Inverting this is a common mistake that can be frustrating if you're not aware of it.

Next, in order to test whether any given point is within your route, you'll need to Buffer your route (LineString). I would use the accuracy of the GPS unit, + a few extra meters, as my buffering radius. This will give you a proper geometry (Polygon) for a Point-In-Polygon test (i.e. Intersection) that will calculate whether a given point is within the bounds of the route.

The GIS.SE post I linked to provides examples for both buffering and intersection using Python and Shapely.

Some notes about coordinates: Geodetic vs. Cartesian

I'm not confident if Shapely will perform reliable calculations on geodetic data, which is what we call the familiar coordinates you get from GPS. Before doing operations in Shapely, you may need to translate your long/lat points into projected X/Y coordinates for an appropriate coordinate system, such as UTM, etc. (Hopefully someone will comment whether this is necessary.)

Assuming this is necessary, you could add the PyProj library to give you a bridge between the GPS coordinates you have and the Cartesian coordinates you need. PyProj is the one-size-fits-all solution to this problem. However if UTM coordinates will work you might find the library cited here to be easier to implement.

If you decide to go with PyProj, it will help to know that your GPS data is described by the EPSG:4326 coordinate system. And if you are comfortable with UTM for your projected coordinates, you'll need need to determine an appropriate UTM zone for your area and get its Proj4 coordinate definition from SpatialReference.org.

For example I live in South Carolina, USA, which is UTM 17 North. So if I go to SpatialReference.org, search for "EPSG UTM zone 17N", select the option which references "WGS 1984" (I happen to know this means units in meters), then click on the Proj4 link, the site provides the coordinate system definition I'm after in Proj4 notation:

+proj=utm +zone=17 +ellps=WGS84 +datum=WGS84 +units=m +no_defs 

If you're not comfortable diving into the world of coordinate systems, EPSG codes, Proj4 strings and such, you might want to favor that alternate coordinate translation library I mentioned earlier rather than PyProj. On the other hand, if you will benefit from a more localized coordinate system (most countries have their own localized systems), or if you need to keep your code portable for use in many areas, I'd recommend using PyProj and make sure to keep your Proj4 definition string in a config file, and NOT hard-coded throughout your app!

Community
  • 1
  • 1
elrobis
  • 1,512
  • 2
  • 16
  • 22
  • It occurred to me after the fact--instead of buffering your route/linestring, it might be better to buffer the GPS position itself and test for intersection with the *unbuffered* linestring. Depending on how long or complex your routes are, there might be a modest computational advantage to buffering the GPS position and not the route. – elrobis Mar 09 '16 at 22:37
  • All the described functionallity is available for real programming languages, too, I would not use script languages for that task. – AlexWien Mar 10 '16 at 13:11
  • @AlexWien ..personally I wouldn't either. I'd use ogr2ogr to move the data into PostGRESql/PostGIS and do all my analysis there. However the OP's question suggests a lack of familiarity with the GIS niche, and Python is a singular, well-documented technology that can do 1) everything he's asking, is 2) portable, and 3) modular and easy to automate. Also, there was no technology preferences tagged or mentioned in comments, so I suggested something I considered most accessible to a beginner. But if you want to post a better recommendation, I'll certainly upvote it. – elrobis Mar 10 '16 at 16:19