Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set polygon/linestring differently for some key values differently than the key in default style.lua #346

Conversation

matthijsmelissen
Copy link
Contributor

This allows the decision whether an object is treated as polygon or linestring
to be set in the style.lua file.

In particular, it treats the following values as linestring:
man_made=embankment, man_made=breakwater, man_made=groyne, natural=cliff, natural=tree_row, historic=citywalls, waterway=derelict_canal, waterway=ditch, waterway=drain, waterway=river, waterway=stream, waterway=wadi, waterway=weir, power=line, power=minor_line. It also treats highway=services as polygon.

Including this in the default style.lua file has the following advantages:

  • It serves as an easy-to-extend example of how the polygon/linestring decision
    can be made based on key.
  • It provides sane defaults - it can be expected that most users of the style
    want to treat man_made=embankment and natural=cliff as linestring, and
    highway=services as polygon.

This resolves the following downstream bugs in openstreetmap-carto:

This builds on #345, and thus assumes #345 is merged first.

@kreed
Copy link

kreed commented Apr 28, 2015

power=line as linestring would be nice too. Usually power lines aren't closed loop so it isn't an issue but sometimes it comes up with busbars inside substations.

@matthijsmelissen
Copy link
Contributor Author

Yes, good suggestion.

@matthijsmelissen
Copy link
Contributor Author

I added power=line now, as well as some other key/value combinations.

@pnorman
Copy link
Collaborator

pnorman commented Apr 30, 2015

changes to filter_tags_relation_member should also be mirrored in multi.lua, as they are basically the same function.

@mboeringa
Copy link

@math1985 , you do take into account possible secondary building NOT IN (NULL,'no') tags? Historic citywalls are sometimes mapped as buildings with individual parts as closed loops / ways. So they may have both a historic = citywalls and building = yes/x tag.

Anything tagged with a building tag should be excluded from this evaluation I think and default to polygon.

I am also not sure about defaulting closed ways of man_made = breakwater and man_made = groyne as linestrings. I agree these are "linear" features by nature protruding from the coast or riverbank, _but if mapped as a closed way_, they almost certainly represent a micro-mapped polygon representation of the feature, so should likely be polygons.

@pnorman pnorman changed the title Allow polygon/linestring decision to be set by value in lua Set polygon/linestring differently for some key values differently than the key in default style.lua May 1, 2015
@pnorman
Copy link
Collaborator

pnorman commented May 1, 2015

Renamed the issue - the polygon/linestring decision has always been allowed be set by value in Lua.

@matthijsmelissen
Copy link
Contributor Author

changes to filter_tags_relation_member should also be mirrored in multi.lua, as they are basically the same function.

I don't really see how that works - there is not even an polygon_keys in multil.lua? What should exactly be changed?

@matthijsmelissen
Copy link
Contributor Author

  1. Rebased and solved a bug.

  2. AppVeyor seems to fail, but I only touched the Lua files. What could be the cause of the build fail?

  3. @pnorman In response to the following:

    changes to filter_tags_relation_member should also be mirrored in multi.lua, as they are basically the same function.

It's not yet totally clear to me how this works. Both style.lua and multi.lua add tags from the outer polygons to the multipolygons under some circumstances. However, these circumstances are quite different. The file style.lua adds the tags from the outer polygons to the multipolygon if the multipolygon has zero polygon tags. However, multi.lua adds the tags from the outer polygons to the multipolygon if the multipolyon is not a building. That's quite a different condition! The only change I made to filter_tags_relation_member is the way the number of polygon tags is counted, and as we don't count polygon tags in multi.lua, it does not seem like we need a similar change in multi.lua at the moment.

@matthijsmelissen
Copy link
Contributor Author

@mboeringa Good point about historic=citywalls.

So basically the problem is that a closed linestring tagged with historic=citywalls can mean two things. Either it is a circular wall, or a wall of which the outline is tagged. Unfortunately, both of them are used commonly in practice. The question is now what we should assume as default.

Unfortunately the presence of a building tag is not sufficient to tell the two apart. For example Templin has a citywall mapped as area, but no building tag. And conversely, I could also imagine that an area tagged with both a building and citywall tag might signify a building with a city wall around it (like a fortress).

To repeat the question: a citywall as an open linestring will in any case be interpreted as line. What should we do with citywalls as closed linestring?
A. Treat as line, unless tagged area=yes.
B. Treat as area, unless tagged area=no.

