[Tile-serving] [osm2pgsql-dev/osm2pgsql] Missing ways when importing relations (Issue #2301)

Goncalo Oliveira notifications at github.com
Tue Feb 11 16:12:36 UTC 2025


## What version of osm2pgsql are you using?

```
osm2pgsql version 2.0.1
Build: Release
Compiled using the following library versions:
Libosmium 2.20.0
Proj 9.5.1
Lua 5.1.4 (LuaJIT 2.1.1732813678)
```

## What operating system and PostgreSQL/PostGIS version are you using?

```
PostgreSQL 17
```

## Tell us something about your system

```
Mac M1 Pro
16 GB
8 cores
```

## What did you do exactly?

```
osm2pgsql --create gabon-latest.osm.pbf --slim --output=flex --style style.lua --cache 8000
```

[Gabon from Geofabrik](https://download.geofabrik.de/africa/gabon-latest.osm.pbf)

style.lua excerpt based on [geometries.lua](https://github.com/osm2pgsql-dev/osm2pgsql/blob/master/flex-config/geometries.lua)
```lua
function osm2pgsql.process_relation(object)
    local relation_type = object:grab_tag('type')

    if clean_tags(object.tags) then
        return
    end

    if relation_type == 'boundary' or (relation_type == 'multipolygon' and object.tags.boundary) then
        if not has_wanted_boundary_values(object.tags) then
            return
        end

        tables.boundaries:insert({
            tags = object.tags,
            geom = object:as_multilinestring():line_merge()
        })
        return
    end
end
```

## What did you expect to happen?

Boundaries imported as multilinestring geometries.


## What did happen instead?

To be honest, I'm not sure if this is down to the data itself or to the import process, but looking at the relation in openstreetmap.org, there are definitely more points. I'll focus on relation [192793](https://www.openstreetmap.org/relation/192793#map=8/-2.230/12.722), but there are others. Two things... 1. the multiline is not closed. At first I thought that the lines only needed to be stitched, but apparently 2. There are missing points.


## What did you do to try analyzing the problem?

Well, apart from the obvious visual discrepancies, I tried to look for missing nodes and ways for the relation

```sql
SELECT COUNT(*) AS missing_nodes
FROM (
    SELECT unnest(nodes) AS node_id
    FROM planet_osm_ways
    WHERE id IN (
        SELECT (member->>'ref')::BIGINT
        FROM planet_osm_rels,
             jsonb_array_elements(members) AS member
        WHERE id = 192793
        AND member->>'role' = 'outer'
        AND member->>'type' = 'W'
    )
) AS way_nodes
LEFT JOIN planet_osm_nodes n ON way_nodes.node_id = n.id
WHERE n.id IS NULL;
```

This resulted in zero, so all good.

```sql
SELECT COUNT(*) AS missing_ways
FROM (
    SELECT (member->>'ref')::BIGINT AS way_id
    FROM planet_osm_rels,
         jsonb_array_elements(members) AS member
    WHERE id = 192793
    AND member->>'role' = 'outer'
    AND member->>'type' = 'W'
) AS rel_ways
LEFT JOIN planet_osm_ways w ON rel_ways.way_id = w.id
WHERE w.id IS NULL;
```

This resulted in 3 missing ways.

As I said, I can't be sure if this is a data issue or an import issue, but if the visualization on openstreetmap is accurate, it seems to be the latter...  or maybe this is due to using a partial extract... of course, it could also be a problem between the keyboard and the chair...

Any guidance is more than welcome...

-- 
Reply to this email directly or view it on GitHub:
https://github.com/osm2pgsql-dev/osm2pgsql/issues/2301
You are receiving this because you are subscribed to this thread.

Message ID: <osm2pgsql-dev/osm2pgsql/issues/2301 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20250211/6d875cd8/attachment.htm>


More information about the Tile-serving mailing list