I noticed a pattern in .osm files : the third line tends to be its bounding box. Typically, the xml element that contains the bbox is called bounds.

I'd like to read this element without loading the whole file. Indeed, loading 80GB of data only to read one row seems pretty inefficient.

Is there a tool that lets you do this simple query ?


How about just using grep?

grep -m 1 bounds yourfile.osm

Option -m 1 tells grep to stop reading after 1 matching line. Thus it won't have to read the whole file.

Note that it doesn't always have to be the third line, that's not how XML files work. But it might still be true for most OSM XML files.

Also note that there might be multiple <bounds> elements. Especially when using JOSM to save the file after downloading different parts of the map.

  • Thanks a lot, it works for me. Sometimes the simplest solution is the best. Cheers. – VeilleData Aug 2 '16 at 12:04

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.