What I have done so far is creating a PostGIS database with the OSM world data which was successful and viewable via QGIS.

I imported the data via osm2pgsql -U USER -W -d gis -H --number-processes 24 -C 2048 osm_world.pbf --hstore

Even after extensive research I could not figure out a way to achieve to get what I said in the title.

Is some postprocessing of the OSM data necessary?

  • 4
    Depending on the tool used to import the planet.osm file (please add that info to your question body) you'll have (a subset of) tags stored as key/value pairs, individual columns, or a combination of both. Get familiar with the OSM tag logic (e.g. building), then the essentials of using ST_DWithin and the usage of CRS units (GIS.SE is a good place for that).
    – geozelot
    Jul 14, 2021 at 8:47
  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works
    – Ian Turton
    Jul 14, 2021 at 8:55

1 Answer 1


If you want to use only the building in a radius of a point location then the best will be to first filter osm data and then store it in a postgresql database.

Filter osm pbf file based on location

To process osm pbf data, there are different tools available. For your goal, I think the best will be to use osmconvert. Here is the documentation link. You can not set a point and radius but can get the same either setting a bounding box with -b argument or a polygon stored in a poly file with -B argument.

osmconvert.exe germany.pbf --max-objects=1000000000 --hash-memory=1000 --max-refs=4000000  -b=10.5,49,11.5,50 -o=nuernberg.osm -v=2 

The line of code based on the example from the documentation and adapted to work with large files in Windows environment(max object max refs or hash memory parameters have to be set).

Filter to keep only buildings

Then you have to keep only the buildings, you can use osmfilter and keep every OSM object that have at least a building key. In the documentation there are many options you can use to drop or keep OSM objects.

osmfilter.exe nuernberg.osm --keep="building=" -o=building.osm --verbose

Store the OSM data in postgresql

I think your code used before will work and will be processed faster :

osm2pgsql -U USER -W -d gis -H --number-processes 24 -C 2048 building.osm --hstore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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