Skip to content

Commit

Permalink
Allow polygon/linestring decision to be set by value in lua
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthijsmelissen committed Apr 28, 2015
1 parent 535755c commit 60a53c9
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ polygon_keys = { 'building', 'landuse', 'amenity', 'harbour', 'historic', 'leisu
'public_transport', 'shop', 'sport', 'tourism', 'waterway',
'wetland', 'water', 'aeroway' }

-- Objects with any of the following key/value combinations will be treated as polygon
polygon_values = {highway='services'}

-- Objects with any of the following key/value combinations will be treated as linestring
linestring_values = {man_made='embankment', natural='cliff'}

-- Objects without any of the following keys will be deleted
generic_keys = {'access','addr:housename','addr:housenumber','addr:interpolation','admin_level','aerialway','aeroway','amenity','area','barrier',
'bicycle','brand','bridge','boundary','building','capital','construction','covered','culvert','cutting','denomination','disused','ele',
Expand Down Expand Up @@ -126,6 +132,22 @@ function filter_tags_way (keyvalues, numberofkeys)
break
end
end

-- Treat objects with a key/value combination in polygon_values as polygon
for k,v in pairs(polygon_values) do
if keyvalues[k] == v then
polygon=1
break
end
end

-- Treat objects with a key/value combination in linestring_values not as polygon
for k,v in pairs(linestring_values) do
if keyvalues[k] == v then
polygon=0
break
end
end

-- Treat objects tagged as area=yes, area=1, or area=true as polygon,
-- and treat objects tagged as area=no, area=0, or area=false not as polygon
Expand Down Expand Up @@ -168,14 +190,29 @@ function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, memberc
-- Treat as polygon
polygon = 1
polytagcount = 0;
-- Count the number of polygon tags of the object
-- Count the number of polygon tags
-- First count keys in polygon_keys
for i,k in ipairs(polygon_keys) do
if keyvalues[k] then
polytagcount = polytagcount + 1
end
end
-- If there are no polygon tags, add tags from all outer elements to the multipolygon itself
if (polytagcount == 0) then
-- Then add key/value combinations in polygon_values
for k,v in pairs(polygon_values) do
if keyvalues[k] == v then
polytagcount = polytagcount + 1
end
end
-- Then substract key/value combinations in linestring_values
for k,v in pairs(linestring_values) do
if keyvalues[k] == v then
polytagcount = polytagcount - 1
end
end

-- If the multipolygon has no polygon keys or polygon key/value combinations,
-- add tags from all outer elements to the multipolygon itself
if (polytagcount <= 0) then
for i = 1,membercount do
if (roles[i] == "outer") then
for k,v in pairs(keyvaluemembers[i]) do
Expand Down

0 comments on commit 60a53c9

Please sign in to comment.