Three ways of creating missing polygons from "holes" using QGIS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
for this screencast I'm going to talk about another problem which is quite common and boundary data we are dealing with and that is where you want to create an area I have a hole in existing boundary data because one of the boundaries is missing so I'm going to go through three different ways of doing this which might be appropriate in different situations so I'm going to start with a real example which is in the electoral Ward's of Kenya so this is a case where we got the data from the IEP capi which had a series of links to geo JSON files for each Ward and some of these links were four or four and these roughly corresponds to the holes you see in the map here so I've done some checking and I've worked out that this region here which I'm going to zoom in on this is actually a single board obviously when you have a whole you need to check you know what the hole should be in the data but I've done that so basically all I want to do is create a new polygon out of this hole that exactly matches it and insert it into the existing layer so to say well try three different ways of doing it one thing just a note for start is that like many okay so we're looking at the boundary data isn't brilliant here you can see there are these gaps between the edges of the polygons and the opposite problem with some of them they overlap as well so I first of all don't make this layer slightly different color because it's a bit close - it's a bit close to the color I've selected thanks okay so the first technique I'm going to try is to basically create a convex hull well so the first two when we look at both involve creating a larger region on top of this one in a new layer and then working out the difference between that layer and this one which should create a polygon which exactly matches that hole and there are two ways we're going to look at doing that the first is creating a convex hull of the areas around it and the second one is hand drawing a region which we know will include it so to start with a convex hull method if you go to the select options here and select feature is the one that just lets you click to select things so I'm ctrl-clicking to select all these areas are surrounded then in the vector menu and under geometry tool note geoprocessing tools there is a convex hull option so if I select that it'll create a convex region which completely encloses all the ones I had selected so as you might bet you can see what that looks like and turning on and off the visibility that layer you can see it's a def definitely includes a--'s foods are polygons so that's good so now to work out the difference between the two of them these are nine different layers we can use another tool from geoprocessing tools which is you see has various operations here that are kind of like set operations that are aware it depends on whether there is a polygon at a particular point in one layer in the next so in this case we want to use the difference one which is like subtracting one set of polygons from another so the complicated bit here you can see we've got the input layer and the difference layer it's working out which way round they go because it's an asymmetric so the input layer in this case this is the one that we are subtracting from so let's make that the convex hull and then the existing Ward's data are all the bits we're taking away so basically want to take away the wards that we have and just leave behind the the whole basically so if I run that hopefully I will do what we want okay so it looks pretty good so I'm gonna you know just hide the convex hull region and actually just makes less confusing I'm going to deselect all these regions in the other layer so don't do any more and actually I accidentally turn this on turned on editing for this layer earlier so I'm going to turn it off so now the difference area if I turn it on and off you can see that has various holes in the in the underlying region so actually this is done something I expected it's clear taking notice of which areas I still have selected and so it was only using them for the difference so do you have these extra bits around the edge there but I as a small irritation I don't think it's worth redoing the screencast for but anyway so as you see we even if we didn't have these extra large regions here they would still be extra little polygons from the difference created by the gaps between the layers so in any other case we'd want to do a little bit of too far we want to do a little bit of tidying up so to do that I'm going to turn off the Kenya Ward's one because it's obvious really which regions we want to get rid of and to do this I might do select features by freehand so here you can just kind of draw a region around oops and okay this shows another problem so in this case what we can see is that this is actually a single multi polygon it's a single feature that was created by the difference operation and what we really want is for these to be separate polygons so he can slide the ones around the outside and separately from this one so there is an operation to do that which it is again when these vector operations this time is on the geometry tools and it's multi parts to single parts so if we run that and make sure it's on the right layer run that on difference so you know hopefully we can select these bits individually yes that looks good okay so I'll go back to the freehand tool and kind of draw around some of these areas and just press delete to get rid of them but it wasn't me those layers not editable okay so hopefully now I can start removing some of these it says there are no selected features in this layer that's surprising it looks like that was because I had selected oh sorry I did actually delete those regions but they were from the difference layer not from the single parts layer so yeah I agreed to go confused to bag which is your active layer when you're doing this kind of thing so in that case because in that case the difference layer looks basically identical to the single parts layer which was the result of splitting it okay so I don't worry about it too much I might remove the difference in convex hull layers now to avoid that kind of confusion so I saw a few more of these regions we can get rid of by hand so if i zoom in a bit more just kind of the process of tidying up the data we generated let's see some more and edge here okay and now I'm going to zoom in just on this corner here and see what's going on there so this kind of a it looks like this is an artifact from the splitter at the edge there so this again these are two boundaries meeting here and here and whoops what we want actually is to just trim off that bit of the region so I'm going to do use the split features operation for this this basically allows you to draw a line from one point to another and split the features along that line so I click left click to start end the line and then right click to say were completed should that allow me to select this feature here and I can get rid of the other two more easily now okay so soo much a bit and see there any more of these stray areas yes it was one down here as well so I can use the same operation there again that's a split features easy to go confuse their various tool by things that have little scissors on but the one you want to split features which looks like it's cutting between two regions there so I'm going to do is terribly precisely else you know I'm assumin and do this by hand like that I think it was that but yeah it's just for example I'm not being too careful here so now I'll just check in the attribute table whether there are any extra feature so I hadn't noticed and it looks like yeah that's the big one but then there's one more which I can't immediately see so let's zoom zoom to selection to see where that is okay so that's another very small little polygon there so I'm just going to delete that again delete key [Music] okay so if I now turn back on I'll turn on the visibility of the Kenya Ward's layer you should see that this nicely fills in the hole that we have there and so now to merge that together you could use the datum under vector data management tools there's merge vector layers which is what I'd use to put that into the single layer again okay so that's the first way of creating a whole light of grating polygons out of the holes and existing boundary data so I think that's probably most useful where you have quite a lot of these holes and ideally where there aren't these kind of awkward gaps between adjacent polygons because then you can do a lot cradle off these holes in one go and effectively it's quite a simple operation one way which might have been better in this situation which I'll talk about no so I was going to remove that layer we just created somewhat painstakingly to show how we do it another way so the rule of the work we had to do though is just because the convex hull we created around it it wasn't a particularly precise didn't precisely fit the polygon we're creating there so another way of doing this would be just to hand draw something which we are pretty sure covers that but doesn't include too much kind of extraneous extraneous data so I'm going to do that by creating a new layer so when you created I will need a new shapefile layer and it's going to be a type polygon because we want to draw a polygon don't worry about what fields we want to know if I create like okay there yeah pops up although annoyingly popped under save dialog say if the save layer for you can work ions I so he'd say covering let's call some once I've done that let's make this new layer called covering for me and in order to create a new polygon in that layer and use the first total on editing and then go to this add feature option and here I'm going to zoom in a bit to get these corners right that's the one the Vantage of doing this is that you can be more you can deal at this stage with where you want this the slices of the edge to be so don't be too precise here I'm just going to take more care at the points we saw previously where we're meeting the kind of cracks at the edge of other polygons I'm actually it's going to turn off the earthly Streetman layer because that's making it slower to zoom okay and then right-click to finish that don't particularly mind what idea has in this case so effective that's doing something very similar to the convex hull except you know in an intent so we can undo the same steps after that's where we go to geoprocessing tools difference so the input layer is one we just created covering the difference layer there's a Kenya Ward's so if we run that I'll night remove the covering layer just so doesn't get confusing a now you can see we have a nice polygon filling that hole there and I'll just check the attribute table to see if we have any extraneous we don't have any extra little polygons created though so I think that looks pretty good I mean maybe you know one should check more carefully around it so the others there's like the old crack around the edge here which we could have dealt with by tracing the covering layer more carefully there or we could again use split feature to take off those bits night as well but basically for a single polygon that would be quite a bit quicker I think okay so I said there was a third way of doing this so again I'm going to go back to start remove the difference layer yeah let me just created so the other way is something I've talked about in another video which is to use the enable tracing option when you're creating a new polygon so this means that you can essentially create a polygon when you're adding a feature by following around the borders of other features which is a very powerful way of quickly creating new shape new polygon data so I'm going to start that by doing the same thing as before create a new layer you shape for a layer make sure it's a polygon and then again on hopefully if I creates that new save dialog underneath and so I'm going to call this one and see because we're directly creating it of course it doesn't really matter what this name is it's going to be a kind of throwaway layer and I I'm going to toggle that lead layer into editing mode I need to enable snapping so it does actually match the line you can start and end on points on the line easily snap to vertexes is all we'll need the tolerance I normally set this to within 20 pixels or seems about right for me and then the layer selection we want to find snap two lines in any visible layer so to I thought okay now we need to turn on this option here with the magnet in napal tracing and click that feature so as you can see if you go near these lines though it'll go near the vertex on these lines little pink cross appears which means you've snapped the line so I can click there and then as we move along it will trace along the edges of these lines so I don't go that far because then that would include this little sliver down the edge because it's following right around the edge of these polygons so I'm going to zoom in a bit and make the first point this vertex here jump to cross to see actually slightly annoying because it's when it snaps directly for that it was immediately jumping across the whole that we're trying to avoid so what be a way of doing that I think what I want to do is create a go to a point in midway between the two of them so I might just reduce the snapping depth because I can't even click in between them at the moment because it's nothing to precisely let's try that we're gonna point there turn back up the snapping so there might well be a smarter way of doing this but no problem we very often have so let me see if I go into here that line is just going back to the beginning of the polygon we're drawing so as we carry on the round there should be shouldn't be a problem right here again I'm gonna do a slightly hacky placing a new freehand point in the middle to make sure it doesn't fall around the gap there same thing here yeah so this means basic you don't have to worry very much about any of the points as you go along except those where there's this kind of crack into the next polygon so it's not actually stopping there's no vertex there to snap to so I'm just gonna create a point freehand here I wish I could turn on snapping to segments there that might be a better idea but this will do you as I say the precision of the binary data here is not such so this is going to be the worst bit of boundary data by any means okay so just one more bit to be careful of down here so this is the kind of place where you might want to look at the whole mystery map data underneath just to see if there's any kind of guidance about whether the lines might lie underneath so there are kind of some roads under there but I don't say not closely aligned enough that it gives us a good guide about where this these points should be so if I go back to this and add feature it keeps the tool active in a way so you can switch about it and it's try different things like that as you go along so I think they go right back for getting now and right click to finish that don't me to worry about an ad there okay so there we are and we have a nice new polygon let me save that toggle it out of noticing mode which again if we turn it on and off nicely fills the hole left by the other polygons okay so that's the third way of doing that and you know in each different case one of these methods might be quicker than the rest of them but hopefully that gives you a good idea and how you can go about filling in gaps and boundary data come up in situations like this so I hope that's been somewhat useful
Info
Channel: Mark Longair
Views: 6,874
Rating: 4.7777777 out of 5
Keywords: qgis
Id: B1zdMPQUaNQ
Channel Id: undefined
Length: 21min 45sec (1305 seconds)
Published: Fri Sep 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.