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

Boundary Labels #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions boundary_labels_shape_file.md

This file was deleted.

4 changes: 1 addition & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"boundary_labels": {
"minzoom": 2,
"maxzoom": 14,
"source": "data/admin-points-4326/admin_points.shp",
"source_columns": true
"maxzoom": 14
},
"addresses": {
"minzoom": 14,
Expand Down
1 change: 0 additions & 1 deletion get-shapefiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ cd "$(dirname "$0")" || exit
mkdir -p data
download_and_extract "https://osmdata.openstreetmap.de/download/water-polygons-split-4326.zip" "water-polygons-split-4326.zip"
download_and_extract "https://osmdata.openstreetmap.de/download/simplified-water-polygons-split-3857.zip" "simplified-water-polygons-split-3857.zip"
download_and_extract "https://shortbread-tiles.org/shapefiles/admin-points-4326.zip" "admin-points-4326.zip"
mkdir -p data/simplified-water-polygons-split-4326
transform_shp data/simplified-water-polygons-split-3857/simplified_water_polygons.shp data/simplified-water-polygons-split-4326/simplified_water_polygons.shp
40 changes: 16 additions & 24 deletions process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,22 @@ function admin_level_valid(admin_level, is_unset_valid)
return (is_unset_valid and admin_level == "") or admin_level == "2" or admin_level == "3" or admin_level == "4"
end

-- Add boundary labels
function relation_function(relation)
local area = Area()
local boundary = Find("boundary")
local admin_level = Find("admin_level")
local name = Find("name")

if boundary == "administrative" and admin_level_valid(Find("admin_level"), false) then
LayerAsCentroid("boundary_labels")
MinZoom(2)
setNameAttributes()
AttributeNumeric("admin_level", admin_level)
Attribute("way_area", area / 10000)
end
end

---- Accept boundary relations
function relation_scan_function()
if Find("type") ~= "boundary" then
Expand Down Expand Up @@ -1151,29 +1167,5 @@ function attribute_function(attr, layer)
attributes["y"] = 0
return attributes
end
if layer == "boundary_labels" then
attributes = {}
attributes["admin_level"] = attr["admin_leve"]
if attributes["admin_level"] == nil then
attributes["admin_level"] = attr["ADMIN_LEVE"]
end
attributes["admin_level"] = tonumber(attributes["admin_level"])
keys = {"name", "name_de", "name_en", "way_area"}
for index, value in ipairs(keys) do
if attr[value] == nil then
attributes[value] = attr[string.upper(value)]
else
attributes[value] = attr[value]
end
end
-- Fill with fallback values if empty
local name = attributes["name"]
local name_de = attributes["name_de"]
local name_en = attributes["name_en"]
attributes["name"] = fillWithFallback(name, name_en, name_de)
attributes["name_de"] = fillWithFallback(name_de, name, name_en)
attributes["name_en"] = fillWithFallback(name_en, name, name_de)
return attributes
end
return attr
end