It’s hard to work with polygons, unless one only needs fast drawing and optimized intersection algorithms. For more fun applications, I need a tile map, with each tile corresponding to some type (building, road, etc.).
There are obviously many more tiles than just building and road. To achieve full coverage—or almost full—we need to consider more polygons and nodes.
For polygons, there are a couple more tags to consider.
This tag encodes rivers, forests, etc.
"natural": ["scree", "blockfield", "cliff", "bare_rock", "shrub", "spring", "rock", "heath", "plateau", "wood", "bay", "ridge", "tree_row", "tree_stump", "wetland", "dune", "tree", "peak", "scrub", "shrubbery", "water", "grassland", "stone", "earth_bank", "peninsula", "sand", "tree_group", "beach", "plant", "shingle", "cape", "mud"]
"landuse": ["religious", "harbour", "commercial", "forest", "education", "traffic_island", "religious;commercial;education;residential", "depot", "farmyard", "shrubs", "brownfield", "emergency", "plant_nursery", "farmland", "retail", "landfill", "vineyard", "government", "grass", "animal_keeping", "civic_admin", "construction", "military", "railway", "cemetery", "meadow", "tree_pit", "greenhouse_horticulture", "greenfield", "village_green", "allotments", "flowerbed", "basin", "quarry", "governmental", "garages", "industrial", "greenery", "residential", "institutional", "orchard", "recreation_ground", "embassy", "fairground", "forestry", "economic_yard"]
With this, we could add greenery and water types to the map.
For each node, we check if its tag map contains keys: building, highway, natural, landuse.
If yes, we check the natural and landuse values and set the appropriate type. Let’s start with:
For each polygon we retrieve, we know its type. We check which pixels the polygon intersects and fill each pixel with the appropriate color for that type.
This would work for almost all types, except roads, as roads are just lines with some width defined in tags.
I picked line widths depending on road type, which we know from some tags:
"highway": ["corridor", "primary_link", "busway", "rest_area", "path", "elevator", "road", "street_lamp", "sidewalk", "tertiary_link", "tertiary", "speed_camera", "living_street", "priority", "motorway_link", "trunk", "crossing", "steps", "motorway", "secondary", "passing_place", "motorway_junction", "turning_circle", "stop", "proposed", "footway", "cycleway", "trunk_link", "primary", "unclassified", "turning_loop", "traffic_sign", "platform", "raceway", "traffic_signals", "construction", "traffic_mirror", "secondary_link", "track", "give_way", "emergency_access_point", "cyclist_waiting_aid", "bridleway", "yes", "mini_roundabout", "services", "give_way;traffic_signals", "speed_display", "street_sign", "ladder", "residential", "milestone", "service", "pedestrian", "bus_stop"]
While not optimized, here is the result:
here this map with legend and scaling
there are still black tiles there, which we need to find in the future