I have a question about the style files used for osm2pgsql.

These files have a structure as follows:

# OsmType  Tag          DataType     Flags
node,way   access       text         linear
node,way   addr:housename      text  linear
node,way   addr:housenumber    text  linear
node,way   addr:interpolation  text  linear
node,way   admin_level  text         linear
node,way   aerialway    text         linear
node,way   aeroway      text         polygon
node,way   amenity      text         polygon

My question is this, how do I know if I should use polygon, linear, hstore, etc.. for the Flags values? The style file gives a brief explanation, but I am looking for further information.

3 Answers 3


The current osm2pgsql default.style explains in much more detail the meaning of the various flags and OsmTypes. If you're looking at writing your own style file, you should start with the empty.style example.

Quoting what I wrote at the time, the five flags are

  • polygon - Create a column for this tag, and objects the tag with are areas
  • linear - Create a column for this tag
  • phstore - Don't create a column for this tag, but objects with the tag are areas
  • delete - Drop this tag completely and don't create a column for it. This also prevents the tag from being added to hstore columns
  • nocache - Deprecated and does nothing

The two most important are polygon and linear. As the OSM data model does not by itself distinguish between linear features and areas, these flags determine if an object is added to the planet_osm_polygon or planet_osm_line table as a POLYGON or LINESTRING respectively.


Indeed this a challenge at OSM, as this tagging schema develops step by step. For example before there were aerial imagery available, users usually just added nodes for restaurants, as there were no building outlines available. But in present a lot of people to 'armchair mapping' and so we get more and more buildings, and you might need to consider watching for (closed) ways that are tagged as amenity=restaurant.

Usually you lookup this lists to get the right OSM tags:

At the tag pages, you usually find a box visualizing the use on nodes, ways, relation elements. But you can also browse http://taginfo.openstreetmap.org directly.
Please keep in mind that there can be different tagging schemas (usually allowing different level of details) and that there can be local differences etc. The wiki is just a suggestion, similar to the editor presets, but OSM is open that people contribute in their own way.

Then you just need to decide on your usecase, with which level of detail osm2pgsql should import this geometry to your DB http://wiki.openstreetmap.org/wiki/Osm2pgsql#Import_style

  • Very helpful, thank you, can you also dive into the Flag tag of linear vs polygon? Jan 30, 2014 at 15:21
  • I don't have experience on creating this kind of styles, so you might want to ask for more details at help.osm.org
    – Mapper
    Feb 3, 2014 at 11:03
  • 1
    +1 for http://taginfo.openstreetmap.org very useful. A Tag a la carte will be greate. We choose tags and download a style file at the end.
    – Magno C
    Jun 8, 2016 at 11:56

The most detailed information about the linear and polygon flags is now in the OSM wiki (refer to it for other flags), which states (emphasis mine) :

  • linear: Specifies that ways with this tag should be imported as lines by default, even if they are closed. Other conditions can still override this. […]
  • polygon: Specifies that closed ways with this tag should be imported as polygons by default. This will override any linear flags that would apply to the same object. Closed ways with area=yes and closed relations with type=multipolygon or type=boundary will be imported as polygons even if no polygon flag is set. Non-closed ways and closed ways with area=no will always be imported as lines.

To summarize, AFAIU the purpose of these flags is only to determine if undetermined closed ways should go in the planet_osm_line or in the planet_osm_polygon tables (assuming default table prefix). And these flags should only make sense for way OsmType.

I think the OsmType column is also worth a small word : to my understanding specifying both (node,way) for all lines should be safe, unless you want a specific treatment for one or the other (e.g. having different columns in planet_osm_point and planet_osm_line, or prevent the population of planet_osm_point by using node in combination with delete).

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.