Mileage traveled by district/state

Tyler Strain2 years ago

We are wanting to use Traccar to generate reports with milage traveled in geographical areas (US states) during a given time period. Specifically this is for quarterly IFTA filings. I looked around the demo server for the US and could not find anything stuck out. Has this been done before with Traccar or can anyone recommend another way to post process the data?

Anton Tananaev2 years ago

You can use API to extract the relevant data. Get geofence enter/exit events first. And then get positions for those events. Positions will include odometer or distance values.

Tony Shelver2 years ago

Anton's approach would likely require setting up geofences for each area / state you are interested in, and connecting the vehicles to all those districts. If you can do that, then likely it would be an easier approach. Not sure how accurate the distance per area would be where routes cross back and forth between areas.
Also, we have sometimes noticed that geofence events go missing or are slightly inaccurate (two different tracking systems, including Traccar).

We have a more complex way of doing something similar. Our Traccar data is mirrored in a custom Postgresql database with PostGIS (geographical / geometry extension), so that is an additional requirement and overhead.
We have an 'Area Stop Report' where the area is a polygonal shape in the DB. We can then run all stop positions and times against those shapes using a 'within' PostGIS function to break them out by area. But loading the DB is the complicating factor.

I'd think what you want to do is much more complex. You would need to extract the route to a polyline, and then get the length of the polyline within each polygon. Do a google on this, there should be several PostGIS examples on similar approaches.

Maybe there is a java geometry library that can do something similar? The advantage of PostGIS is that the functions are written in C and indexes can be applied to positions, shapes and lines to speed processing,
Also note if using PostGIS that geometry datatypes are processed faster than geography datatypes, but are slightly less accurate especially at higher latitudes.

Tony Shelver2 years ago

Additional thought: if you are using Postgresql already, maybe you could add PostGIS extension to the Traccar DB, and then import your state / district geoshapes directly into a custom table in that DB? Then you could use the PostGIS functions from java, after extracting your routes from the Traccar API.