Closed jumanbar closed 7 years ago
The request used in the code is aGeom.isGeosValid()
. Make your layer active and select all features, then in your Python console you could do something like:
>>> l = iface.activeLayer()
>>> for f in l.selectedFeatures():
... <space><space>if not f.geometry().isGeosValid():
... <space><space><space><space>print str(f.id())
should output you a list of feature ids that do not match isGeosValid()
for each <space>
hit on the space bar
I tried this, and after some big headaches, I finally got to a layer in which no line was printed after running your code. Now it works, but I discovered that I need to select the features around the gap for it to do it.
Just a small thing, but it bugged me for some time. It could be improved, I guess, with one of these options:
I tried this, and after some big headaches, I finally got to a layer in which no line was printed after running your code. Now it works, but I discovered that I need to select the features around the gap for it to do it.
Could you identify what is wrong with the features that my code lists? What kind of defect do they have?
Ask the user to select at least 2 features.
It's mentioned in the wiki that it is better to select the polygons around the gap, especially if there are many features in the layer. Two features might be too few, I am afraid; I cannot tell beforehand how many are around a certain gap, so I put it in the user's responsibility to select all necessary features.
Try to automatically guess which are the features around the gap.
that's done if you don't select any features (may take some time to run, though)
Here, an explanation of what the problem was with my layer (or, at least, what I think it was): http://imgur.com/a/Pe7iZ
As you can see, with 2 features it works all right, at least in some cases. Btw, in my layer it wasn't able to guess with was the gap without selecting the surrounding features (even though it took some time to try and do it, as it was evident from the noise from the CPU), hence my las comment here.
Hope it helps...
ok this is clearly an invalid geometry because for each line in a polygon on one side must be the outside. Any type of spatial processing will fail if the input contains invalid geometries.
Better to learn now than to keep being ignorant... Thanks for the help!
Btw, I think now that I can avoid this problem using the "Cut with polygon from another layer" (In fact, I just did with my toy example). It's a little cumbersome to have to use a different layer for this function, is there some limitation that makes it impossible to do the same thing with a feature (polygon) from the current layer?
cut erases everything in the active layer that falls beneath the features in cutting layer. Both can have a selection. If both are the same layer you will get an empty layer as a result. Try it by loading the layer a second time and selection the same feature(s) in both!
That works quite nicely :)
I made a small tutorial for using this method: http://imgur.com/a/kAtI1
On Thu, Sep 29, 2016 at 11:19 AM, Bernhard Ströbl notifications@github.com wrote:
cut erases everything in the active layer that falls beneath the features in cutting layer. Both can have a selection. If both are the same layer you will get an empty layer as a result. Try it by loading the layer a second time and selection the same feature(s) in both!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bstroebl/DigitizingTools/issues/18#issuecomment-250479610, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_eIHfZsj6V_OnZQwClugSRwTrODIDYks5qu8jagaJpZM4KI0cQ .
MSc. Juan M. Barreneche Sarasola
I made a small tutorial for using this method: http://imgur.com/a/kAtI1
nice! But your islands are gone, aren't they?
They are just unchecked so as to show that there are holes in the water polygon... maybe I should explicitly say that.
On Thu, Sep 29, 2016 at 12:48 PM, Bernhard Ströbl notifications@github.com wrote:
I made a small tutorial for using this method: http://imgur.com/a/kAtI1 nice! But your islands are gone, aren't they?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bstroebl/DigitizingTools/issues/18#issuecomment-250506259, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_eICePBlXYM7E39Ec8KILn1_NVZFJBks5qu92zgaJpZM4KI0cQ .
MSc. Juan M. Barreneche Sarasola
ah, my fault, you selected the water polygon, so they weren't cut
When trying this tool with my layer, it doesn't work because 'There are invalid geometries in layer X'. The problem is, I cannot find the geometry problems with the default QGIS tool (Vector > Geometry Tools > Check geometry validity).
Fixing errors with the Geometry Checker plugin (who did find some), didn't solve the problem.