[Tile-serving] [openstreetmap/osm2pgsql] Centroid of linestrings (Issue #1771)

Jochen Topf notifications at github.com
Wed Sep 21 20:14:45 UTC 2022


Lets try to unpack this:

1. Yes, the documentation is incomplete. Calculating the centroid is actually possible for all geometry types except GeometryCollection. We should change the docs.
2. The `centroid()` of a geometry is defined as the center of gravity of that geometry. If you have an invalid geometry there is no meaning to that. osm2pgsql is more picky about invalid geometries than PostGIS is. We consider creating invalid geometries a bug, because working with invalid geometries leads to all sorts of problems.
3. Your example `select ST_Centroid(ST_MakePoint(1,1))` is wrong, this will create a point and centroids for points work in osm2pgsql also. The right example would be `ST_Centroid(ST_MakeLine(ST_MakePoint(1, 1)))` which indeed does work in PostGIS but not in osm2pgsql, as discussed in 2.
4. I think the real question is: Should it be possible to create a point geometry from a way that has only a single point? If the answer is yes, we need `object:as_point()` to work in that case. For consistency it should probably return the null geometry if there is more than one point. (Note that there are many reasons why there can be only one point in a way, either because there is only one node, or because there are several nodes with the same ids or different ids but same locations, or because some of the nodes are not in the input data in which case osm2pgsql will just use the ones it finds.)
5. The example you mention is a bit different, because it is a relation only containing a single node. There is nothing wrong with that. Currently, the only way to get to that node is `as_geometrycollection()` though, and centroid isn't supported for GeometryCollections (mostly because I am not sure what the correct semantic would be for that). From your description I understand you tried to treat that relation as a MultiLineString, which will return a null geometry, because the relation doesn't contains any lines.

I think we should probably add (4). This would at least allow you to do whatever you want to do, although it is a bit annoying that you have to try `as_polygon()`, `as_linestring()`, and `as_point()` in that order for best results. But the normal use case is still that you want to be sure to always have good data and wrong data is ignored by default.

We are already thinking about how to fix (5). There will be some way of accessing single member geometries of relations directly. (And we should probably also add an `as_multipoint()` for consistency.)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/issues/1771#issuecomment-1254181643
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/osm2pgsql/issues/1771/1254181643 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20220921/126d3b29/attachment-0001.htm>


More information about the Tile-serving mailing list