omniscale / imposm3

Imposm imports OpenStreetMap data into PostGIS
http://imposm.org/docs/imposm3/latest/
Apache License 2.0
723 stars 158 forks source link

On Generalized table : error Geometry type (MultiPolygon) does not match column type (Polygon) #262

Closed frodrigo closed 2 years ago

frodrigo commented 3 years ago

Generalization of multi-polygon table may produce polygon table. Then it fails to update, when the update come with a multipolygon geometry.

The geometry type of generalized table is left to postgres.

When the imported tables is from polygons, the geometry type is geometry(Geometry,3857) allowing any type of geometry, and it fine. On generalisation process with a filter (WHERE), multi-polygon may be excluded. Resulting only with polygon. Postgres compute the type of the column from the data. So it maybe a mix of polygons and multipolygons geometry(Geometry,3857) or only polygon geometry(Polygon,3857).

When an update come with a type of multipolygon while the generalized table is only for polygon, the insert fails with:

ERROR:  Geometry type (MultiPolygon) does not match column type (Polygon)

It look like to me the issue com from here: https://github.com/omniscale/imposm3/blob/master/database/postgis/postgis.go#L335 The generalized field are computed here: https://github.com/omniscale/imposm3/blob/master/database/postgis/columns.go#L29 and only the name is used.

The column must contain cast to the desired type, from the original field type:

geometry::geometry(Geometry,3857)

https://github.com/openmaptiles/openmaptiles/issues/1018

pnorman commented 3 years ago

I tried hard to reproduce this but couldn't with imposm3 v0.11.1, which has 9a98d9c5066e2c751c381b817013111226246895 in it. I see the original report at https://github.com/openmaptiles/openmaptiles/issues/1018#issuecomment-782148237 identified that OMT uses an old version of imposm3. Is it possible it's using one that doesn't support PostGIS 3?

olt commented 2 years ago

Fixed with #263