Skip to content

Conversation

@joto
Copy link
Collaborator

@joto joto commented Feb 4, 2022

This is intended to show how geometry processing in Lua could work. Only some example functions are implemented and not for all geometry types, error detection is limited etc.

Geometry creation functions:

  • as_point() (for nodes)
  • as_linestring() (for ways)
  • as_polygon() (for ways)
  • as_multipolygon() (for relations)

Geometry functions:

  • area() (for polygons)
  • centroid() (for polygons)
  • simplify() (for linestrings)

See the file flex-config/custom-geometries.lua for an example that shows how to use these.

@joto
Copy link
Collaborator Author

joto commented Feb 4, 2022

There are some issues with this approach:

  • Performance: It is unclear whether all of this processing and jumping between C++ and Lua is fast enough. This needs more testing.
  • Projections: Currently you can set the projection only in the table definition and it will be done automatically when a geometry is set. This is probably not enough, for instance when calculating an area in a different projection, we need to be able to project first, then calculate the area. So something like this would probably need adding: geom:as_polygon():transform(3857):area().
  • Backwards compatibility and "magic" geometry processing: The old way of handling geometries was somewhat magic, for instance long lines could be split and then add_row() would add multiple rows with those split geometries. The "new" way doesn't do that any more. We'd have a split_linestrings() function in Lua and then need to write a loop in Lua to add several rows. This makes certain types of processing harder to write in the config file and (probably) slower to process. But it allows more flexibility, for instance now multiple geometry columns are easily done, because the new geometry column types behave just like any other column type. It is difficult to wrap your head around all this, especially when old and new geometry types are mixed.

@joto joto force-pushed the wip-geom-flex branch 2 times, most recently from f1fd58b to 9ce32a8 Compare May 2, 2022 18:59
@joto joto force-pushed the wip-geom-flex branch 2 times, most recently from 194cc73 to 5e2efa7 Compare July 31, 2022 19:38
joto added 2 commits August 1, 2022 08:48
This is the future of geometry processing in Lua. Only the most
important geometry functions are implemented so far.

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 functions only work with
the "insert" command. The "insert" function also allows multiple
geometry columns which wasn't possible with "add_row".

Geometry creation functions:
* as_point() (for nodes)
* as_linestring() (for ways)
* as_polygon() (for ways)
* as_multilinestring() (for relations)
* as_multipolygon() (for relations)
* as_geometrycollection() (for relations)

Geometry functions:
* geometrytype()
* srid()
* transform(target_srid)
* area() (for polygons)
* centroid() (for polygons)
* simplify(tolerance) (for linestrings)
* split_multi() (for multi geometries)
* #geom/__len() returns the number of geometries (0 for null geom, 1 for
  point/linestring/polygon, n for multi* and geometrycollection geoms)

See the file flex-config/new-insert-syntax.lua for an example that shows
how to use these.
@joto joto closed this Aug 7, 2022
@joto joto deleted the wip-geom-flex branch August 7, 2022 12:49
@wambacher
Copy link

would like to have pointonsurface(geom) too, because the centroid of an admin boundary may be outside of the area.

See https://www.openstreetmap.org/relation/408592

regards
walter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants