diff --git a/boundary_labels_shape_file.md b/boundary_labels_shape_file.md new file mode 100644 index 0000000..b20b070 --- /dev/null +++ b/boundary_labels_shape_file.md @@ -0,0 +1,48 @@ +# 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/config.json b/config.json index 189ea84..63588b8 100644 --- a/config.json +++ b/config.json @@ -14,7 +14,9 @@ }, "boundary_labels": { "minzoom": 2, - "maxzoom": 14 + "maxzoom": 14, + "source": "data/admin-points-4326/admin_points.shp", + "source_columns": true }, "addresses": { "minzoom": 14, diff --git a/process.lua b/process.lua index 1facb03..fe6eed5 100644 --- a/process.lua +++ b/process.lua @@ -757,9 +757,6 @@ function way_function(way) end -- Layer boundaries - if way:Find("boundary") == "administrative" then - process_boundary_labels(way) - end process_boundary_lines(way) -- Layer streets, street_labels @@ -824,5 +821,21 @@ 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 + 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 + return attributes + end return attr end