12 - QGIS 3.10 Tutorial - Flows and Network Visualization

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this tutorial i want to look a little bit at the possibility of depicting a network a social network in a qgis map it's pretty easy to do this in some off-the-shelf social network analysis programs including the online tool palladio but it was also possible to do this directly within qgis today i'm basically going to be following through a tutorial that anita grosser has made on her blog in this posting about flow maps and qgis no plugins needed you can find the instructions for doing everything that i'm going to demonstrate here directly on this web page but there are a few points in the blog entry that i thought were a little less than clear for beginning users of qgis i'm also going to be combining a few tips from another book that anita grosser co-edited called qgis map design in one of the chapters that's located there so what are we trying to do here let's start by taking a look at some data in this particular example i have some node and edge data that i would normally use in software for visualizing social networks in the nodes table which is the dots in a social network graph representing here by individuals and various attribute information about them and edge tables which shows relationships between individuals what i'd like to do is add some information in here about the locations that these individuals are in you can see that there is in the node table a column for location but none of these have latitudes and longitudes that are useful when we bring them into um qgis so what i did in a separate example was i went and looked up the latitudes and longitudes for a number of different locations and if i just copy these into a fresh example for us to demonstrate today i have then created a new sheet and called it locations and just pasted this data in here you can do this a whole bunch of different ways normally i just go into google maps i right click at the location roughly in the center of the city and i choose what's here and that will then show the information including the latitudes and the longitudes so once you've looked up the unique places that are mentioned in this table here it would then be useful to get the latitudes and the longitudes actually into this node table so i'm going to put in lat and long as two empty columns here i've shown in another tutorial how i used the lookup function to go from a situation where i had only the names of these individuals in an edge table to grabbing those ideas ids from another column i'm going to use the same principle here to grab the latitudes and longitudes in another sheet on the basis of this location so let's do that right now i put in equals and i'm going to use lookup what is it that i want to look up i want to know where is the latitudes and the longitudes or in this case just the latitude for tahu where am i going to find tegu well i'm going to find it in the a column and what is it that i want to return i want to return the data that's in the b column now for this to work one thing is really important this table has to be sorted as you can see it's currently an alphabetical list if it's not sorted you'll get a number but it'll be the incorrect number so if this worked correctly we would expect tegu to be at the latitude of 35.8501 let's check that tegu 35.8501 so that seems to be correct so i can now just drag this down and it should show the latitudes for all of these locations let's repeat the process now for longitude i'm going to look up the location just as before and oh i'm going to look up the location there you know what i'm just going to start fresh here all right look up the location it's important you put a comma afterwards and then i'm going to go here and where am i going to find that information i'm going to find it in the location column press comma again and what is the information that i would like to grab i would like to grab the longitude this time so i'm going to then put a closed parenthesis and if this is correct tegu should be at a longitude of 128.622 tegu 128.622 that seems to be correct and i can now just drag down like this so i've now added latitude and longitude data it is possible to do this inside of qgis as well but just as easy to get it done before you bring the data into qgis so i have the latitude longitude information that's equivalent to this particular location using the lookup command so this is my nodes data here i'm going to export that information as a utf-8 comma separated values this is my nodes table i'm going to save that in my screencast collection here for data i'm going to walk through all the warnings here because i'm i think it's worried about me destroying this format and then i also want to export the edge data which i'm also going to need to bring in to qgis i'm going to call this edges again a csv utf-8 save it as a csv file there and that's pretty much all we need to do in excel now we're back in qgis and it's time for us to import this data in i think the first thing i'm going to do just to have something in the background for us to work with is to bring in the natural earth data coastlines information and i know that all of my points are going to have to do with asia so one thing that i'd like to do is to uh i actually i can just leave it like this i think it'll be fine um you can project this in a number of different ways and the qgis map design book has a nice little instructions to get this looking like a globe so it's a little a little more curved here but that's a more advanced feature we can we can say for another tutorial i have a coastline now now let's bring in some of this table data that we were just playing with i'm going to import it as a csv i'm going to go find the file that i just exported out in my screencast folder here the nodes and this has point coordinates that are going to be grabbed from the latitude and the longitude it's a long way from the north pole to the south pole so that's the vertical lines the vertical lines will tell us how far we are to um the left or right so latitude so that x field is going to be the longitude and the y field is going to be the latitude and i'm going to leave it in wgs84 and that looks good so i'm going to press the add button if i close this now and if i just make this a black dot you can see that our points are showing up here uh and they're in fact uh multiple overlapping points because if we go into the attribute table insofar as we have more than one individual in a given city we'll have overlapping points this is something to keep in mind if you try to visualize any kind of network is overlapping points means that when you get relationships between individuals in different places how are you going to be able to make it clear that this is coming from and connecting to different nodes something to keep in mind now let's bring in the other table our edges and our edges has no geometry data there's no uh information in here that suggests uh anything other than our from and the two in terms of the person however it does have the id number id from and id2 which is something we're going to use so we have a table without geometry and we have geometry that is to say latitudes and longitudes in the node table here now the next state stage comes from anita grosser's tutorial she says the way for us to get from a an edges table in a nodes table is to create something called a virtual layer so let's walk through the step that she's describing here i'm going to follow her instructions by going up to add layer add or edit virtual layer and here's the query box where she has that text i'm just going to bring it in from here this was the text that she used in her example but i'm going to have to make a few changes here these are the titles of things in her uh example and we need to use the things that are in our edges table if i open this up here you can see the titles of the the columns there let's leave that open as we as we play with the virtual layer here i don't have a start id i have an id from i don't have a desk id i have an id2 and i also like in her example have a number of other things i want to bring in i want to bring in kind intensity year start and year end and i'm not going to include the from into these are actually keywords in sql and i'm a little worried that if i bring those in they may cause some problems make it'll now make a line uh from the from point to the two point and this is from the edges table and it's going to join it to information from the nodes table and i need to again replace this edges dot id from and i need to update this to be what i have which is id2 and just to see if this looks like it's looking okay i'm going to test it and it says no error that's a good sign and if i add this and close we can now see it has created a bunch of lines between these different locations now as uh as anita grosser points out in her blog these lines are not terribly attractive curved lines would be a lot better so we're going to continue following her suggestion here she points out that if you make these lines into lines with arrows you'll end up with curves but we need to have lines with at least i think she said three points in them so what she suggests is that we um basically go in and uh change this such that we add a geometry generator and we're not dealing with polygons here we're dealing with lines and the geometry generator will allow us to use all of the toolbox of commands and variables that are available to us in in qgis i'm going to be copying and then modifying slightly her code she divides it into two parts so that you can see what's going on in the first she shows uh that by just doing this you'll end up with lines that have a kind of a division in the middle of it um so she adds more code uh that uh will set things up nicely once we change things to um uh to uh the arrow approach okay when i click the apply button you'll see here is that a straight line with multiple divisions in it i'm going to get rid of the original simple line that was there and here's the cool part if you change this to arrow and press apply now suddenly we have curves and the curves are controlled in part by the code that was put in here notice for example what happens when i change this number to a nine if i change this to a number closer to zero you end up with really big curves it is for this purpose that um i made a small modification here i wanted to change it so that i could get a little bit more variety in the curves especially because we've got multiple lines connecting the same two nodes since i have a column of intensity data in here in the edges if you look in the attribute table you can see i have an intensity column which goes from 1 to five and in order to create a little bit more of a variety in the curvature of the lines i replace this negative five with a negative six plus the intensity which will vary from 1 to 5 divided by 1.3 and i ended up with something that gives you a little bit more variety in in the different types of lines uh furthermore uh when you go down to styling the arrow itself uh under arrow width i um i'll do that next but under offset which is to say how much do you offset the line from the normal path it might otherwise take you can fix the number for all of them by putting it here but you can enter in a variable or kind of a formula in here and here again i add a little bit of randomness using a random function where it chooses a number between 1 and 400 and multiplies this by 0.01 and this will this will give us a number between one and four of various denominations uh uh such as 2.25 here is one example 3.75 is another one that's produced and if i click apply again you'll see that the number of lines has proliferated a little bit if you don't like that and you liked having all of the lines completely overlapped then obviously don't add that in and just get rid of that again let's clear it and apply um and i'm gonna add it back in again uh you know you can play with the the functions to get the kind of variation that you think works well and then in order to further differentiate between some of these lines i also added some variation to the width of the line in this case the entire arrow including its stem are handled by this arrow width here i used something called the assistant down at the bottom here choosing that i mapped this variable to the intensity which as you remember was a number from zero to sorry one to five you can load that from here and it shows it's loaded the numbers one to five which it found in the in the data itself and we want to translate that into output sizes that is to say the width of the line currently i think they're set to 0.6 so something a little bit thinner 0.3 say and scale that up to 1.5 say so the visual effect is not huge but it does add a little bit more of a variety to to the output if you find that you have too many points and things start getting too busy then you may not want to add this kind of uh level of variety to your your your chart but i just wanted to show you how it's done at the very least again um the color is currently set to be all blue but what if we were to map the color of the the edges to match the kind of relationship i've got three different kinds in one column so let's map this to kind again using the assistant and there are actually only three possibilities three discrete possibilities and unfortunately it says here that it will end up with all of these different colors when in fact there's just a one a two and a three um one way we can fix that is by reducing the number of different possible gradient stops so for example if i delete this stop and i delete that stop i delete this one and i delete that one i delete this one and i say discrete okay in fact let's delete one more we now end up with three colors uh located at different sides you can mess with this so that it comes out properly and at any rate we end up with three possible colors now this would require a little bit more fiddling but just to show you what it looks like quickly is now you'll see that the colors give an immediate indication of the kind of relationship that could obviously be mapped to any of your variables as you see fit why don't we add some labels to this let's go switch to our node table and i'm going to put that above the virtual table so that the nodes are nice and clear i'm going to switch on the labels i'm doing all of this in the layer styling panel here you could also do it by going into the properties of the layer single labels and let's label it with the name of the purse sorry not the name of the person the name of the location uh i'm going to up the font up a little bit i'm going to switch to something different for the font and let's see how that looks okay i want to increase the readability so let's draw a buffer and now we're beginning to see a little bit more the possibilities of visualizing a network in qgis to be honest i don't think that this is a very readable uh visualization um i'm showing this for the purpose of uh those of you who might have let's say a smaller number of key points or relationships or you can have a level of zoom where the lines come out in a much larger variety but the main point is it's possible to visualize networks natively in qgis using this kind of method now anita grosser's demonstration is about flows in different directions she styles it here so that when it goes in one direction when there's a directional network uh it shows you one color and when it goes in the other way it's another color that would be really nice for immigration flows for example um but if it's immigration flows then it's networks uh a relationship between not a person and soul and a person in tokyo but um the relationship is between seoul and tokyo itself and then the edge column that would be styling that line between seoul and tokyo would be the amount of the flow let's say the number of people who have moved from one place to another that will allow you to have a much simpler map well can you do that with people as well i think so i think if you were to aggregate the relationships between the cities say everyone who if there's let's say five people in guangzhou who have a relationship with somebody in shanghai then if we had a way and excel again is probably the place to do this if you have a way to aggregate the total number of uh unique combinations of locations then uh you know you count up the total number of dalian to guangzhou relationships then it'll become like the example of migration flows between them but that's something we can explore in another tutorial
Info
Channel: Fool's Workshop
Views: 4,713
Rating: undefined out of 5
Keywords: QGIS, social networks, flows
Id: gXp0FJAkql0
Channel Id: undefined
Length: 25min 21sec (1521 seconds)
Published: Sat Oct 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.