Invalid Geometry and QGIS

Dec 2, 2013 | GDAL, GPS, GRASS, QGIS

If you ever get bored one year – make the decision to do all of your editing in an open source GIS package.

I’m working on a project that I’ve let get a bit out of hand by not being the annoying GIS guy. I’m at the 80% cleanup mark though and that makes me feel better than I felt a few weeks ago when I surveyed the damage.

This project had a lot of interesting things occurring.

  • Pulling data out of very old shapefiles.
  • Modifying it with NAIP and whatever imagery I could find that was useful.
  • Modifying it with GPS tracks and waypoints collected in the field.
  • Course changes from the client with regards to the deliverable.

This  led to a lot of issues in my file based geodatabase. In some cases I fixed these in ArcGIS using the Repair geometry tool and in some cases I didn’t – I was in too big of a hurry and would use that time honored phrase of “I’ll do this later”.

Well – later is here and I’ve committed myself to fixing all of this in QGIS, GDAL, and now GRASS. I’m moving from File Based Geodatabases to shapefile with the goal of PostGIS. Tonight’s discovery was a bit unexpected. Some polygons in my data layer refused to “act right” when I was editing them (they refused to be edited with the cut polygons tool). It took a few tries to finally realize QGIS wasn’t allowing me to edit data with invalid geometry. There are a couple of tools that ended helping me to fix this. The first was the invalid geometry tool – it will actually save the problems out as points so you can visit them one by one. My favorite ended up being the new topology checker.

topologyThat beautiful pile of red is my invalid polygon(s). Invalid geometry abounds and the biggest issue ended up being self intersection. It was crossing back over itself – and how I managed that I had no clue. Nine problems in total for this one. More problems on others. I did a bit of digging and found that the kind people over at Faunalia had run into the same problem.

So here is what I did:

  1. I pulled the offending polygon out of my file and saved it to a new shapefile.
  2. QGIS and GRASS are connected through a toolbar and I can fairly easily create a new mapset in GRASS and import a shapefile. Why? Topology. GRASS has topology built into it’s 30 year old core. I have some options in fixing my data. I can set snapping and minimum areas to import.

grassimport3. I import it and run topology in QGIS and see how I did. I ended up doing a couple of imports playing with options until I was down to one error – a self intersect. I ran the check geometry tool and found it and fixed it. I did one more import into and out of GRASS just to make sure.

Once I have it fixed I copy and paste it back into my original data set. Everything works. I continued my edits. I did find a few issues where my data had moved just a bit (considering I was snapping and setting minimum import areas I’m not surprised at all). I had some gaps – but those were found by the topology tool and fixed.

So why this way? Well because I can. It’s completely doable with a little bit of work. For those of you with stretched budgets and data issues – there are tools that are readily available to fix your data. After all – it’s all about your data. I will eventually write this up into some sort of tutorial someone can follow and it gets possibly included in the QGIS Class Part II. Hopefully – but for now it’s time for some sleep. Next it’s time to get this out of shapefiles and into something a bit more powerful – postgis.

You may also like

The Trail Map – Part 1

The Trail Map – Part 1

A few posts ago I babbled about cartography. I've never had the patience for Cartography mainly because two things usually happen...well three things: the map can't be bigger than 8x11 the map must have everything on it Make the map however you want except we will...

My So called Life as a Map Maker

My So called Life as a Map Maker

I can sum it up: It's not much of one. Way back in my younger days I was infatuated with ArcPlot (which was the plotting portion of ArcINFO). From there I moved to Arcview, ArcMap, and eventually here to QGIS. All of my work typically revolves around Data. I usually...

Tricks with an ESRI File Geodatabase

Tricks with an ESRI File Geodatabase

A few years back I jumped in way over my head with QGIS/Postgis. I had moved a process out of one software and into my favorite two (QGIS/PostGIS) and little did I know the final output had to be a ESRI File Geodatabase. So what did I do? I shamed them into using a...