From 926d32c055971cccaacc0bd4df1e831c51f6993b Mon Sep 17 00:00:00 2001 From: Math1985 Date: Tue, 28 Apr 2015 15:33:02 +0100 Subject: [PATCH] Allow polygon/linestring decision to be set by value in lua 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 expeced 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: * https://github.com/gravitystorm/openstreetmap-carto/issues/892 * https://github.com/gravitystorm/openstreetmap-carto/issues/268 * https://github.com/gravitystorm/openstreetmap-carto/issues/137 This builds on #345, and thus assumes #345 is merged first. --- style.lua | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/style.lua b/style.lua index 6de4fc455..4111acd35 100644 --- a/style.lua +++ b/style.lua @@ -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', @@ -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 @@ -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