Bug report #6257

db manager fails to import all features from shapefile to spatialite

Added by Etienne Tourigny about 12 years ago. Updated almost 12 years ago.

Status:Closed
Priority:Normal
Assignee:Giuseppe Sucameli
Category:Data Provider/SpatiaLite
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:15563

Description

when dropping layer from file manager to spatialite file in browser, not all features are copied. This happens in both 1.8 and master

However, import is fine when using qspatialite plugin.

The error given when using 1.8 is

Failed to import some layers!

clas_226_67_20100724_pol: Feature write errors:
Creation error for features from #200 to #281. Provider errors was: 
SQLite error: constraint failed
SQL: INSERT INTO "clas_226_67_20100724_pol"("pk","geomm","sprarea","sprperimet","sprclasse") VALUES (NULL,GeomFromWKB(?, 4326),?,?,?)
Only 200 of 282 features written.

in master:

Failed to import some layers!

clas_226_67_20100724_pol: Feature write errors:
Creation error for features from #0 to #0. Provider errors was: 
SQLite error: constraint failed
SQL: INSERT INTO "clas_226_67_20100724_pol"("geomm","sprarea","sprperimet","sprclasse") VALUES (GeomFromWKB(?, 4326),?,?,?)
Only 200 of 282 features written.

ogrinfo on the file:

$ ogrinfo -so clas_226_67_20100724_pol.shp clas_226_67_20100724_pol
INFO: Open of `clas_226_67_20100724_pol.shp'
      using driver `ESRI Shapefile' successful.

Layer name: clas_226_67_20100724_pol
Geometry: Polygon
Feature Count: 282
Extent: (687536.000000, 8806300.000000) - (886580.000000, 8975017.000000)
Layer SRS WKT:
(unknown)
SPRAREA: Real (20.4)
SPRPERIMET: Real (20.4)
SPRCLASSE: String (32.0)

I get a similar error with a larger file

Failed to import some layers!

clas_226_67_20101012_pol: Feature write errors:
Creation error for features from #3600 to #3799. Provider errors was: 
SQLite error: constraint failed
SQL: INSERT INTO "clas_226_67_20101012_pol"("pk","geomm","sprarea","sprperimet","sprclasse") VALUES (NULL,GeomFromWKB(?, 4326),?,?,?)
Creation error for features from #3800 to #3999. Provider errors was: 
SQLite error: constraint failed
SQL: INSERT INTO "clas_226_67_20101012_pol"("pk","geomm","sprarea","sprperimet","sprclasse") VALUES (NULL,GeomFromWKB(?, 4326),?,?,?)
Creation error for features from #4000 to #4148. Provider errors was: 
SQLite error: constraint failed
SQL: INSERT INTO "clas_226_67_20101012_pol"("pk","geomm","sprarea","sprperimet","sprclasse") VALUES (NULL,GeomFromWKB(?, 4326),?,?,?)
Only 3600 of 4149 features written.

clas_226_67_20100724_pol.zip (114 KB) Etienne Tourigny, 2012-08-27 12:33 PM

Associated revisions

Revision 1bde6c58
Added by Giuseppe Sucameli almost 12 years ago

SL provider: convert geometries to multipart when necessary (fix #6257)

History

#1 Updated by Giovanni Manghi about 12 years ago

  • Operating System deleted (linux)
  • Assignee set to Giuseppe Sucameli

#2 Updated by Paolo Cavallini about 12 years ago

  • Target version set to Version 2.0.0

#3 Updated by Giuseppe Sucameli almost 12 years ago

  • Category changed from DB Manager to Data Provider/SpatiaLite
  • Status changed from Open to In Progress

The SL provider doesn't convert geometries to multipart when needed (i.e. when the layer has a multipart type).

Somehow related to #5547 because the problem usually occurs importing shapefiles.

#4 Updated by Giuseppe Sucameli almost 12 years ago

Giuseppe Sucameli wrote:

The SL provider doesn't convert geometries to multipart when needed (i.e. when the layer has a multipart type).

The AddGeometryColumn spatialite function adds triggers to check the geometry type and srid of new/changed geometries but the constraint fails trying to add a singlepart geometry to a spatial table with a multipart geometry type.

The ST_Multi function is available for SL >= 2.4.0, so we have to handle it to avoid to get a "no such function" error working on older DBs.

#5 Updated by Giuseppe Sucameli almost 12 years ago

  • Status changed from In Progress to Closed

Also available in: Atom PDF