bstroebl / DigitizingTools

A QGIS plugin, that subsumes different tools useful during digitizing sessions
GNU General Public License v2.0
22 stars 9 forks source link

Fill Gap complains about unidentifiable invalid geometries #18

Closed jumanbar closed 7 years ago

jumanbar commented 7 years ago

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.

System: Ubuntu 16.04

QGIS version               2.14.5-Essen      QGIS code branch          Release 2.14
Compiled against           Qt 4.8.7          Running against Qt        4.8.7
Compiled against GDAL/OGR  1.11.3            Running against GDAL/OGR  1.11.3
Compiled against GEOS      3.5.0-CAPI-1.9.0  Running against GEOS      3.5.0-CAPI-1.9.0 r4084
PostgreSQL Client Version  9.5.2             SpatiaLite Version        4.3.0a
QWT Version                5.2.3             PROJ.4 Version            492
QScintilla2 Version        2.9.1
bstroebl commented 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

jumanbar commented 7 years ago

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:

bstroebl commented 7 years ago

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)

jumanbar commented 7 years ago

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...

bstroebl commented 7 years ago

http://imgur.com/a/Pe7iZ

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.

jumanbar commented 7 years ago

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?

bstroebl commented 7 years ago

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!

jumanbar commented 7 years ago

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

bstroebl commented 7 years ago

I made a small tutorial for using this method: http://imgur.com/a/kAtI1

nice! But your islands are gone, aren't they?

jumanbar commented 7 years ago

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

bstroebl commented 7 years ago

ah, my fault, you selected the water polygon, so they weren't cut