6 Commits

Author SHA1 Message Date
64e1202283 Add configuration for luacheck and run luacheck in Github actions
Also fixes some warnings generated by luacheck.
2023-07-30 16:21:04 +02:00
6642d04bc2 Add geometry functions in Lua / new insert syntax
This is the future of geometry processing in Lua. Geometries are not
something happening magically behind the scenes as before, but they are
(mostly) normal objects that can be manipulated in Lua. There are
several functions to create those geometry objects from the OSM objects:

* as_point() (for nodes)
* as_linestring() (for ways)
* as_polygon() (for ways)
* as_multilinestring() (for relations)
* as_multipolygon() (for relations)
* as_geometrycollection() (for relations)

Geometries can be manipulated with the following functions (all based on
their equivalents in PostGIS):

* area() (for polygons)
* centroid() (for polygons)
* geometries() for iterating over (multi)geometries
* geometry_n() return the nth geometry from a (multi)geometry.
* geometry_type() returns type as string ('POINT', 'LINESTRING', ...)
* is_null() returns true if this is a null geometry
* num_geometries() returns the number of geometries (0 for null geom, 1
  for point/linestring/polygon, n for multi* and geometrycollection
  geoms). This can also be accessed as #geom (the usual Lua length
  operator)
* segmentize(max_segment_length) (for linestrings)
* simplify(tolerance) (for linestrings)
* srid()
* transform(target_srid)

Some of these functions are using boost::geometry for their
implementation. More functions can be implemented in the future as
needed.

There is a new syntax for inserting rows into a table. Instead of
"add_row" the "insert" function is used. "add_row" is still available
and it works as before. But the new geometry types only work with the
"insert" command. The "insert" function also allows multiple geometry
columns which wasn't possible with "add_row".

See the file flex-config/new-insert-syntax.lua for an example that shows
how to use the new capabilities.
2022-08-10 15:07:55 +02:00
ca7c5faed4 Make several Lua helper functions handle nil
The Lua helper functions clamp(), has_prefix(), has_suffix(), trim(),
and split_string() now all return nil if they are called with nil
as (first) argument. This makes them more robust, for instance when
called on non-existent tags and so simplifies user code.
2020-11-11 15:01:16 +01:00
2a826c3aae Add trim(), split_unit() and split_string() Lua helper functions 2020-11-11 14:48:55 +01:00
8c5d5fd715 Add starts_with()/ends_with() and suffix check in make_clean_tags_func
Adds Lua helper functions has_prefix() and has_suffix(). This is useful
for checks like osm2pgsql.has_prefix(some_tag, 'addr:').

Also add functionality to the osm2pgsql.make_clean_tags_func() function
to also check for suffixes, so '*:sources' will check for all tags
with suffix ':sources'.
2020-11-05 09:50:38 +01:00
0034569bac Add some Lua helper functions with docs, and tests for them 2020-02-27 09:23:52 +01:00