From 1753a0f7eaf0bbc0ba6c42a830a20950b57afd44 Mon Sep 17 00:00:00 2001 From: astrid Date: Fri, 11 Oct 2024 13:50:43 +0200 Subject: [PATCH 1/4] pointOnSurface --- config.json | 4 +--- process.lua | 38 ++++++++++++++------------------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/config.json b/config.json index e4b659e..f605aaa 100644 --- a/config.json +++ b/config.json @@ -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, diff --git a/process.lua b/process.lua index 9673d18..f364cca 100644 --- a/process.lua +++ b/process.lua @@ -1119,6 +1119,20 @@ 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 boundary = Find("boundary") + local admin_level = Find("admin_level") + local name = Find("name") + + if boundary == "administrative" and (admin_level == "2" or admin_level == "3" or admin_level == "4") then + LayerAsCentroid("boundary_labels") + MinZoom(2) + setNameAttributes() + Attribute("admin_level", admin_level) + end +end + ---- Accept boundary relations function relation_scan_function() if Find("type") ~= "boundary" then @@ -1151,29 +1165,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 From ca6e6e6cb7d937585a6e3b77f55c1d5220c28039 Mon Sep 17 00:00:00 2001 From: astrid Date: Fri, 11 Oct 2024 21:17:26 +0200 Subject: [PATCH 2/4] impove --- process.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/process.lua b/process.lua index f364cca..b735e0f 100644 --- a/process.lua +++ b/process.lua @@ -1125,11 +1125,11 @@ function relation_function(relation) local admin_level = Find("admin_level") local name = Find("name") - if boundary == "administrative" and (admin_level == "2" or admin_level == "3" or admin_level == "4") then + if boundary == "administrative" and admin_level_valid(Find("admin_level"), false) then LayerAsCentroid("boundary_labels") MinZoom(2) setNameAttributes() - Attribute("admin_level", admin_level) + AttributeNumeric("admin_level", admin_level) end end From 9a83f90d1f6f20654736509e8a3d556f1110f2d0 Mon Sep 17 00:00:00 2001 From: astrid Date: Fri, 11 Oct 2024 21:19:05 +0200 Subject: [PATCH 3/4] wip --- boundary_labels_shape_file.md | 48 ----------------------------------- get-shapefiles.sh | 1 - 2 files changed, 49 deletions(-) delete mode 100644 boundary_labels_shape_file.md diff --git a/boundary_labels_shape_file.md b/boundary_labels_shape_file.md deleted file mode 100644 index b20b070..0000000 --- a/boundary_labels_shape_file.md +++ /dev/null @@ -1,48 +0,0 @@ -# Boundary Labels Shape File - -The *boundary_labels* layer uses a shape file of labelling points for administrative polygons as data source -because Tilemaker offers a centroid but no PointOnSurface function. This file explains how to create the shape file. - -## Content of the Shape File - -The shape file must have the following fields: - -* `admin_leve`: value of OSM `admin_level=*` tag -* `name`: value of OSM `name=*` tag -* `name_de`: value of OSM `name:de=*` tag -* `name_en`: value of OSM `name:en=*` tag -* `way_area`: polygon area in ha in Web Mercator projection - -The features must be sorted by `way_area` in descending order. - -The shape file must contain features with `admin_level=2` and `admin_level=4` only. - -## Create Shape File with Osmium, Osm2pgsql and PostGIS - -You can create the shape file with Osmium, Osm2pgsql and PostGIS: - -Filter the planet dump using Osmium: - -```sh -osmium tags-filter -o admin.osm.pbf planet-latest.osm.pbf r/admin_level=2 r/admin_level=4 -``` - -Create database and enable PostGIS and Hstore support (you might have to create the database superuser using `createuser` first): - -```sh -createdb -E utf8 -O $USER adminpolygons -psql -d adminpolygons -c "CREATE EXTENSION postgis;" -psql -d adminpolygons -c "CREATE EXTENSION hstore;" -``` - -Import filtered planet dump: - -```sh -osm2pgsql -d adminpolygons --hstore --multi-geometry --latlong admin.osm.pbf -``` - -Export shape file: - -```sh -pgsql2shp -f admin-points.shp adminpolygons "SELECT admin_level, name, tags->'name:de' AS name_de, tags->'name:en' AS name_en, ST_Area(ST_Transform(way, 3857)) / 10000 AS way_area, ST_PointOnSurface(way) AS geom FROM planet_osm_polygon WHERE osm_id < 0 AND boundary = 'administrative' AND admin_level IN ('2', '4') ORDER BY way_area DESC;" -``` diff --git a/get-shapefiles.sh b/get-shapefiles.sh index 450beeb..8c7df0e 100755 --- a/get-shapefiles.sh +++ b/get-shapefiles.sh @@ -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 From 16e7be1ec06d3391fbde63b494cd5fda53a58bc7 Mon Sep 17 00:00:00 2001 From: astrid Date: Sat, 12 Oct 2024 12:13:33 +0200 Subject: [PATCH 4/4] add way_area --- process.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/process.lua b/process.lua index b735e0f..ed3a7a2 100644 --- a/process.lua +++ b/process.lua @@ -1121,6 +1121,7 @@ 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") @@ -1130,6 +1131,7 @@ function relation_function(relation) MinZoom(2) setNameAttributes() AttributeNumeric("admin_level", admin_level) + Attribute("way_area", area / 10000) end end