Bug report #5109

ERROR: Geometry type Poly not match MultiPoly

Added by Salvatore Larosa over 12 years ago. Updated about 11 years ago.

Status:Closed
Priority:Normal
Assignee:Salvatore Larosa
Category:Data Provider/PostGIS
Affected QGIS version:master Regression?:No
Operating System:Debian/wheezy Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed
Crashes QGIS or corrupts data:No Copied to github as #:14870

Description

Hi,
when I try to add a new geometries and then stop editing (save) I get this error:

Errore PostGIS nell'aggiunta delle geometrie: ERROR:  Geometry type (Polygon) does not match column type (MultiPolygon)

My features PostGIS is MULTIPOLYGON

postGISErrorQgis.png (14.5 KB) Salvatore Larosa, 2012-03-02 01:50 AM

postgis.jpg - Error message when adding a multipolygon shapefile wtih DB Manager. (72 KB) Maximilian L., 2012-08-12 10:26 PM

shp2pgsql.jpg (73.3 KB) Maximilian L., 2012-08-16 10:06 AM

multipart-singlepart.jpg (156 KB) Carlos Alberto Machicado Cabezas, 2013-07-09 05:51 PM


Related issues

Duplicated by QGIS Application - Bug report #7555: Postgis Multipolygon Errors Closed 2013-04-09

History

#1 Updated by Andreas Neumann over 12 years ago

Hi,

what are the constraints in the table in Postgis. The error message sounds like a Postgis problem - not like a QGIS problem.

There are two potential issues in Postgis:
  • constraints: you can allow either Multipolygon or polygon or both
  • an invalid entry in public.geometry_columns

Theoretically it could also be a QGIS problem - but I would first make sure that everything on the Postgis side is ok?

#2 Updated by Salvatore Larosa over 12 years ago

Hi, my table is:

CREATE TABLE test.prov
(
  gid serial NOT NULL,
  provincia character varying(30),
  cod_pro character varying(3),
  sigla character varying(2),
  cod_reg character varying(2),
  sede character varying(50),
  anno_volo numeric(10,0),
  liv_utente numeric(10,0),
  geom geometry(MultiPolygon,3004),
  CONSTRAINT prov_pkey PRIMARY KEY (gid ),
)

I did try to add some constraints:

CONSTRAINT enforce_dims CHECK (st_ndims(geom) = 2),
CONSTRAINT enforce_geometry_type CHECK (geometrytype(geom) = 'MULTIPOLYGON'::text OR geom IS NULL)

but I got the same error!

more info:

workshop=# SELECT * FROM public.geometry_columns WHERE f_table_name = 'prov';
 f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid |     type     
-----------------+----------------+--------------+-------------------+-----------------+------+--------------
 workshop        | test           | prov         | geom              |               2 | 3004 | MULTIPOLYGON
(1 row)

workshop=# SELECT postgis_full_version();
                                                                       postgis_full_version                                                    

-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------
 POSTGIS="2.0.0beta5SVN r9530" GEOS="3.3.2-CAPI-1.7.2" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.7.
8" TOPOLOGY RASTER
(1 row)

Thanks!

#3 Updated by Jürgen Fischer over 12 years ago

Salvatore Larosa wrote:

I did try to add some constraints:
CONSTRAINT enforce_dims CHECK (st_ndims(geom) = 2),
CONSTRAINT enforce_geometry_type CHECK (geometrytype(geom) = 'MULTIPOLYGON'::text OR geom IS NULL)
but I got the same error!

The constraint is the problem (or QGIS' ignorance about it, if you like). Changing it to

CONSTRAINT enforce_geometry_type CHECK (geometrytype(geom) = 'MULTIPOLYGON'::text OR geometrytype(geom) = 'POLYGON'::text OR geom IS NULL)

could help.

#4 Updated by Salvatore Larosa over 12 years ago

Jürgen Fischer wrote:

The constraint is the problem (or QGIS' ignorance about it, if you like). Changing it to

[...]

could help.

Thanks for the advice, but does not solve the problem!
If that works for you means that the problem is only mine! so?

#5 Updated by Salvatore Larosa over 12 years ago

I noticed that it happens only if the geometry is identified as a 'MULTI[LINESTRING,POINT,POLYGON]'

#6 Updated by Jürgen Fischer over 12 years ago

Salvatore Larosa wrote:

I noticed that it happens only if the geometry is identified as a 'MULTI[LINESTRING,POINT,POLYGON]'

That's what I meant. You're trying to save a POLYGON into a table that you restricted to MULTIPOLYGON s.

But I admit that the postgres provider could internally convert the POLYGON to a MULTIPOLYGON if necessary, but it currently just determines if the layer is a point, line or polygon layer as higher levels don't differentiate between single and multi geometries.

#7 Updated by Salvatore Larosa over 12 years ago

Something terrible has happened! :-)

I tried to edit and save with QGIS 1.7.3 (on the PC of a friend, but after that I hate :-)) on windows, and it works perfect!
I used the same table as I have created a connection that pointed to my linux machine!

