Flex: Allow creating point geometry from way#2429
Flex: Allow creating point geometry from way#2429lonvia merged 1 commit intoosm2pgsql-dev:masterfrom
Conversation
|
The cleaner solution would be to have a |
|
I think that's a different use case and we should solve that differently. We'll need some function to get nodes from ways and members from relations, but not just their geometries, but the whole object. We don't need |
|
Force pushed new version: as_point() can now take an index argument when called for a way which specifies which member node to take the location from. Index is 1-based, negative indexes count from the back. So :as_point(), :as_point(nil), :as_point(0), :as_point(1) will return the first node, :as_point(2) the second node and so on. :as_point(-1) will return the last node. If the index is out of range a null geometry will be returned. If the parameter is not a number an error will be generated. |
This allows the as_point() function to be called for ways. The function has a single (optional) parameter specifying which member node to create the point from. The index parameter is 1-based as usual in Lua. Negative indexes count from the back, :as_point(), :as_point(nil), :as_point(1) will return the first node, :as_point(2) the second node and so on. :as_point(-1) will return the last node. If the index is 0 or out of range a null geometry will be returned. If the parameter is not a number an error will be generated.
Ways can have a single node (or multiple nodes at the same location) in which case we can't build a proper linestring. This doesn't happen very often and is always an error in the data. This adds the functionality to flex Lua code to run as_point() on a way geometry which creates a point geometry from the first node.
This is mostly intended for the use case where we want to create a point from invalid ways to help fix them. It can also be used if you just need any point in that linestring for a rough position or so.