QGIS: counting points in polygons

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
was a quick update to counting points in polygons in qgis so this changed relatively recently and one of the latest updates to queue just and the way you want to do this is you have two layers and first before I do anything I want to make sure they're in the same projection if they're not in the same projection or as you'll often see in QGIS CRS if they're not in the same one then counting points and polygons isn't going to work because the data is not actually lining up and an easy way to see that and the latest QGIS is you can hover over any layer name in the layers panel you can see the name and then in parentheses what the projection is so this one's in four three two six if I look at the city council districts this is in some kind of user projection I don't gonna trust that so I'm going to save this one in four three two six so do that before you do anything else just to be sure I'll call this city council just straight for three to six all right and I'm gonna make sure I pick the same one as the other layer if it's not here it is here because it's a commonly used one if it's not you can click here and find the right one okay once I have saved it into the right projection I'm going to delete the other one because I don't want to get confused by it okay so if possible get down to just the two layers that you're doing this with okay so there are two ways to do this I'll show you the hard way first the hard way is to go to vector data management tools join attributes by location so this is you're doing a spatial join and that spatial join is going to count the number of points in each polygon so the target vector layer is always the layer that you want the counts to end up on so I'm counting the number of points in each polygon I want the counts to end up on the polygons so whenever you're counting points in polygons this way this is always going to be your polygons and the join vector layer is the points so in this case these are super pickups from one day and 2014 by the way and I'm going to pick intersects so choose the uber pickups that intersect with each City Council District I'm going to skip the precision and I'm going to look at hit this so I want to take a summary of intersecting features which will include the count I'm going to get rid of the statistics although if you had interesting numeric columns you could do a sum or mean and so on to keep it simple I'm going to remove those and the joins table I want to keep all the records so if we look at our map there might be some city council districts with no I just messed it up with no pickups it looks like maybe this one in Staten Island has no pickups I want to include it anyway in the in the file that this makes okay so that's all that says keep all the records and I'm going to run I'm going to create a temporary layer for now and I'll run and this should take a second or two it shouldn't take too long but if it goes very fast like less than a second there's a chance that your projections are wrong all right so we see now in our layers panel we have three layers I'll turn off the other ones we can see just the joined layer and if I open the attribute table on that you should see there's a count column and it should be a numeric column and yeah should have the number of points in each polygon and to be certain I'm going to pick one of those and turn on my points and make sure that it makes sense so yes this one does have a lot of them so it has over two thousand let's look at one with two okay it's out here and I can visually see from here there are two perfect okay all right so if I wanted to keep that I would need to save as and save that as its own shape file I'm not going to do that right now I'm going to show you another way to do exactly what we just did it's a little bit simpler so I'm going to remove that from my layers panel and I'm going to go over to the processing tool box instead of what we did before so if you don't see the processing toolbox I can turn it off right now go up to the processing menu and turn on tool box and it will be a tab with the layer styling so they should both show up over here and what the processing toolbox is is it's an assortment of algorithms that you can use and I will often search in here if I'm trying to do something so let's say I'm counting points and polygons or if I'm looking for points in polygons this is a very common GIS operation so you see that there are actually multiple ways to do that here in QGIS and I'm just gonna pick the first one and if you double click on that it's going to open a dialog very similar to the one we just saw but it has fewer options and it's a little bit harder to get confused and you can see that instead of saying join vector layer and vector layer HSS polygons and points it looks like in this case at least it intelligently picked the polygons and the points for me it's lovely I can change the count field name to something like total or num pickups say and again I'll create a temporary layer you could save to a file here I'm just going to create a temporary one you see that happened a little bit faster too if I open up the attribute table it's still a numeric column it's the same exact results yep and now if I wanted to really quickly just do like graduated style based on what we just picked based on the count right either I'll go over the air styling make that a little bit bigger pick graduated instead of single symbol and my map this appears because I have no classes yet and for the column I'm going to pick that count column that I just made and I'm going to say do it by color I'll pick a color ramp I'm going to make it will start with an equal interval mode and hit classify and you'll see okay there's not much differentiation here in outside of Manhattan there is no differentiation so it's not giving us much information so I'm going to try some other ones often I feel like natural breaks is going to differentiate between the different features pretty well but definitely experiment with these and pick the one that works best for your map if you're having a hard time picking one that you think works well I recommend looking at the histogram feature I'll make it a little bit bigger so we can see it so what this is doing is its showing you number of council districts the frequency with which they have certain counts so there's only one council district with this many pickups there's only one here and you can see that those are these two so you can see these lines are the dividing lines between the buckets the classes that you just made for us so we can actually if we wanted to include more in the biggest bucket I can click here and drag it over and you can see that this one has now included here usually I wouldn't recommend tweaking things this way but it's an option to you and it at least gives you an idea of how frequently these numbers are coming up and you can see looking at this that the the fact that there are so many council districts down here it kind of makes sense because there that's just the most frequent class so it kind of makes sense that they're all yellowish okay and last thing I should note you'll probably want to save as on this temporary layer if I close Q just with this temporary layer I lose that forever so I will often if you look back at that counts in polygon count points and polygons I'll often start with a temporary layer until I'm sure that it's the one that I want and then I'll save that and that way you avoid getting so many temporary files on your in your file system clogging things up files that you no longer need so that's the quick way to count points poly points and polygons and Kjus and I hope it was helpful
Info
Channel: Eric Brelsford
Views: 18,547
Rating: undefined out of 5
Keywords: QGIS, maps, gis
Id: HzABVWGMCCA
Channel Id: undefined
Length: 10min 32sec (632 seconds)
Published: Fri Sep 22 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.