Skip to content

Latest commit

 

History

History
121 lines (116 loc) · 4.89 KB

File metadata and controls

121 lines (116 loc) · 4.89 KB
chapter 21
appendix B
title Lua Library for Flex Output
functions
name synopsis description example
clamp
osm2pgsql.clamp(VALUE, MIN, MAX)
Return VALUE if it is between MIN and MAX, MIN if it is smaller, or MAX if it is larger. All parameters must be numbers. If VALUE is `nil`, `nil` is returned.
osm2pgsql.clamp(2, 3, 4) ⟶ 3
name version synopsis description example
has_prefix
1.4.0
osm2pgsql.has_prefix(STRING, PREFIX)
Returns `true` if the STRING starts with PREFIX. If STRING is `nil`, `nil` is returned.
osm2pgsql.has_prefix('addr:city', 'addr:') ⟶ true
name version synopsis description example
has_suffix
1.4.0
osm2pgsql.has_suffix(STRING, SUFFIX)
Returns `true` if the STRING ends with SUFFIX. If STRING is `nil`, `nil` is returned.
osm2pgsql.has_suffix('tiger:source', ':source') ⟶ true
name synopsis description example
make_check_values_func
osm2pgsql.make_check_values_func(VALUES[, DEFAULT])
Return a function that will check its only argument against the list of VALUES. If it is in that list, it will be returned, otherwise the DEFAULT (or nil) will be returned.
local get_highway_value = osm2pgsql.make_check_values_func({ 'motorway', 'trunk', 'primary', 'secondary', 'tertiary' }, 'road') ... if object.tags.highway then local highway_type = get_highway_value(object.tags.highway) ... end
name synopsis description example
make_clean_tags_func
osm2pgsql.make_clean_tags_func(KEYS)
Return a function that will remove all tags (in place) from its only argument if the key matches KEYS. KEYS is an array containing keys, key prefixes (ending in `*`), or key suffixes (starting with `*`). The generated function will return `true` if it removed all tags, `false` if there are still tags left.
local clean_tags = osm2pgsql.make_clean_tags_func{'source', 'source:*', '*:source', 'note'} function osm2pgsql.process_node(node) if clean_tags(node.tags) then return end ... end
name version synopsis description example
split_string
1.4.0
osm2pgsql.split_string(STRING[, DELIMITER])
Split STRING on DELIMITER (default: ';' (semicolon)) and return an array table with the results. Items in the array will have any whitespace at beginning and end removed. If STRING is `nil`, `nil` is returned.
local opening_hours = osm2pgsql.split_string(object.tags.opening_hours)
name version synopsis description example
split_unit
1.4.0
osm2pgsql.split_unit(STRING, DEFAULT_UNIT)
Split STRING of the form "VALUE UNIT" (something like "10 mph" or "20km") into the VALUE and the UNIT and return both. The VALUE must be a negative or positive integer or real number. The space between the VALUE and UNIT is optional. If there was no unit in the string, the DEFAULT_UNIT will be returned instead. Return `nil` if the STRING doesn't have the right pattern or is `nil`.
value, unit = osm2pgsql.split_unit(object.tags.maxspeed, 'km/h')
name version synopsis description example
trim
1.4.0
osm2pgsql.trim(STRING)
Return STRING with whitespace characters removed from the beginning and end. If STRING is `nil`, `nil` is returned.
local name = osm2pgsql.trim(object.tags.name)
name synopsis description example
way_member_ids
osm2pgsql.way_member_ids(RELATION)
Return an array table with the ids of all way members of RELATION.
function osm2pgsql.select_relation_members(relation) if relation.tags.type == 'route' then return { ways = osm2pgsql.way_member_ids(relation) } end end

The flex output includes a small library of useful Lua helper functions. All functions are in the osm2pgsql namespace.

These functions are available on the flex output, they cannot be used in the Lua tag transformations of the pgsql output. {:.note}

{% for func in page.functions -%}

Name{{ func.name }}{%- if func.version -%} (available from version {{ func.version }}){%- endif -%}
Synopsis{{ func.synopsis }}
Description{{ func.description }}
Example{{ func.example }}
{%- endfor -%}