7

I'm using Postgres 9.4 and PostGIS 2.1. I have a table that looks like this:

 wkb_geometry | geometry(Polygon,4326) |
 id           | integer                |
 county       | character varying      |

I've learned that the table contains some invalid polygons (e.g. when I try to do ST_UNION I get errors), so I'm trying to fix them:

UPDATE mytable SET wkb_geometry=ST_makevalid(wkb_geometry) WHERE id='1';

But this gives me an error:

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

What should I do about this?

4 Answers 4

9

Previous answers might fail if you already have data (Polygon type) in your db.

To solve this with present polygon-type data: sql ALTER TABLE your_table ALTER COLUMN your_geocolumn TYPE geometry (multipolygon, 4326) USING ST_Multi(your_geocolumn);

5

Your incoming geometries are multipolygons, while the datatype of the geometry is polygons. These are incompatible, and hence you should convert the data type of your column to multipolygons, so that you can save the valid geometries.

This can be achieved by the following command:

Alter table  table1 alter column geom type geometry ( multipolygon,srid)

see sections 4.3.1 - 4.3.4 for more information on the SPATIAL_REF_SYS table, creating spatial tables and the postGIS GEOMETRY_COLUMNS view table.

1

I had the same problem and I could fix it from

Geometry tools < "multiple parts to unique parts".

Easy and smooth...

-1

Alter table table1 alter column geom type geometry ( multipolygon,srid)

1
  • 1
    Converting the table to contain multipolygon geometries is the right thing to do but perhaps you could add a few lines and tell why it is necessary.
    – user30184
    Commented Apr 24, 2016 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.