3

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?

3

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.

6

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);

0

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

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 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 Apr 24 '16 at 13:29
0

I had the same problem and I could fix it from

Geometry tools < "multiple parts to unique parts".

Easy and smooth...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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