Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to load osm data into a postgis (postgresql) database. In How to load OSM data into PostGIS preserving all Tags? there has been a solution posted:

Download the OSM files (in .osm format) and import using osm2pgsql.

When using osm2pgsql, there's a file called default.style that allows you to control 
which OSM feature goes into which postgresql table, e.g.:

way        boundary     text         polygon
node,way   railway      text         linear

means that

    features tagged "boundary" go into the *planet_osm_polygon* table
    features tagged "railway" go into the *planet_osm_point* and *planet_osm_line* 
        because the "railway" tag is common between railway stations (osm nodes) and 
        railway tracks (osm ways).

Now I wonder how to find out which features are contained in the .osm or .pbf file to configure "default.style"

Any input on how to make a good configuration file (default.style) would be appreciated. Thanks!

share|improve this question

3 Answers 3

up vote 6 down vote accepted

Magnus,

What are you intending to do with the OSM data once in a postgis table ? Depending on what you intend on doing with the data (Are you looking to do spatial analysis of highways ? Make a map of a complete city including restaurants and other POIs (points of interests) ? ), your osm2pgsql style files will be a little different.

First, osm2pgsql's style file converts features based on key of each tag (A tag provides information for each geometric element).

For example, you'll find the line in the style file: node,way highway text linear

highway is the key that is used for features including roads, highways, motorways, alleys, etc. (then the value more descriptively specifies the type of highway)

Every value that has the highway as the key will be imported into your postgis database.

The other 3 portions of the line above, don't worry about them for now, the ones that are used in the osm2pgsql style file should be fine in most uses of osm2pgsql.

However, the default osm2pgsql style file is inclusive and if you use that, you'll likely import most features in the .OSM file into your postgis database. There may be less popular tags that are used in osm (here is a list of the most used keys - there are a few on that most used keys list that are not in the default style sheet - attribution, created_by, but those keys are used to describe the source of the data, and you likely don't want to include them).

As to finding out what keys are in your .osm file, just peek around in it by opening it in josm or qgis. One way to find out what tags are used is by opening your osm file in josm, then go to search, and type:way and it will return with a column of all the keys that are used on at least one way in that file.

The disadvantage to using the default style file is that you may be including data that you don't want or need into your database; increasing the conversion time (from osm2pgsql), and possibly lengthening the time for your queries (likely only noticeable if you're doing a very large, country-wide), and increasing the size of your database as well.

I'd recommend to just include the keys that you would need.

share|improve this answer

Just to cut short the answer by Will

As to finding out what keys are in your .osm file, just peek around in it by opening it in 
josm or qgis. One way to find out what tags are used is by opening your osm file in josm, 
then go to search, and type:way and it will return with a column of all the keys that are 
used on at least one way in that file.
share|improve this answer
    
I should have mentioned: Any large OSM files, like one for an entire American state, or a country, will crash josm and qgis with this method. For these large files, you'll have to import the OSM file into a postgresql database (through osm2pgsql) (and be sure to enable hstore to obtain keys not found in the default.style file) and then use some SELECT sql queries to find out what keys are used. –  Will. Nov 29 '13 at 17:03

There are several ways:

  • http://taginfo.openstreetmap.org already provides this kind of data for the complete OSM data set
  • the tool osmfilter can be used with the parameter --out-count or --out-key to get this data from your OSM data file.
  • you can configure the .style file to just store any tag present in the data set using Postgres' hstore feature. This does not require any prior knowledge of the set of tags.
share|improve this answer

Your Answer

 
discard

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.