[Tile-serving] [openstreetmap/osm2pgsql] Add whitelist functionality to osm2pgsql.make_clean_tags_func (Discussion #1955)
Tilman M. Jaeschke
notifications at github.com
Fri Apr 21 08:46:15 UTC 2023
I use [PostGIS](https://postgis.net) and it's built-in function [ST_AsMVT](https://postgis.net/docs/ST_AsMVT.html) to provide my application client with tile data. My app is not a general purpose map and it uses only a specific set of tags. By whitelisting tag keys instead of blacklisting them i can be sure that nothing i do not need unnecessarily wastes any resources and i do not need to know every key there is and maintain a complete list.
Add this function to your flex config and call it with whitelist set to `true` to filter out tags with keys not present in the keys list. With whitelist set to `false` or not set at all it behaves exactly like the built-in function.
```lua
function osm2pgsql.make_clean_tags_func(keys, whitelist)
whitelist = whitelist or false;
local keys_to_consider = {}
local prefixes_to_consider = {}
local suffixes_to_consider = {}
for _, k in ipairs(keys) do
if k:sub(-1) == '*' then
prefixes_to_consider[#prefixes_to_consider + 1] = k:sub(1, -2)
elseif k:sub(1, 1) == '*' then
suffixes_to_consider[#suffixes_to_consider + 1] = k:sub(2)
else
keys_to_consider[k] = true
end
end
return function(tags)
local delete_tags = {}
local tag_matched
for key, _ in pairs(tags) do
tag_matched = keys_to_consider[key] or false
if not tag_matched then
for _, k in ipairs(prefixes_to_consider) do
if osm2pgsql.has_prefix(key, k) then
tag_matched = true
break
end
end
end
if not tag_matched then
for _, k in ipairs(suffixes_to_consider) do
if osm2pgsql.has_suffix(key, k) then
tag_matched = true
break
end
end
end
if tag_matched ~= whitelist then
delete_tags[#delete_tags + 1] = key
end
end
for _, key in ipairs(delete_tags) do
tags[key] = nil
end
return next(tags) == nil
end
end
```
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/discussions/1955
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/osm2pgsql/repo-discussions/1955 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20230421/e203c924/attachment.htm>
More information about the Tile-serving
mailing list