I am struggling to import the entire shapefile into PostGIS. I get an error that shows there is an error. What can I do to ensure that the entire shapefile is imported into PostGIS?

Error 6
Feature write errors:
Creation error for features from #-9223372036854775808 to #-9223372036854775808. Provider errors was: 
PostGIS error while adding features: ERROR:  Polygon must have at least four points in each ring

Stopping after 62216 errors
Only 62351 of 124567 features written.
  • 3
    You have invalid geometries in your shapefile. Polygon must have an area and as a minimum it is a triangle with vertices A-B-C-A. If your polygon has one vertex it is a point (A), with two or three vertices it is a linestring (A-B or A-B-A). With so many errors that you have there must have been something wrong in the process that created the data.
    – user30184
    Oct 4 at 8:58
  • Thanks. Do you know how I can fix these geometry errors in QGIS? Oct 4 at 9:08
  • 1
    You can't really. If a polygon has been degraded into a linestring the error has already happened. You can't know what was the original geometry. A poor workaround could be to buffer the geometries. Where did you get the data? Can you find the data provider and ask to send proper data?
    – user30184
    Oct 4 at 9:23
  • The problem could also be that the Polygons are not closed. A dirty fix could be to copy and add the first vertex to every linestring (e.g. Copy A so that A-B-C becomes A-B-C-A, etc.). Oct 4 at 10:31
  • There's tools in QGIS and in PostGIS to make geometries valid : postgis.net/workshops/postgis-intro/validity.html
    – GISHuman
    Oct 4 at 18:58

Your Answer

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

Browse other questions tagged or ask your own question.