Skip to content

Commit

Permalink
Merge pull request #2015 from joto/lua-cleanups
Browse files Browse the repository at this point in the history
Various Lua example file cleanups
  • Loading branch information
lonvia authored Jul 30, 2023
2 parents 12bf572 + 5eaf961 commit b977158
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion flex-config/addresses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local addrs = osm2pgsql.define_table({
}
})

function get_address(tags)
local function get_address(tags)
local addr = {}
local count = 0

Expand Down
2 changes: 1 addition & 1 deletion flex-config/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tables.relations = osm2pgsql.define_relation_table('relations', {
{ column = 'members', type = 'jsonb' },
})

function format_date(ts)
local function format_date(ts)
return os.date('!%Y-%m-%dT%H:%M:%SZ', ts)
end

Expand Down
8 changes: 4 additions & 4 deletions flex-config/bbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tables.boundaries = osm2pgsql.define_relation_table('boundaries', {

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand All @@ -43,7 +43,7 @@ end

-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
local function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
Expand Down Expand Up @@ -81,8 +81,8 @@ end

-- Format the bounding box we get from calling get_bbox() on the parameter
-- in the way needed for the PostgreSQL/PostGIS box2d type.
function format_bbox(object)
xmin, ymin, xmax, ymax = object.get_bbox()
local function format_bbox(object)
local xmin, ymin, xmax, ymax = object.get_bbox()
if xmin == nil then
return nil
end
Expand Down
27 changes: 13 additions & 14 deletions flex-config/compatible.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ if hstore and hstore_all then
end

-- Used for splitting up long linestrings
if srid == 4326 then
max_length = 1
else
local max_length = 1
if srid == 3857 then
max_length = 100000
end

Expand Down Expand Up @@ -320,8 +319,8 @@ local non_point_columns = {
'wood',
}

function gen_columns(text_columns, with_hstore, area, geometry_type)
columns = {}
local function gen_columns(text_columns, with_hstore, area, geometry_type)
local columns = {}

local add_column = function (name, type)
columns[#columns + 1] = { column = name, type = type }
Expand Down Expand Up @@ -412,11 +411,11 @@ local z_order_lookup = {
motorway = {39, true}
}

function as_bool(value)
local function as_bool(value)
return value == 'yes' or value == 'true' or value == '1'
end

function get_z_order(tags)
local function get_z_order(tags)
local z_order = 100 * math.floor(tonumber(tags.layer or '0') or 0)
local roads = false

Expand Down Expand Up @@ -447,7 +446,7 @@ function get_z_order(tags)
return z_order, roads
end

function make_check_in_list_func(list)
local function make_check_in_list_func(list)
local h = {}
for _, k in ipairs(list) do
h[k] = true
Expand All @@ -465,7 +464,7 @@ end
local is_polygon = make_check_in_list_func(polygon_keys)
local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)

function make_column_hash(columns)
local function make_column_hash(columns)
local h = {}

for _, k in ipairs(columns) do
Expand All @@ -475,7 +474,7 @@ function make_column_hash(columns)
return h
end

function make_get_output(columns, hstore_all)
local function make_get_output(columns)
local h = make_column_hash(columns)
if hstore_all then
return function(tags)
Expand Down Expand Up @@ -511,10 +510,10 @@ end

local has_generic_tag = make_check_in_list_func(generic_keys)

local get_point_output = make_get_output(point_columns, hstore_all)
local get_non_point_output = make_get_output(non_point_columns, hstore_all)
local get_point_output = make_get_output(point_columns)
local get_non_point_output = make_get_output(non_point_columns)

function get_hstore_column(tags)
local function get_hstore_column(tags)
local len = #hstore_column
local h = {}
for k, v in pairs(tags) do
Expand Down Expand Up @@ -561,7 +560,7 @@ function osm2pgsql.process_node(object)
tables.point:insert(output)
end

function add_line(output, geom, roads)
local function add_line(output, geom, roads)
for sgeom in geom:segmentize(max_length):geometries() do
output.way = sgeom
tables.line:insert(output)
Expand Down
4 changes: 2 additions & 2 deletions flex-config/data-types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local highways = osm2pgsql.define_way_table('highways', {

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand Down Expand Up @@ -63,7 +63,7 @@ for _, k in ipairs(highway_types) do
end

-- Parse a maxspeed value like "30" or "55 mph" and return a number in km/h
function parse_speed(input)
local function parse_speed(input)
if not input then
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion flex-config/expire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ print(")")

-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
local function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
Expand Down
4 changes: 2 additions & 2 deletions flex-config/gen/forests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
-- the forest has a name tag and the area is larger than a defined minimum
-- we'll also add the name and a point for the label.
local minimum_area_for_label = 0.001
function insert_forest(tags, geom)
local function insert_forest(tags, geom)
local attrs = {
tags = tags,
geom = geom,
Expand All @@ -93,7 +93,7 @@ function osm2pgsql.process_way(object)
end

function osm2pgsql.process_relation(object)
if not object.tags.type == 'multipolygon' then
if object.tags.type ~= 'multipolygon' then
return
end
local tags = object.tags
Expand Down
2 changes: 1 addition & 1 deletion flex-config/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)

-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
local function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
Expand Down
4 changes: 2 additions & 2 deletions flex-config/geometries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tables.pubs = osm2pgsql.define_node_table('pubs', {

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand All @@ -65,7 +65,7 @@ end

-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
local function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
Expand Down
2 changes: 1 addition & 1 deletion flex-config/indexes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tables.postboxes = osm2pgsql.define_node_table('postboxes', {

-- Helper function that looks at the tags and decides if this is possibly
-- an area.
function has_area_tags(tags)
local function has_area_tags(tags)
if tags.area == 'yes' then
return true
end
Expand Down
2 changes: 1 addition & 1 deletion flex-config/labelpoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'poi2', type = 'point', not_null = true },
})

function add(tags, geom)
local function add(tags, geom)
tables.polygons:insert({
name = tags.name,
tags = tags,
Expand Down
2 changes: 1 addition & 1 deletion flex-config/route-relations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tables.routes = osm2pgsql.define_relation_table('routes', {
-- it can be called any number of times and will lead to the same result.
local w2r = {}

function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand Down
2 changes: 1 addition & 1 deletion flex-config/simple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ end

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand Down
4 changes: 2 additions & 2 deletions flex-config/unitable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local dtable = osm2pgsql.define_table{

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
function clean_tags(tags)
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
Expand All @@ -34,7 +34,7 @@ function clean_tags(tags)
return next(tags) == nil
end

function process(object, geometry)
local function process(object, geometry)
if clean_tags(object.tags) then
return
end
Expand Down

0 comments on commit b977158

Please sign in to comment.