4

I think I have a problem in understanding how the ‘Identify Features’ tool works in QGIS with a shapefile that might have some kind of error. I don’t know quite enough QGIS to be sure I’m asking this question the right way, so please bear with me while I try my best. The Shapefile I’m using can be downloaded from here: https://gis-countyofdane.opendata.arcgis.com/datasets/supervisor-districts-1/explore (and mirrored here: http://pages.cs.wisc.edu/~epaulson/Supervisor_Districts.zip )

I have a shapefile of 37 County Supervisor districts. I am using QGIS 3.20 on a Mac, and QGIS displays them just fine, but for a handful of them, I can’t select them using the ‘Identify Features’ tool - if I click on one of these problematic districts QGIS says ‘No features found at this position’. I can select any of those features by going to the Attribute Table for the layer and clicking on the row for any of the 37 districts. (The attached screenshot is when I tried to click on the most southwest district)

enter image description here

My first idea was to try and check for invalid geometry, so I used the ‘Check validity’ tool with the ‘GEOS’ option, and it identifies 5 districts/features that have problems and lists them in the ‘Invalid output’ layer, all on the eastern side of the county. However, one of the five features was one that I could click on with ‘Identify Features’ in the original data (DistrictNu 20, the district that is the northeast corner) and one of those features that I cannot click on with the ‘Identify features’ in the original layer is listed in the ‘Valid Output’ layer (DistrictNu 30, the district that is the southwest corner). So I’m not sure if there’s something going on with valid geometry or not.

enter image description here As a further test, I used the ‘Fix geometries’ tool, and that seemingly works for nearly everything - in the resulting ‘Fixed Geometries’ layer, I can now click on all of the features on the east side of the county with the ‘Identify Features’ tool, including the 4 that I couldn’t before as well as the 1 that I could click on in the original data but was included in the ‘Invalid Output’ layer from ‘Check Validity’. But now, DistrictNu 30 in the southwest corner is not drawn at all in the ‘Fixed Geometries’ layer. (It is included in the Attribute Table for the layer, I see all 37 districts in the table, but I only see 36 drawn, even if I zoom very far out so there’s no issue in anything being partially clipped) enter image description here

I’m at a loss to understand what problems this shapefile might have, so I’m not sure where to dig next. I’d like to be able to click on any of the 37 districts with the ‘Identify Features’ tool, but I don’t know how to modify/repair this shapefile so that I can. The other approaches that I’ve seen on blogposts and tutorial videos - using ‘Check Validity’ tool to find errors that I could manually correct, or the ‘Fix geometries’ tool to automatically repair any errors, don’t seem to get me to a shapefile where I can click on each of the 37 districts. Is there another tool in QGIS I should use, or is there something deeper wrong with the shapefile I’m trying to explore?

1 Answer 1

6

Try using the Grass tool v.clean from the processing toolbox to repair the geometries. This will create a total of 175 features so afterwards, run Collect geometries on the cleaned output and use 'DistrictNu' in the parameters as the unique ID field.

After running v.clean:

enter image description here

After running Collect geometries:

enter image description here

I didn't have much time when I posted the original answer above so I mainly focussed on finding a working solution. So here is some additional information and an extension of this answer following further query in comments:

In order to find and identify a variety of potential geometry errors and problems, here are some tips and methods.

Firstly, after you run the Check validity processing tool, the output layers are very helpful. The Error output point layer shows you the locations of the found errors. The attribute table also tells you the type of error for each point so if you view it on top of the Invalid output layer, you can zoom in and inspect the errors the tool has found (example below).

enter image description here

Secondly, to view the log information from the GRASS v.clean algorithm, just wait until it finishes running then switch from the parameters tab to the log tab (see image below).

enter image description here

Thirdly, another tool at your disposal is the Topology Checker plugin. This is a core plugin so just enable it from the plugin manager dialog:

enter image description here

Open the plugin and add one or more rules to check against:

enter image description here

Now click Validate All and see the results:

enter image description here

enter image description here

In this case, several features with invalid geometries are identified in the eastern districts region- the results appear very similar to those obtained with the Check Validity tool, but setting different rules can yield different results, so it can be worth experimenting.

As for the problematic south-western district, I'm not sure why it is not identified as invalid by either Check validity or Topology checker, but another method is simply to use the vertex tool. If you put the layer in edit mode, you can activate the vertex tool on the current layer or all layers.

enter image description here

Hovering over a polygon's edges will highlight its vertices. In the screenshot below, there are some suspicious looking interior vertices which warrant investigation.

enter image description here

Zooming in on this area reveals what looks like a non-valid, collapsed ring or similar (screenshot below). I simply deleted these vertices by clicking and hitting the delete button which seemed to fix the problem with this feature.

enter image description here

Another tip which sometimes comes in handy for fixing geometry problems is to use one of the buffer processing tools and apply either a 0 distance buffer or a very small positive or negative buffer. I tried this on the original Supervisor_Districts shapefile and found that it did not fix the south west feature, but after manually repairing that one, a very small negative buffer seemed to work quite well on the other invalid features.

The moral of the story: Sometimes it is necessary to use a 'multi-pronged' approach and utilize all tools at your disposal to find & fix these types of errors.

Finally, some links to related questions, tutorials/ blog posts:

Fixing geometry validity errors in QGIS 2?

https://www.qgistutorials.com/en/docs/3/handling_invalid_geometries.html

https://anitagraser.com/2017/08/29/fixing-invalid-polygon-geometries/

3
  • Thanks, that worked! Any ideas as to what was wrong with the geometry in D30, and how to discover/surface that error? The log from v.clean closes after running so I'm not sure how to see what it's saying. I'd like to better understand what the original problem. Commented Jul 9, 2021 at 0:32
  • 1
    @Erik Paulson, please see the (fairly extensive) edits to my answer which I hope will help with your follow up query. By the way, if my answer helped you to solve your problem, would you please consider accepting it by clicking on the check mark. Cheers. See: gis.stackexchange.com/help/someone-answers
    – Ben W
    Commented Jul 9, 2021 at 9:29
  • could you explain briefly how the buffer trick works with zero? I tried it and it saved me from a day's work :)
    – Faris
    Commented Nov 5, 2021 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.