3

While trying to clip a layer with another polygon layer, I received the message that it contained invalid geometries. I used the Topology Checker tool under Vector/Topology Checker and it confirmed that there was a geometry error, but it only indicated which feature contained the error. It did not show what or where the error was. I tried using the Check Geometries tool under Vector/Geometry Tools and tried checking various options but could not find the error. One of the options kept crashing QGIS. I then tried the Check Validity tool under Vector/Geometry Tools (there were two Geometry Tools under Vector for some reason, and and it was under the 2nd Geometry Tools). When I ran it, it kept giving an error "-2147483645 See log for more detail" but this message was in the log so I don't know what it means. Here is a link to the shapefile: http://brucewiland.com/download/invalid_geometry.zip

Can anyone tell me what the invalid geometry is and if there is a better tool to find it?

Using QGIS 2.18.18

2

In QGIS 3.2. you have a tool called "fix geometries". You will not know where was the error, but it will fix it.

1

I had a similar issue last time. I used both mentioned tools but nothing worked. My solution was to import the shapefile into a postgis database and use the functions

ST_isValid(geom)

and

ST_IsValidReason(geom);

it helped me to find the reason.

1

That error is likely due to the shapefile being of geometry type wkbPolygon25D which you can see if you check the metadata by right-clicking the layer and going to Properties > Metadata. It would say something like:

Geometry type of the features in this layer

Polygon (WKB type: "PolygonZ")

If you type the following in the Python Console, you can see the same value which arises from the error log (which is probably stating without words that it cannot run the tool on geometries with a z-dimension):

from osgeo import ogr
ogr.wkbPolygon25D

>>> -2147483645

A simple fix is to re-save the layer as polygon layer without the z-dimension:

Save as polygon

The geometries should no longer contain any errors in the newly-saved shapefile.

1

I appreciate all of the suggestions. Re-saving without a z-dimension did not solve the problem. I did not try the postgis database suggestion because I was not sure how to do it. I decided I didn't need to know why the geometries were invalid, so I downloaded and installed QGIS 3.2 and used the "fix geometries" tool. Like magic it fixed the problem.

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.