Using Polygonize and the attribute table in QGIS to generate polygonal boundaries from linestrings

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay I thought I would record another podcast showing how to deal with a different type of boundary data this is kind of I guess in the middle level of level of difficulty it's not as awkward as the example where we had to manually trace the boundaries from disconnected line strings without external boundaries but the case we're looking at is that of Bayern and as an example these this data was divided up into different regions which I then kind of unified together at the end merged together at the end so I'm going to take a look just at over Bayern which is one of the regions of bone so opening that shapefile that we were supplied with that this is line string data I'll just zoom to that layer to get a reasonable view of it that's still quite difficult to see so I'm going to make the lines a bit darker and thicker we're going to do that in here okay so I'd know from looking at the map of on Wikipedia of what these areas should look like that this is looks basically reasonable and if I use the identify tool this one here to click on various of these features I can see that they are they do look like they describe they're basically lines that go all the way around the boundaries or each of these regions which is hopefully what we do what you don't see when I click on identify you can see in the left here that they actually have various IDs and so on the method we're gonna use wasn't known actually preserve these but in other cases this is very important that you have good IDs there and saves a lot of time because you don't have to add them manually so I say well we'll lose them in what we're gonna do here but another since that's quite useful so the tool we're going to use here because these look like pretty good complete boundaries is public and ice this is from the processing toolbox if that's not open you can get to that through processing toolbox it's in my recently used algorithms here but just to point out if you do just search for it in there there are actually two polygons eise's and you want the one which is under vector geometry tools so if I double click on that it's it gives me a variety of options the input layer it selected is the right one so that's okay there's an option to keep the table structure of the line layer so what this would do is to keep the fields which were defined on the original lines if you remember there were various IDs that were defined for each of those features it went you know it won't know how to map the IDS from the lines to the polygons as we'll create but it's sometimes useful to have the fields still there if you want to put them back I'm not going to bother about that here because we're going to do a separate screencast explaining how to add IDs anyway if I run this we get a new layer polygon some lines as result and again a quick clod so it looks like it's pretty good Thera no non-green errors in there for a start if i reordered these layers so the original lines are on top and click the visibility of that on and off we can see that it does look like there problems over each of them and another quick kind of by I check if we do select feature and click on each show so it's not selecting them because I haven't I need to select polygons some lines as the active layer in the layer panel though I click on each of those they basically look pretty good however this is quite a approximate way of seeing what's been generated so what I'm going to do to do a slightly more rigorous examinations data is to use the attribute table which lists all the features in this layer I'm going to hide the original line is for a bit we might need them later to refer to but at the moment it's kind of getting in the way so if I open the attribute table I think is a potentially rather confusing dialogue in so I'll just explain a little bit about what's going on here in the left-hand pane you have a list of all the features in the area so basically each polygon within the layer is a feature and what it lists here is that if you like then the name of the preview of each polygon is one of the values that it contains so each of these features after polygamy's it only has an area and a perimeter of value which is something that algorithm adds as I said if we selected that preserve table structure thing root have various other IDs here but with null values and so this list on the Left can be very helpful at the moment is showing area but you can change the column preview to show so parameter if you want but I'm going to do here is the display area and then use the sort by preview expression option so that we can see or the generated polygons in order of area from the very tiny ones to much larger ones now as you can see there's a lot more than the polygons so you can see by eye on the screen there and most them have a very small area if we go to say one of the ones which is about well I I haven't no this one is going to be about this more than we need to care or care about so I'll just click on this to select it yeah and this another computing the amount of this panel is there kind of two ways of selecting things if you just click on the value that changes the values you're displaying and editing and if you click in the left box that's selecting or deselecting the polygon in the in the normal QGIS sense of sliding a polygon so friends if I click these you can see they're very obviously that's poor but to maybe where I'm sitting in here so this one I just clicked on that's like a little island in the middle of a lake there which is disconnected and we'll look at which polygon that should really belong to later but the one below that isn't obviously visible so now I've selected that in a kind of curious sense I can use a zoom to selection to see where that is and have a look at it and as you can see this is basically a tiny sliver between two lines so this tells us that the original line string data for the borders doesn't actually exactly coincide at all the edges is pretty close but when you run polygamy's and it doesn't know how to interpret that and so you get lots of these little sliver polygons between the edges so i just to show that bit clearer my make this layer transparent so you can see the underlying OpenStreetMap tiles okay so I'm gonna say that in this instance I think probably everything of this kind of area and smaller is going to be unimportant to us let's go back to the previous zoom the zoom last option is actually surprisingly useful Oh No but not in this case closing date by hand a little bit yeah zoom last again and it moves me out again so if I bring back the attribute table basically what we decide here is that everything of this side or smaller we can delete this one is when we do want to keep though that's the little island there so basically anything which is less an area at naught point naught naught naught 3 not to leak so another curiosity about this attribute table is that you can control click to select multiple things but you can't shift click to select loads in a range so since they're quite a lot of these we can select them in a different way using this option select features using an expression and it has this this little kind of interface for building up these expressions which to be honest I'm not very familiar with but if you like if you double click on area there that loads in I think these look a little bit like SQL where expressions I think but I wouldn't like to switch that so in this case we make our expression naught point naught naught naught 3 and you select ok that looks like it's worked so it's just the tiny areas being selected though and if I now topple this edit layer into editing mode which I'm neither to you from there or in always on here but I think they're there same you can see when you go into editing mode each vertex is marked the Red Cross which is why it gives you appearance these from red fuzzy boundaries now that I've talked into editing mode this option has become enabled delete selected features so I can delete then all the those small areas so as if this does create a problem that there are tiny gaps between some of these areas in some cases so in other situations I might worry about that much more in this case however the quality of the boundaries is not so good that I think is even worth worrying about that because they do seem to be even be a little bit misaligned if you look in various cases on top of the OpenStreetMap tiles so in terms of kind of expediency I wasn't worrying too much about either those things because it'll work enough the vast majority of the cases but you know if you're being really careful you would want to go back and do that okay so at this stage it looks like we have a reasonable selection of polygons and probably the next thing I would want to do is to check some of these cases which requires is being a bit which increase you might notice or a bit strange and try and correct them so close the attribute table for the moment so to check this out I have a kind of a source of ground truth if you like for these this data this map of the various regions of Byron that we're looking at in this case I'm looking at over a barn which is this region here so two things that point out one is that if we zoom in you can probably see that in Munich in the middle there are actually multiple different regions within this central region here but in the polygons we have if I select this we just have a single region for Mueller so this is actually for us in a different data set I might just load that just to show you that we do have that data okay so you can probably see there that there is one of the other shapefiles does have the internal boundaries from unit but they're not in this data set note again and these don't exactly match up at the edges which is annoying but on the problems with getting data from kind of random sources okay so I'll remove that layer again but this that means that when we deal with the the Munich region individually then that will supply the polygons in there so it's not useful having this polygon so we're still in editing mode and I can use select feature to select Munich again need to make sure that's the active layer in order to select it and then if I press Delete on the keyboard that removes the Munich Chronicle of the polygon the other thing I want to take a quick look at was do you remember those little island in this region okay so it seems very likely this island is not a region in its own right but it's actually part of either this one or this one so again no that's kind of these boundaries are not perfect like this island some completely describes but so it goes so the area on the left and the area on the right no them have IDs yet but let's look on the the other map I had just to see which these regions that should belong to okay so if you can make this out of this region here the one called one two nine is a region kind of around there and the one to the west of it one to six is this region here and so our islands that we're worrying about is this one here and that has one two six written on it so it's clearly in Rosenheim Oster turns out this region is called so oh you can see if you zoom in a bit more in this map so sort of Rosenheim off Strada than try and stein so going back to QGIS if I select both of these features by clicking in one and control clicking in the other in this toolbar which one is that the advanced digitizing toolbar there is a merge selected features option so if I click that brings up this dialog which asks you basically how to merge the attributes of those features we don't really care about this in this instance we're not going to use the areas but you're not gonna use the areas of parameter values but you know you can make sure they were the sum of the two areas above or whatever so I'll click OK there and that's merged those two now so if I select this it's actually now this feature is now a multi polygon which includes the island okay so I think you know I would normally go through a bit more carefully and find if there any other odd cases like that just checking by I mostly but I think this looks about pretty good now so what I do know toggle off editing this is a kind of bug I've come across before could not commit changes to layer polygons from lines so you click on show more it gives you this error one feature not added geometry type it's not compatible with the current layer I think so I did you read out a bit about this this error and it seems like it is a bug I think where the current layers type isn't changed to accommodate the multi polygons we created so but a workaround for this seems to be to save it adds a shapefile so in this case I'll do just that my gums and I think to check when you're saving a shapefile is that for the data we're preparing for our partners in this case they always want it to be wgs84 coordinates so I changed the CRS the coordinate reference system to epsg for three to six wgs84 so i select that if i save it then that creates a new layer this one here but that will have saved it correctly so you can get rid of the the old Pali bottom lines layer okay so I think that's about it for this screencast I haven't discussed a highly how we set the IDs on these areas but I'm going to do that in a separate the full screencast so I hope that's been of some use
Info
Channel: Mark L
Views: 3,454
Rating: undefined out of 5
Keywords: qgis
Id: 9MDKFOa8lOQ
Channel Id: undefined
Length: 17min 4sec (1024 seconds)
Published: Tue Sep 26 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.