In Linux with the master version, why not?

#8 Updated by Salvatore Larosa over 12 years ago

I also tried the version 1.7.4 is working correctly on Windows!
The problem seems to be present only in the master version on Linux!

#9 Updated by Jürgen Fischer over 12 years ago

49456116 should fix this.

#10 Updated by Salvatore Larosa over 12 years ago

Jürgen Fischer wrote:

49456116 should fix this.

Yes, solved!
Thanks!
I can't change the status ticket to closed, because I haven't rigths to do it, evidently!

One more thing, Might it solve the problem very like with the SPIT plugin?
Worth to file a new ticket?

#11 Updated by Jürgen Fischer over 12 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Salvatore Larosa wrote:

One more thing, Might it solve the problem very like with the SPIT plugin?
Worth to file a new ticket?

Give it a spin. I'd expect that one is solved too.

#12 Updated by Maximilian L. about 12 years ago

Salvatore Larosa wrote:

I also tried the version 1.7.4 is working correctly on Windows!
The problem seems to be present only in the master version on Linux!

I tested 1.7.4 and 1.8 on Windows 7 but got the same error-message in SPIT. :( How can I fix this easily on windows?

#13 Updated by Salvatore Larosa about 12 years ago

Maximilian L. wrote:

I tested 1.7.4 and 1.8 on Windows 7 but got the same error-message in SPIT. :( How can I fix this easily on windows?

Actually there is not any solution for that, the better way to import SHP into PostGIS is with DB Manager plugin!

Also have a look at this #5328, the SPIT plugin will be removed!

#14 Updated by Maximilian L. about 12 years ago

Salvatore Larosa wrote:

Actually there is not any solution for that, the better way to import SHP into PostGIS is with DB Manager plugin!

Also have a look at this #5328, the SPIT plugin will be removed!

Thank you for this information. But trying to import SHP into PostGIS with DB Manager brings me the same error (see picture).

#15 Updated by Salvatore Larosa about 12 years ago

Maximilian L. wrote:

Thank you for this information. But trying to import SHP into PostGIS with DB Manager brings me the same error (see picture).

I am aware of that!
I already filed this ticket #5547!
It is occurs because your polygon dataset has some multipolygon geometries.
Right now, one possible solution is to convert your dataset from multiparts to singlepart by Vector > Geometry Tools > Multipart to singleparts tool (fTool) and then import it by DbManager.

#16 Updated by Maximilian L. about 12 years ago

I already filed this ticket #5547!

Thank you!

It is occurs because your polygon dataset has some multipolygon geometries.
Right now, one possible solution is to convert your dataset from multiparts to singlepart by Vector > Geometry Tools > Multipart to singleparts tool (fTool) and then import it by DbManager.

I know but this is no solution for me...seems that I have to use the PostGIS Shapefile Loader.

#17 Updated by Giovanni Manghi about 12 years ago

Maximilian L. wrote:

I know but this is no solution for me...seems that I have to use the PostGIS Shapefile Loader.

so also the "PostGIS Manager" plugin works for you?

#18 Updated by Salvatore Larosa about 12 years ago

Giovanni Manghi wrote:

Maximilian L. wrote:

I know but this is no solution for me...seems that I have to use the PostGIS Shapefile Loader.

so also the "PostGIS Manager" plugin works for you?

I think Maximilian was referring to shp2pgsql-gui importer!
Unfortunately, no QGIS plugin at the moment works!

#19 Updated by Giovanni Manghi about 12 years ago

I think Maximilian was referring to shp2pgsql-gui importer!
Unfortunately, no QGIS plugin at the moment works!

postgis manager uses shp2pgsql so it should work

#20 Updated by Salvatore Larosa about 12 years ago

Giovanni Manghi wrote:

I think Maximilian was referring to shp2pgsql-gui importer!
Unfortunately, no QGIS plugin at the moment works!

postgis manager uses shp2pgsql so it should work

You're right, works fine!

Also, I guess there is a redundance between PostGIS Manager, Spatialite Manager and
RT_SQL Layer plugins. I do not know if they still maintained but should be removed IMO.
DBManager already does all of that!

#21 Updated by Giovanni Manghi about 12 years ago

Also, I guess there is a redundance between PostGIS Manager, Spatialite Manager and
RT_SQL Layer plugins. I do not know if they still maintained but should be removed IMO.
DBManager already does all of that!

PostGIS manager is abandoned and it will be removed when all its feature will be ported in DB manager. Same for SL manager. I'm not sure but also the RT_SQL plugins will be integrated into DB manager.

Anyway, DB manager does not uses shp2pgsql (to avoid have the user install postgis) but it sometimes fails, like in this case. So please file a ticket against DB manager, give it to Giuseppe and if possible attach a sample of the data.

#22 Updated by Maximilian L. about 12 years ago

Salvatore Larosa wrote:

Giovanni Manghi wrote:

postgis manager uses shp2pgsql so it should work

You're right, works fine!

For me it does not: "somethings wrong: The command "shp2pgsql" is wrong written or couldn't be found". In addition I had to edit 2 .py-files of the extension in combination with PostGIS 2.0 to not have an error log at startup.

#23 Updated by Giovanni Manghi about 12 years ago

Maximilian L. wrote:

Salvatore Larosa wrote:

Giovanni Manghi wrote:

postgis manager uses shp2pgsql so it should work

You're right, works fine!

For me it does not: "somethings wrong: The command "shp2pgsql" is wrong written or couldn't be found". In addition I had to edit 2 .py-files of the extension in combination with PostGIS 2.0 to not have an error log at startup.

maybe you don't have shp2pgsql in your path. Under Windows must be added manually.

#24 Updated by Maximilian L. about 12 years ago

Giovanni Manghi wrote:

Maximilian L. wrote:

Salvatore Larosa wrote:

Giovanni Manghi wrote:

postgis manager uses shp2pgsql so it should work

You're right, works fine!

For me it does not: "somethings wrong: The command "shp2pgsql" is wrong written or couldn't be found". In addition I had to edit 2 .py-files of the extension in combination with PostGIS 2.0 to not have an error log at startup.

maybe you don't have shp2pgsql in your path. Under Windows must be added manually.

Where I have to add it? Okay, than it is perhaps my mistake.

#25 Updated by Giovanni Manghi about 12 years ago

Where I have to add it? Okay, than it is perhaps my mistake.

you have to add the path (that points to the folder were shp2pgsql resides) into the "path" Windows environment variable. You find this option in the advanced system settings in your Windows control panel.

#26 Updated by Maximilian L. about 12 years ago

Giovanni Manghi wrote:

you have to add the path (that points to the folder were shp2pgsql resides) into the "path" Windows environment variable. You find this option in the advanced system settings in your Windows control panel.

Well, this is what I did, but it didn't help (after restart).

#27 Updated by Giovanni Manghi about 12 years ago

Well, this is what I did, but it didn't help (after restart).

odd, because it certainly works.

Try open the Windows terminal and enter the command

shp2psql

what happens?

#28 Updated by Maximilian L. about 12 years ago

Giovanni Manghi wrote:

odd, because it certainly works.
Try open the Windows terminal and enter the command
shp2psql
what happens?

Same error message: "Command not found or wrong written". Variable is shp2pgsql and the value is the path where the shp2pgsql.exe is.

#29 Updated by Giovanni Manghi about 12 years ago

Same error message: "Command not found or wrong written". Variable is shp2pgsql and the value is the path where the shp2pgsql.exe is.

I'm sorry, it means that you have done something wrong. Until the command is not available trough the command line interface it cannot work in QGIS.

But anyway, this is why DB Manager does not use shp2pgsql. If you have any error using DB manager then please file a ticket, give it to giuseppe sucameli, and add sample data (along with the error message).

#30 Updated by Maximilian L. about 12 years ago

I'm sorry, it means that you have done something wrong. Until the command is not available trough the command line interface it cannot work in QGIS.

This is what I've done --> shp2pgsql.jpg

#31 Updated by Carlos Alberto Machicado Cabezas about 11 years ago

Found a solution focused on the shapelfile data, the problem lies in the geometry in this case multipolygon Multipart a way to simplify the geometry of Multipart To Singlepart(multipolygon to polygon) found in the Data Management's toolbox of ArcGis. Regards
Carlos Alberto Machicado

#32 Updated by Giovanni Manghi about 11 years ago

  • Status changed from Reopened to Closed

Carlos Alberto Machicado Cabezas wrote:

Found a solution focused on the shapelfile data, the problem lies in the geometry in this case multipolygon Multipart a way to simplify the geometry of Multipart To Singlepart(multipolygon to polygon) found in the Data Management's toolbox of ArcGis. Regards
Carlos Alberto Machicado

why reopening this ticket? the multipart to singlepart tool there is also in qgis, what is your point? cheers!

Also available in: Atom PDF