I have a bunch of GPX files and I want to find out which files contain tracks located in certain geographic extent, e.g. files containing tracks in Pennsylvania. Also, the inverse is also useful too, e.g. any file containing tracks not in USA. How to do this using any command line tool?

Gpsbabel's polygon filter looks like what I want. But for some reason I could not make it work. The filter does not filter anything. I am not sure whether the polygon filter works with track data. This is how I run it:

gpsbabel -i gpx -f infile.gpx -x polygon,file=test_bb.txt -o gpx -F outfile.gpx

Adding exclude suboption to polygon filter does not make any different to the output as well.

  • Thanks for your question. You have written a perfect example of how to filter waypoints, which was my endeavour when filtering my favourites from OSMAnd by a specific region (polygon). The only thing I had to look for, was the polygonfile syntax, which is a list of latitudes and longitudes, one latitude and longitude separated by space per line and the last line has to be the same as the first line (closed polygon). – erik Aug 22 '18 at 5:51

I don't know much about gpsbabel, but here are a few examples with OGR: if you just need an approximation, you can use:

ogrinfo -al -so infile.gpx

Which will give you the binding box. Similarly, you can use ogr2ogr to pull out geometries which overlap a spatial extent with -spat:

ogr2ogr -spat xmin ymin xmax ymax filtered.gpx infile.gpx

If binding boxes are insufficient, you could write a Python script which used Shapely's Intersection().

  • ogrinfo is just what I need. I eventually used ogrinfo -so infile.gpx -spat xmin ymin xmax ymax | grep 'Extent'. If there are tracks in the given bounding box, the Extent value will be available. – ejel Mar 4 '11 at 3:23

According to capabilities page gpsbabel's polygon filter only supports waypoints.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.