I need to append the shapefiles to a PostgreSQL database. Once the data gets appended to PostgreSQL, some topology errors like gaps & overlaps can be seen.

By using the v.clean tools the topology errors can be removed. However, as a result, it gives a separate shapefile ("cleaned").

So how can I remove the topology errors in the given table (test1) in PostgreSQL database?


  • Do you have access to PostGIS as well? – Taras Jan 10 '19 at 8:01
  • yes. I can access the PostGIS. – Prabhath Nishan Jan 10 '19 at 9:14
  • 1
    That's a very interesting question for me as well. From my experience, I could say that such errors can be eliminated only within some interactive program tool. Because no one can guarantee that some automatic procedure does what you want. – Vadym Jan 10 '19 at 9:26
  • 1
    I think you may confuse geometries errors (self-intersections etc.) which can be solved with ST_MakeValid() in PostGIS, and logical errors like gaps and overlaps as seen on your image, for which there is no magical function. – MaxPlank Jan 10 '19 at 10:25

You can fix the invalid geometries in PostGIS like that:

UPDATE test1 SET geom = ST_MakeValid(geom) 
WHERE ST_IsValid(geom) = FALSE;

Note that ST_MakeValid might result in some unwanted lower-dimension geometries ( for example your layer is of type MultiPolygon and you get some resulting Point geometries ), in which case your new geometry column type will GeometryCollection, so you might want to force the return of only one type; maybe MultiPolygon in your case:

update test1 set geom = st_multi(st_collectionextract(st_makevalid(geom),3))
where st_isvalid(geom) = false;

PS: Overlaps and gaps/holes are not invalid geometries, you need to decide yourself what to do with them. You can for instance fill or delete holes between polygons, and for overlaps, you can dissolve them, but this depends entirely on your data and purpose of the analysis.

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.