Skip to content

Commit

Permalink
Merge pull request #40 from astridx/master
Browse files Browse the repository at this point in the history
Update openstreetmap-carto-hstore-only-l10n.lua - Switching from `add_row()` to `insert()` for osm2pgsql
  • Loading branch information
giggls authored Oct 21, 2024
2 parents f84119f + c9962cc commit d06b251
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions openstreetmap-carto-hstore-only-l10n.lua
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ col_definitions = {
{ column = 'tags', type = 'hstore' },
{ column = 'layer', type = 'int4' },
{ column = 'z_order', type = 'int4' },
{ column = 'way_area', type = 'area' },
{ column = 'way_area', type = 'real' },
{ column = 'name_l10n', sql_type = 'text[]'}
},
route = {
Expand Down Expand Up @@ -439,6 +439,15 @@ function remove_name_tags(tags)
return next(tags) == nil
end

local function create_cols(tags)
local cols = {}
cols.tags = tags
cols['layer'] = layer(tags['layer'])
cols['z_order'] = z_order(tags)
cols.name_l10n = name_l10n
return cols
end

--- Splits a tag into tags and hstore tags
-- @return columns, hstore tags
function split_tags(tags, tag_map)
Expand All @@ -453,34 +462,27 @@ function split_tags(tags, tag_map)
return cols
end

function add_line(tags, name_l10n)
local cols = {}
cols.tags = tags
cols['layer'] = layer(tags['layer'])
cols['z_order'] = z_order(tags)
cols.way = { create = 'line', split_at = 100000 }
cols.name_l10n = name_l10n
tables.line:add_row(cols)
function add_line(tags, name_l10n, mgeom)
local cols = create_cols(tags)
for sgeom in mgeom:geometries() do
cols.way = sgeom
tables.line:insert(cols)
end
end

function add_roads(tags, name_l10n)
local cols = {}
cols.tags = tags
cols['layer'] = layer(tags['layer'])
cols['z_order'] = z_order(tags)
cols.way = { create = 'line', split_at = 100000 }
cols.name_l10n = name_l10n
tables.roads:add_row(cols)
function add_roads(tags, name_l10n, mgeom)
local cols = create_cols(tags)
for sgeom in mgeom:geometries() do
cols.way = sgeom
tables.roads:insert(cols)
end
end

function add_polygon(tags, name_l10n)
local cols = {}
cols.tags = tags
cols['layer'] = layer(tags['layer'])
cols['z_order'] = z_order(tags)
cols.way = { create = 'area'}
cols.name_l10n = name_l10n
tables.polygon:add_row(cols)
function add_polygon(tags, name_l10n, poly)
local cols = create_cols(tags)
cols.way = poly
cols.area = poly:area()
tables.polygon:insert(cols)
end

function add_route(object)
Expand All @@ -489,7 +491,7 @@ function add_route(object)
local cols = object.tags
cols.member_id = member.ref
cols.member_position = i
tables.route:add_row(cols)
tables.route:insert(cols)
end
end
end
Expand Down Expand Up @@ -523,7 +525,7 @@ function osm2pgsql.process_node(object)
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
end
tables.point:add_row({tags = object.tags, name_l10n = name_l10n})
tables.point:insert({tags = object.tags, name_l10n = name_l10n, way = object:as_point()})
end

function osm2pgsql.process_way(object)
Expand All @@ -532,14 +534,17 @@ function osm2pgsql.process_way(object)
return
end

local mgeom = object:as_linestring():transform(3857):segmentize(100000)
local poly = object:as_polygon():transform(3857)

local area_tags = isarea(object.tags)
if object.is_closed and area_tags then
if ((object.tags['name'] ~= nil) or (object.tags['name:' .. lang] ~= nil)) then
names = osml10n.get_names_from_tags(object.id, object.tags, true, false, lang, object.get_bbox)
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
end
add_polygon(object.tags, name_l10n)
add_polygon(object.tags, name_l10n, poly)
else
-- on line/road use streetname function on highways
if ((object.tags['name'] ~= nil) or (object.tags['name:' .. lang] ~= nil)) then
Expand All @@ -551,60 +556,61 @@ function osm2pgsql.process_way(object)
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
end
add_line(object.tags, name_l10n)

add_line(object.tags, name_l10n, mgeom)
if roads(object.tags) then
add_roads(object.tags, name_l10n)
add_roads(object.tags, name_l10n, mgeom)
end
end
end

function osm2pgsql.process_relation(object)
local names,languages,name_l10n

-- grab the type tag before filtering tags
local type = object.tags.type
object.tags.type = nil

if clean_tags(object.tags) then
return
end


local mgeom = object:as_multilinestring():line_merge():transform(3857):segmentize(100000)
local poly = object:as_multipolygon():transform(3857)

if type == "boundary" or (type == "multipolygon" and object.tags["boundary"]) then
-- add custom naming of countries because name is noit reliable
-- add custom naming of countries because name is not reliable
if ((object.tags['admin_level'] == '2') and (object.tags['ISO3166-1:alpha2'] ~= nil)) then
names = osml10n.get_country_name(object.tags, lang, true)
else
names = osml10n.get_names_from_tags(object.id, object.tags, true, false, lang, object.get_bbox)
end
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
add_line(object.tags, name_l10n)
add_line(object.tags, name_l10n, mgeom)

if roads(object.tags) then
add_roads(object.tags, name_l10n)
add_roads(object.tags, name_l10n, mgeom)
end

add_polygon(object.tags, name_l10n)
add_polygon(object.tags, name_l10n, poly)

elseif type == "multipolygon" then
if ((object.tags['name'] ~= nil) or (object.tags['name:' .. lang] ~= nil)) then
names = osml10n.get_names_from_tags(object.id, object.tags, true, false, lang, object.get_bbox)
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
end
add_polygon(object.tags, name_l10n)
add_polygon(object.tags, name_l10n, poly)
elseif type == "route" then
if ((object.tags['name'] ~= nil) or (object.tags['name:' .. lang] ~= nil)) then
names = osml10n.get_names_from_tags(object.id, object.tags, true, false, lang, object.get_bbox)
name_l10n = table2escapedarray(names)
if remove_names then remove_name_tags(object.tags) end
end
add_line(object.tags, name_l10n)
add_line(object.tags, name_l10n, mgeom)
add_route(object)
-- TODO: Remove this, roads tags don't belong on route relations
if roads(object.tags) then
add_roads(object.tags, name_l10n)
add_roads(object.tags, name_l10n, mgeom)
end
end
end

0 comments on commit d06b251

Please sign in to comment.