Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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

share|improve this answer
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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