I think personally I'd prefer option A. It seems counterintuitive to me that closing a linestring would suddenly change the semantics. Also, I don't think we currently have any tags that can refer both to a line or area that do not need an area=yes tag when used as area, except the tags in this PR.

What do others think?

For breakwater and groyne, the situation is similar, except that closed linestrings for these objects in almost all cases do refer to an area. How should we treat these objects?

@sommerluk
Copy link

@math1985 Could you also add junction=yes as polygon? (Downstream gravitystorm/openstreetmap-carto#1253 )

@lonvia
Copy link
Collaborator

lonvia commented Feb 22, 2016

A general remark: You do say that the PR is intended as an example implementation but at the same time I see a tagging discussion unfold here with plenty of references to the carto style. That tells me this might be the wrong repository for that change. Shouldn't you better start maintaining your own lua style file like you already do for the C style file? I'm just afraid that the more fine details of tagging are lost on the osm2pgsql maintainers as evident from the fact that this PR hasn't been merged in almost a year.

@matthijsmelissen
Copy link
Contributor Author

I have thought a bit more about this, and I came to the following conclusions:

  • An object with both a polygon-key and a line-key are currently treated as polygon. Therefore, the logical thing to do is to treat an object with both a polygon-key and a line-tag (e.g. building=yes and historic=citywalls) also as polygon. I have changed the code to handle this correctly. Thanks again @mboeringa.
  • Current practice is that objects that can be interpreted as a line, such as highways, are interpreted as lines even when they form a closed linestring. To treat them as an area, the tag area=yes is needed. I'd like to follow that practice, so with this PR, tags like historic=citywalls or waterway=weir will be interpreted as line even for a closed linestring. This can be overruled by adding either area=yes or an area tag, such as building=yes. No change is needed to the PR.

@matthijsmelissen
Copy link
Contributor Author

@math1985 Could you also add junction=yes as polygon? (Downstream gravitystorm/openstreetmap-carto#1253 )

Added.

@matthijsmelissen
Copy link
Contributor Author

This is now ready to be merged. I can still squash the commits if you like.

A general remark: You do say that the PR is intended as an example implementation but at the same time I see a tagging discussion unfold here with plenty of references to the carto style. That tells me this might be the wrong repository for that change.

I understand your point, but I'm not sure if I agree. I think it would be good if osm2pgsql provides sane defaults. The decision whether to treat a certain tag, like natural=tree_row, as polygon or line is a data representation decision, not a rendering decision. I would therefore expect this to be solved within osm2pgsql. For this decision, it doesn't matter whether a user wants to use a PostGIS-database for openstreetmap-carto, an other style sheet, or perhaps not for rendering purposes at all. I'd expect all applications would require the same defaults for the line/area decision. I'd consider the current default behaviour, where a closed natural=tree_row is treated as a polygon, as a default that's not sane..

However, if the osm2pgsql maintainers feel this repository is not the right place for this PR, I would understand. Maintaining an openstreetmap-carto specific .lua-file would work for us too, and might be a good idea anyway, independent on whether this PR is or is not merged.

@@ -0,0 +1 @@
timestamp for config.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems accidentally committed, it is an artifact from autoconf times.

@lonvia
Copy link
Collaborator

lonvia commented Feb 23, 2016

Well, I see the argument that style.lua should do something sane. I'm saying that I'm not able to judge, if this PR counts as bug fixing or as a carto-osm-specific change. I've had a look at the code-part now and added a few comments but I would leave the final decision to @pnorman, if this makes sense to have this change in osm2pgsql or not.

From a practical point of view, you'd want your own lua style anyway because otherwise carto devs are forced to compile their own osm2pgsql all the time just to stay in sync with the style file.

@matthijsmelissen
Copy link
Contributor Author

@lonvia Thanks for your feedback, I think I addressed all issues now.

@matthijsmelissen
Copy link
Contributor Author

@pnorman Would you be able to review this PR? Let me know if you need anything else.

@lonvia
Copy link
Collaborator

lonvia commented Mar 3, 2016

We had a lengthy discussion about the lua style file at the last hackweek end. The general conclusion was that the lua style in its current state is not really ready to be used. The code is unnecessarily complicated and often terribly inefficient. So we are now seriously considering the idea of rewriting it from scratch. I'm afraid this will leave this PR (and possibly also #532) a bit in the hanging until there is decision on that matter.

I've also noticed that the code is still not quite right. I'll add a comment about that.

@lonvia
Copy link
Collaborator

lonvia commented Mar 3, 2016

Ignore the last part of my comment. The code is probably okay. But that reminds me of the second observation we made at the hackweekend: we need proper tests for the lua code.

@matthijsmelissen
Copy link
Contributor Author

Thanks for the update. I know it's always hard to tell, especially when volunteers are involved, but do you have any idea how long it will take before the new lua file is ready?

Do you think the problems are so serious that you'd recommend openstreetmap-carto (and therefore the openstreetmap.org tile servers) to wait for the new lua file, or do you think we could use the current lua file within openstreetmap-carto?

@pnorman
Copy link
Collaborator

pnorman commented Mar 4, 2016

style.lua is an example, not a default. I wouldn't recommend using it as-is for any project.

This allows the decision whether an object is treated as polygon or linestring
to be set in the style.lua file.

In particular, it treats man_made=embankment and natural=cliff as linestring,
and highway=services as polygon.

Including this in the default style.lua file has the following advantages:
* It serves as an easy-to-extend example of how the polygon/linestring decision
  can be made based on key.
* It provides sane defaults - it can be expected that most users of the style
  want to treat man_made=embankment and natural=cliff as linestring, and
  highway=services as polygon.

This resolves the following downstream bugs in openstreetmap-carto:
* gravitystorm/openstreetmap-carto#892
* gravitystorm/openstreetmap-carto#268
* gravitystorm/openstreetmap-carto#137

This builds on osm2pgsql-dev#345, and thus assumes osm2pgsql-dev#345 is merged first.
… lua

The first commit did not work if a key occurs with multiple values in
polygon_values or linestring_values
@matthijsmelissen
Copy link
Contributor Author

Rebased.

As far as I'm aware, this is still awaiting review from the osm2pgsql team.

matthijsmelissen added a commit to matthijsmelissen/openstreetmap-carto that referenced this pull request May 16, 2016
This PR proposes a database-reload. It changes the documentation on the use of
osm2pgsql, and adds a .lua file for preprocessing.

This database import aims to be backwards compatible with older versions of
the style.

This resolves (at least part of) gravitystorm#1504.

Adding the hstore option to osm2pgsql allows the database to use all keys.

This PR proposes using hstore for new keys, and using traditional columns for
old keys. This allows us to stay compatible with old versions of the style.

According to [@pnorman's benchmarks](http://www.paulnorman.ca/blog/2014/03/osm2pgsql-and-hstore/),
using hstore without dropping columns would lead to a 9% size increase and a
0.38% speed decrease. Given the benefits of having all columns available, I
would consider this acceptable.

This is based on the following unmerged PR to osm2pgsql:
osm2pgsql-dev/osm2pgsql#346

It makes the polygon/linestring decision based on the tag value, in addition to
the tag key. In particular, highway=services and junction=yes are now treated as
polygon, while leisure=track, man_made=embankment, man_made=breakwater,
man_made=groyne, natural=cliff, natural=tree_row, historic=citywalls,
waterway=derelict_canal, waterway=ditch, waterway=drain, waterway=river,
waterway=stream, waterway=wadi, waterway=weir, power=line, and power=minor_line
are now treated as linestring.

This resolves gravitystorm#1362, resolves gravitystorm#137, resolves gravitystorm#268, and resolves gravitystorm#892.

The new .lua file creates a osmcarto_z_order value in the database, which stores
the rendering order we use. This will allow us to simplify the road queries.

This resolves gravitystorm#59.

This resolves gravitystorm#101.

The .lua file drops some more meta-information from imports that is of no
need for rendering.

This is based on the following unmerged PR to osm2pgsql:
* osm2pgsql-dev/osm2pgsql#532
matthijsmelissen added a commit to matthijsmelissen/openstreetmap-carto that referenced this pull request May 16, 2016
This PR proposes a database-reload. It changes the documentation on the use of
osm2pgsql, and adds a .lua file for preprocessing.

This database import aims to be backwards compatible with older versions of
the style.

This resolves (at least part of) gravitystorm#1504.

 #Hstore
Adding the hstore option to osm2pgsql allows the database to use all keys.

This PR proposes using hstore for new keys, and using traditional columns for
old keys. This allows us to stay compatible with old versions of the style.

According to [@pnorman's benchmarks](http://www.paulnorman.ca/blog/2014/03/osm2pgsql-and-hstore/),
using hstore without dropping columns would lead to a 9% size increase and a
0.38% speed decrease. Given the benefits of having all columns available, I
would consider this acceptable.

 # Make polygon/linestring decision based on value
This is based on the following unmerged PR to osm2pgsql:
osm2pgsql-dev/osm2pgsql#346

It makes the polygon/linestring decision based on the tag value, in addition to
the tag key. In particular, highway=services and junction=yes are now treated as
polygon, while leisure=track, man_made=embankment, man_made=breakwater,
man_made=groyne, natural=cliff, natural=tree_row, historic=citywalls,
waterway=derelict_canal, waterway=ditch, waterway=drain, waterway=river,
waterway=stream, waterway=wadi, waterway=weir, power=line, and power=minor_line
are now treated as linestring.

This resolves gravitystorm#1362, resolves gravitystorm#137, resolves gravitystorm#268, and resolves gravitystorm#892.

 # Rendering order
The new .lua file creates a osmcarto_z_order value in the database, which stores
the rendering order we use. This will allow us to simplify the road queries.

 # Recommend -G flag for multipolygons
This resolves gravitystorm#59.

 # Import ele on buildings
This resolves gravitystorm#101.

 # Delete more meta-tags from imports
The .lua file drops some more meta-information from imports that is of no
need for rendering.

This is based on the following unmerged PR to osm2pgsql:
* osm2pgsql-dev/osm2pgsql#532
matthijsmelissen added a commit to matthijsmelissen/openstreetmap-carto that referenced this pull request May 16, 2016
**This is a pull-request against the lua branch**

This PR proposes a database-reload. It changes the documentation on the use of
osm2pgsql, and adds a .lua file for preprocessing.

This database import aims to be backwards compatible with older versions of
the style.

This resolves (at least part of) gravitystorm#1504.

 #Hstore
Adding the hstore option to osm2pgsql allows the database to use all keys.

This PR proposes using hstore for new keys, and using traditional columns for
old keys. This allows us to stay compatible with old versions of the style.

According to [@pnorman's benchmarks](http://www.paulnorman.ca/blog/2014/03/osm2pgsql-and-hstore/),
using hstore without dropping columns would lead to a 9% size increase and a
0.38% speed decrease. Given the benefits of having all columns available, I
would consider this acceptable.

 # Make polygon/linestring decision based on value
This is based on the following unmerged PR to osm2pgsql:
osm2pgsql-dev/osm2pgsql#346

It makes the polygon/linestring decision based on the tag value, in addition to
the tag key. In particular, highway=services and junction=yes are now treated as
polygon, while leisure=track, man_made=embankment, man_made=breakwater,
man_made=groyne, natural=cliff, natural=tree_row, historic=citywalls,
waterway=derelict_canal, waterway=ditch, waterway=drain, waterway=river,
waterway=stream, waterway=wadi, waterway=weir, power=line, and power=minor_line
are now treated as linestring.

This resolves gravitystorm#1362, resolves gravitystorm#137, resolves gravitystorm#268, and resolves gravitystorm#892.

 # Rendering order
The new .lua file creates a osmcarto_z_order value in the database, which stores
the rendering order we use. This will allow us to simplify the road queries.

 # Recommend -G flag for multipolygons
This resolves gravitystorm#59.

 # Import ele on buildings
This resolves gravitystorm#101.

 # Delete more meta-tags from imports
The .lua file drops some more meta-information from imports that is of no
need for rendering.

This is based on the following unmerged PR to osm2pgsql:
* osm2pgsql-dev/osm2pgsql#532
@pnorman
Copy link
Collaborator

pnorman commented Jul 26, 2017

Closing as stale. style.lua is an example, and if a style needs a full transform, the osm-carto one is a good starting point.

We should probably rewrite style.lua based on osm-carto's experience, and add tests.

@pnorman pnorman closed this Jul 26, 2017
@matthijsmelissen
Copy link
Contributor Author

We should probably rewrite style.lua based on osm-carto's experience, and add tests.

Yes, that would be great.

I don't think it make sense that each individual style decides for themselves which osm objects represent areas and which represent linestrings. This is a decision about the semantics of objects in OSM, not a styling decision. Competing styles are great, but competing semantics make no sense. So I think this is really something that should be done in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants