An Absolute Beginner's Guide to Python GeoPandas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to this tutorial in this tutorial i'm going to explain to you the basic but extremely important things that you need to know to get started with jio pandas python library in order to work with geospatial data very efficiently now we're going to cover a wide array of topics all the way from teaching you how to install or how to configure the jio pandas library to performing geospatial operations and creating attractive plots of your geospatial data all within python using jio pandas library so without further ado let's get started with the tutorial all right so to get started i'm first going to show you how to install this jio pandas library using the anaconda prompt so i hope you guys have already installed the anaconda distribution and we are going to use the anaconda prompt to actually install this jio pandas library so i'm just going to type anaconda prompt here and right click and make sure that you run this as the administrator now even though jio pandas itself is just a single library for jio pandas to function properly it actually needs a certain set of other libraries as well we call them dependencies now some of the required dependencies for jio pandas are libraries such as numpy pandas shapely fiona and piperoch and also if you would like to plot things out you might have to install a separate library such as discard this so and one of the benefits of using conda to actually install jio pandas is that majority of these dependencies will automatically get installed without you having to actually worry about understanding what each of those dependencies might be and installing them separately by yourself so what we are going to do is we are going to simply say conda install jio pandas and simply hit enter and the command will run and this might actually take a while depending on your specific case depending on how fast it can download all these required packages and how fast it actually extracts all the packages so we are going to have to be patient just for a little while and once you get this prompt whether to proceed or not simply hit y to say that you would like to proceed and now as you can see it's actually downloading and extracting the required packages all right once it's done we are going to have to install one more library which is the descartes library which is going to be essential because we are going to do some plottings as well and this library is required for that so just go ahead and type pip install discard this and simply hit enter and that should be it so so first we used conda to install the geopandas package and after that we installed the discard package separately and that should be it we can simply go ahead and open up spider and check whether we manage to install jio pandas correctly or not so i'm going to close this one out and i'm going to open up spider just like this all right so what we can do is we can simply type import jio pandas over here and hit enter and as you can see we did not get any error or anything like that which indicates that we have successfully installed this library and if you would like to do a further check you can always say help and type the name of the package and it'll actually display the different contents of this of this package which further solidifies the fact that this package is already installed and it's ready to be used so speaking of the spyder ide you have your code editor down here you will see different panels you have the ipython console over here and you have a tab called variable explorer and you have a history tab help plots files so if you would like to navigate through different files you can actually come over here and click on these files and it'll allow you to sort of navigate through your files and folders and we'll also be quite frequently using this variables explorer because because all of the variables that we'll be specifying will actually get recorded somewhere over here so if you want to have a quick look at your variables you can simply come over here and you can actually explore your variables and see what sort of data are saved in each of those different variables and ipython console of course it's this interactive console where you can perform quick operations and every time when you run your script from this code editor your response will get displayed on this ipython console as well and we'll be using this ipython console quite frequently as well just to perform a quick checks of certain things all right guys so so first what i'm going to do is i'm going to navigate to the folder in which i have kept a couple of files that i'm going to use for this tutorial and also i'm going to create my python script inside that folder so that will be quite convenient to have everything at one place so what i'm going to do is i'm going to come over here to this files tab and you can use this icon of this folder to open up the select directory window and as you can see this introduction to jio pandas folder is actually the folder which i'm going to be working in so after i open up that folder i can simply say select that folder and over here you will be able to view the different contents which are stored in inside that folder now as you can see we have one folder called shape files and you can also go ahead and expand those and these are the things which we have inside this shapefiles folder we have a shape file called area of interest atms districts railway tracks so these are actual shape files well let me go ahead and open the same exact folder using windows explorer so you'll be able to see what sort of files we're actually dealing with so over here you can see that i'm using windows explorer to navigate into the same folder and these are the files that you can actually see this area of interest shape file this adm shape file this share file as well as this railway tracks shapefile so one of the obvious benefits of using jio pandas is actually you having the ability to import shape files and display them using python and we'll be discussing how to do so but before that i'm going to create a new script a new python script so all you have to do is just right click somewhere over here in this empty space inside this files tab and go to new and you can create a new python script from here and i'll be saving that inside this introduction to jio pandas folder as well so i think i'll just name this one as maybe intro to jio pandas dot py and i can go ahead and save it and now as you can see over here we have two file types one is a folder and one is this introduction to jio pandas or intro to jio pandas dot py python script all right so the very first thing that i'm going to do is i'm going to import joe pandas library now before we import that jio geopanas library using this console but to make it a permanent import whenever we run the script i'm going to import it from here using this editor so so i can say import jio but since i'll be frequently using this geopandas i'm going to avoid having to type geopandas all the time simply by importing this as gpd so whenever we want to call this geopandas library i'm just going to say gpt dot and whatever the function it actually serves depending on your specific need all right so the first thing that i'm going to do is i'm going to show you how to import or how to read in shape files using joe pandas and that's quite easy so let's go over to these files and open up the shape files folder and decide which shapefile we we are going to import for this specific case let's say i'm going to go with this districts.shp now the districts that you see over here actually the districts of northern ireland so i'm going to import this by creating a by creating a variable called districts so here it's going to be gpd dot read file and now i'm going to specify the exact path to this district's shape file which contains the districts of northern ireland so i'm going to specify the path over here but before that i would like to double click on the shapefiles folder so that now i'm exactly inside this shapefiles folder so i can simply copy this and paste it so what i'm going to do is i'm going to say r and i'm going to open up the quotes like this and i'm going to paste this path that i can see from here but i need to direct this to the exact shape file which i would like to open so in that case i'm going to say districts districts.shp and that should be it [Music] now to run this all you have to do is simply save the script and you can hit this run file or you can hit f5 as well i'm just going to click on this button and from here you can see that these two lines of code ran without any issue as you can see from here now we can actually do some inspections about the data that we just loaded in to get started you can actually use this ipython console first i'm going to say districts and now when i say districts now this is how the attributes actually look corresponding to this district's s3 shape file but you have to keep in mind that once you import this into python using jio pandas it's not considered as a shape file anymore but it's considered as jio pandas geodata frame now the way to check the type of your variable is simply you can type type and then you can enter the variable the name of the variable and when you hit enter you will see that the type is jio pandas geodata frame and just a second ago i told you guys that we can actually make use of this variables explorer to have a look at the different variables that we load in now in this case when i run the script you can see that the information pertaining to this particular shape file got loaded into a variable called districts and that jio pandas geodata frame is now getting displayed right over here you can even simply double click this one in order to open up this district's jio pandas geodata frame and from here you can see the different items the different districts of northern ireland and if you're actually new to geopandas of course you might be wondering what is this geometric column now this special geometry column is actually something which gets created when you import a vector file like an s3 shape file or a geo json file and it contains the information corresponding to the geometrical properties of each of these attribute so when you're working with joe panda's geodata frames just make sure that you don't delete this geometry column even by accident because that will cause for this to lose its geometrical properties which means it's not going to be a type of a spatial data anymore all right so i'm going to go ahead and close this one out and now we will see how we can actually plot this one out so that we can visually see the different districts in the form of a figure so for that you don't have to do anything much you can simply use the plot command so we can say districts dot plot and now if you run this command well in the newer versions of the spyder ide you will get this notification saying that the figures are actually getting plotted under this plots tab so if you go ahead and open this one up you can see that now this is how the different districts of northern ireland actually look so it's simply like opening up an estuary shape file using a gis software like qgis but over here we managed to actually plot that one out in python itself now there's a setting over here saying mute inline plotting and it's already activated by default so i'm going to deactivate that because every time when i run the script i do not want to actually come over here to these plots i would like to get the plot right over here in the ipython console itself so since i have unchecked this box i can come over here and if i run the script again you can see that now the image gets displayed right over here and you can use this plot command only because this district's variable is jio pandas geodata frame and there are a couple of arguments actually you can pass to change the appearance of your plot depending on your preferences now for example if you would like to have this plot in a different color other than blue you can specify the color like this you can say color equals let's say in this case i would like to have a red color plot and especially when you're using spider you can get these kinds of recommendations over here you can see what are the arguments that you can actually pass in and now if i say the color is equal to red and now if i run the script you can see that it appears in red color now let's say that if you would like to have the boundaries of each of these attributes marked in a black color line you can pass another argument called edge color and i'm going to say the edge color i would like to have it in black and now if i simply hit f5 you can see now the different attributes are sort of bordered between between each other using this black color boundary and from here you can easily distinguish between the different districts of northern ireland but let's say that if you would like to maybe have a unique color for different attributes depending on a different attribute value now if i go over here and open up this district's geopandas geodata frame you can see over here there's one column in my attributes table called district and over here you can see that it specified then it specifies the name of the district so let's say i would like to assign randomly a color based on the name of this district so in that case i'm going to get rid of this color and instead of color i'm going to pass an argument called cmap which is basically a shortened form for color map and let's say over here i'm going to pass an argument called jet now just in a second i'm going to explain to you guys where exactly i got this jet value from and over here i'm going to specify another argument called column and now i'm going to say that i would like to assign these values which correspond to this jet color map based on a specified column name now in this case if i again open up this district's jio pandas geodata frame you can see different values in here now when i say values it doesn't necessarily mean numerical values it can be text values as well so here the different values actually correspond to the different name of the of each of the districts so i'm going to say color my map based on the different values of this district column so here i'm going to specify by which column i would like to color this by the values of the district column now we will run this one and see how it looks and now you can see that depending on the different values of each of the districts it randomly assigned different colors now in case if there happens to be two districts which has the same name of course that's not the case but hypothetically if that was the case this assignment will assign the same color for those two districts because now we are saying that specify the colors based on the values of this district column but in this case just because all of the districts happen to have a unique name it gets a unique color as well so that's basically the difference of uh using just the color argument and using the cmap argument now i told you guys i'm going to explain to you guys how we got this jet value over here so to explain that i'm going to open up this page from the matplotlib documentation and even though we did not specifically import the matplotlib library i told you guys that jio pandas is actually built on top of certain libraries and matplotlib happens to be one of those libraries so that's where the plotting capabilities come from so that means we can actually use certain plotting capabilities of original matplotlib library inside jio pandas as well and if you scroll down over here by the way i'll put the link to this page down in the description below and over here you can see what sort of keywords that we can use in order to use different color schemes or color maps now the jet which i used is actually right over here so similarly you can see that there are other color schemes like turbo this brg now this hsv is also actually one of my favorites so but it looks quite similar to this jet color scheme so let's see if i want to use this hsv color scheme i can simply pass that keyword over here and if i run the script now you can see that it actually gets colored based on the based on this hsb color scheme so you guys can explore a bit more uh because i'll be providing you the link to that documentation page so you can actually test out different colors and see which one you like more so that's how to import an s3 shape file and how to plot it using jio pandas so i'm going to put a small heading over here or something like a keyword which lets you guys easily identify what each of these uh lines of code have been written for because later on i'm going to pass you guys this entire thing so you can even open up this entire script and if you want to run it in your own computer you can sort of get an idea what each of these different blocks of code mean so this one is importing an s3 shape file and plotting it using jio geopandas all right so let's go over here to these files and into my shape files folder and see what sort of other files i have over here which i can make use of now here you can see there's one shapefile called area of interest now you guys must be interested to know what this area of interest might specially mean when we consider the special extent of these different uh districts of of northern ireland you're not actually limited to importing just one s3 share file you can import as many s reshare files as you want so i'm going to to import this area of interest shapefile as well so i'm going to create a variable called area of area of interest and it's going to be similar to what i typed over here jpd.read file and [Music] just instead of saying districts it's going to be area of area of interest dot shp that's this file and after that i can again say area of will not pass any arguments for the time being and we'll simply run this one and see how it looks yeah now you can see that after after running the script it imported two shape files and recorded them in the form of geopandas geodata frames and those are districts and area of interest and similarly i asked the program to plot them as well so that's why you see two plots over here the first one is coming from this line of code and the second one is coming from this particular line of code and if you just have a look at the x and y coordinates or in this case latitude and longitude values you can kind of get the idea that it it's supposed to be in the same region more or less but we are still not so sure so now i'm going to teach you guys how to plot information from multiple files or even how to plot the information from the same file but with different representations side by side or one after another or how to plot information from different sources in the same map itself so first we'll see how to plot the figures side by side all right now to do this i'm going to actually import the matplotlib library because using the capabilities of matplotlib within jio pandas is kind of limited so if you want to make use of the advanced capabilities of of matplotlib library you cannot do that simply through the geopandas library you have to exclusively import the matlab lib library well what i'm going to import is import matplotlib dot pi plot s plt and over here i'm going to say figure and i'm going to declare two variables called axis one and axis two and i'm going to say that's going to be equal to plt dot subplots and over here you can see the types of arguments that we are able to pass now for this let's say i would like to plot the thing side by side so i'm going to say over here n calls equals to 2 and after that i can simply say again districts dot plot and over here i'm going to specify this argument ax and i'm going to make ax equal to ax1 over here and as a second figure i'm going to plot this area of interest dot plot and as the axis i'm going to make it equal to ax2 now without passing any more arguments let's first run this one and see how our result looks so i'm going to save this and simply run this and now you can see that the two diagrams or the two figures got plotted side by side just like this now of course there are certain things that we can actually do to make this more visually pleasing now the first thing that i'm going to do is i'm going to copy this entire thing i'm going to copy all of these arguments which i passed right over here into this let's say that i would like to change the color of my area of interest to be green in this case now i can simply plot this now i can simply save this and run and now you can see that all the changes that we specify over here will get applied into this figure now let's see if you would like to increase the size of the figure you can actually pass an argument over here called fig size and let's say i'm going to make this one 10 by 8 simply run this one if you're not really sure about these figures you can always test out and see which one suits you the best now over here you can see that the size of the figure actually got increased and side by side you can see first over here on the left side you have the districts and over here on the right side you have my area of interest but to me what's more interesting is that if i were to if i were to plot this area of interest layer on top of this district's layer so that i can see actually visually or specially what i mean by this area of interest now since i prepared these files for you guys i know already that my area of interest is most probably going to be some specified area which covers a certain number of districts but if you are the one who is actually receiving this this data for the first time and if you had no clue it would be very convenient to plot these two as different layers on top of each other and then you can sort of get a very clear idea what each of these layers actually mean and where it's supposed to be specially and how to do that is what we're going to see right now so this is actually how to plot the figure side by side so i'm going to create another section plotting multiple layers because in this case even though i'm going to demonstrate this using two layers it's actually not limited to two layers you can plot as many layers as you want without a limitation and by the way if you're wondering what happens if you happen to pass n rows over here instead of n columns we can actually simply test that round as well and i'm going to leave and rows to be equal to 2 and i'm not going to make any changes to the rest of the code and we can simply run this one and now you can see that it gets plotted one after another with the districts being on top and area of interest being on the bottom right here and similarly depending on your preference you can you can use both number of rows and columns together let's say if you would like to have a two by two representation then you can use number of rows to be two and the number of columns to be two so it's up to you guys to choose however you want to actually represent the figures so coming back to this plotting multiple layers so if you want to plot multiple layers i'm going to say figure and over here instead of saying access 1 and axis 2 i'm going to actually declare just one variable called access and over here i'm going to say plt dot subplots and i'm not going to specifically mention any number of rows or columns i'm just going to leave this one as it is and by default it assumes that in that case the number of rows and the columns are just 1 which means it's just going to be one single figure but of course you can pass the other arguments like this defining the figure size and that's not going to be an issue at all and i'm going to simply copy this and paste it over here and now just make sure that you're going to make this axis value equal to this axis right over here in that case both the values are going to be actually equal to the same axis because we are going to plot things on the same figure itself and i'm going to maybe comment this entire thing out because i do not want to actually repeat the plots again and again because we already discussed this part and now we'll run the script and see how it looks yeah and now you can see that the two things actually got plotted on top of each other and now you can see very clearly that especially where this area of interest is actually located at and it's covering this middle part of northern ireland covering a number of districts so similarly you can actually plot any number of layers on top of each other and just make sure that you maintain the order of the layers simply by by making sure that you stack the layers on top of each other as you come down on these different lines of code one more thing that i would like to do is i would like to see the extent of this area of interest but without having a fill color now in this case it would be good if i just had the edge color but if i did not have any fill color and we can simply do that as well by saying the color equals to none but we of course do pass one argument called edge color and that's going to be equal to well in this case i'm still going to go with black [Music] and now if i run the script you can see where exactly my area of interest is especially it's covering one two three four five six seven eight districts out of all the districts of northern ireland i guess you guys got the idea how to plot different things all together now i told you guys we are not actually limited to just two layers when it comes to plotting we can add as many layers as we want now if i go back to my files over here i might be able to find something else that can be that can be of of some use now over here you can see that i have another shape file called atms now let's try to see whether we can import this atm shapefile into a geopandas geodata frame and whether we can actually plot that on top of this figure so that we can visually see where those where each of those different atms are located at let me just go over here and add one more line of code which corresponds to the to the atms so i'm going to name this one as atms and of course i have to specify the correct file name in this case you can see the name of the file is atms.shp so that's going to be dot shp and after that i'm going to say atms dot plot well just to begin i'm not going to pass any arguments other than this specification of the axis because when you do this it'll actually get plotted as the topmost layer because it's the last line of code that you can see over here but regarding the appearance i'm not going to pass any any other arguments first i'm going to have a look at the figure itself and then later i can decide how i would like to change the things so i will run the script and now you can see that the location of the different atms actually appear as dots over here and you can even have a look at the attributes table of the different atms now you can see one column called operator well for most of the atms the name of the operator is not available but for some you can see that the name of the bank or the name of the operator and you can see that it's of multi-point geometry type so what you see over here is basically the xy coordinates of each of the points and of course you can change the color of the points to be let's say i'm going to specify them to be black and you can specify the size using this argument called marker size and let's put about 2.5 and see how it looks first yeah you can see that 2.5 makes it a bit too small so i'm going to maybe make it to be about 6. you sort of get the idea what i'm trying to do so in this case you can see that the points actually got plotted on top of this this figure let me go ahead and maybe increase this to about 14 not sure whether that would be too large or not yeah i think still it's all right all right so with that i'm going to wrap up the plotting part and now we are going to move on to a different part and that's how to change how to work with projections in jio pandas all right so the reason why you are able to plot these things accurately in a spatial sense is because it contains a define a predefined coordinate reference system if you are a bit of an experienced gis user simply by looking at these numbers over here on the x and y axis you might be able to get some sort of an idea about its coordinate reference system and in this case the coordinate reference system that all of these layers are using is basically the geographic coordinate reference system that's wgs1984 geographic coordinate reference system now how do you check that you can simply check that by specifying the name of the jio pandas your data frame in this case let's go go ahead and check the coordinate reference system of districts so we can simply use the ipython console to do those kind of quick checks i'm going to say districts and keep in mind that over here i'm referring to the district's jio pandas geodata frame if i say dot crs and if i press enter you can see that it doesn't really say what precisely my coordinate reference system is in in so many words but instead what it's giving you is this epsg code and this epsd code 4326 refer to geographic coordinate reference system wgs1984 now if you just go to google and type this out you can see that 4326 is just the epsg identifier of wgs1984 so similarly if i check the coordinate reference system of let's say my area of interest dot crs again you can see that it's the same coordinate reference system and it's the same for atms as well now especially when working with geospatial data quite often you'll find yourself in situations where you have to work with different coordinate reference systems depending on your needs now the easiest example that i can give you guys is that let's say if you want to calculate the areas of each of these different attributes and for most of our day-to-day usages we are calculating the areas in units such as meters or kilometers but if you were to calculate the areas while these layers are having a geographic coordinate reference system such as the wgs1984 you're going to get those computations in decimal degrees which is it is really going to be useful at all so first i'm going to show you how to reproject the coordinate reference system from one crs to another using jio pandas now i'm going to open up another subheading called reprojecting jio pandas geodata frames and to to demonstrate this to you guys i'm going to reproject this district's layer from eps g4326 which is wgs 1984 into a projected coordinate system which is quite frequently used for uk now the coordinate reference system which i'll be converting this into is going to be this epsg 32629 which is this utm zone 29 projected coordinate reference system so to do that conversion for the crs of these districts joe pandas geodata frame all we have to say is districts dot to crs and again keeping in mind that these districts is actually a geopandas geodata frame and over here all you have to do is specify the new ephd code and in my case it's going to be 32 629 and it'll know exactly to which coordinate reference system it needs to transform its crs into based on this given ephd code and of course i'm going to save this into a new variable called districts well in that case the the existing districts jio pandas jio data frame will get sort of replaced with this new transformed one so we can simply go ahead and run this here now as you will see the code got executed and now if i just do a quick plot of this district's geopandas geodata frame let me go ahead and run this again and right over here in the bottom you can see how it gets changed even visually when we change the the coordinate reference system because now it's using a projected coordinate reference system and the appearance of course it's going to be different and over here on the y and the x axis you can see that the coordinates are also actually now in in meters well let me go ahead and increase the figure size to be the same as this over here so what i'm going to do is i'm going to copy this and i'm going to rerun the script here i need to add one bracket and i will rerun the script here now you can see that this was the previous figure with the the crs being wgs 1984 geographic coordinate reference system and this is the figure after the district's layer was transformed into a projected coordinate reference system and over here you can see that in the x and y axis now the units are in meters as opposed to these decimal degrees that you see over here so that's basically how to transfer coordinate reference system from one crs to another using geopandas now you don't have to do this only for one layer let's say if i want to convert this area of interest layer into a projected coordinate reference system as well you can simply do that by saying area of interest dot 2 crs and similarly the eps g code is going to be 32 629 and let me go ahead and plot that one as well well i'm thinking i'll comment this one out as well because now we sort of got the idea of how to plot multiple layers together and now i'm going to plot these two reprojected layers together so i'm going to use this figure axis line from here and in the plot i'm going to make this axis to be equal to ax and over here as well all right in that case we will plot the area of interest and the districts on top of each other but in this case what we will be plotting is basically going to be the reprojected layers which are now in projected coordinate reference system well i think i can still retain the this individual settings when it comes to the appearance and over here i'm going to specify the fill color to be none and the edge color to be black for the area of interest as well and now we'll simply go ahead and run this yeah we seem to have an error yes of course this part it's supposed to be right over here yeah now we can simply go ahead and run and now you can see that in this new figure the area of interest and the districts are being plotted together in the same figure after the geopandas geodata frame layers have been converted into a projected coordinate reference system in the next part i'm going to show you guys one of the most frequently used geoprocessing operations that we do when we are working with special data and that's how to intersect two different layers so in this case as you might have guessed by now the two layers which i'm going to intersect are going to be this district's layer and my area of interest basically with the objective of knowing what are the different districts which fall inside my area of interest and you can simply do those kinds of job processing tasks quite simply by using geopandas alright so i'm going to open up a new heading over here saying intersecting layers the layer which gets generated after the intersection happens i'm going to name this one as districts in my area of interest a bit descriptive but i think since this is a beginner's tutorial we can still use these kind of long variable names just so that it will be clear for you guys and i'm going to say gpd dot overlay and over here i'm going to specify the two layers that i'm going to intersect so the first layer that i'm going to intersect is this district's layer and i'm going to intersect that with my area of interest and we simply have to specify how we need to do this overlay operation and over here even in the example that's being provided to us right now it says intersection so i'm going to simply go ahead and specify intersection we are not limited to just intersecting two layers there are so many other different geoprocessing tasks that we can actually do using jio pandas we have created an entire tutorial showing 10 extremely useful geoprocessing operations that we can do using joe pandas you can check the tutorial out as well but since this is a beginner's tutorial if you're actually a beginner to geopandas we recommend that you go through this tutorial first and after that you can actually have a look at that tutorial after afterwards so the things will be much more meaningful to you guys all right that's about it after that we can simply go ahead and say districts in aoi dot plot well i'll try to reduce the size of the figure in this case well actually it was not necessary to specify the figure size over here so i'm going to get rid of these two arguments and let me go ahead and maybe reduce the figure size just a little bit maybe put eight by six i'm not sure whether it'll be sufficient or not but we'll run the code and see how it looks now you can see that in the first figure we have the corresponding plot to this block of code we have the plot of this intersected districts within my area of interest just like this now if i pass the edge color to be let's say red in this case and if i run the script again yeah now you can see that these are the individual districts which happens to be included within my area of interest and you can see that now it results with the intersection of these two layers just like we anticipated and if you would like to have a look at the attributes of this districts in aoi you can simply use this ipython con console and from here you are able to see very clearly what sort of districts get intersected when we consider the special extent of our area of interest so you can see that it's only about yeah just about just eight districts which are included over here let's see if i'm interested to know the area of of the parts of these different districts which happens to be located within my area of interest and to perform those kind of geometrical calculations you can very conveniently use geopandas as well so that's going to be our next task how to calculate the areas using geopandas all right so i'm going to perform this for the intersected layer so i'm going to say districts in aoi now before i calculate the areas i would like to specify a new column to which i would like to record the area calculation so over here you can see that i have one column called district and i have another column called geometry now if you would like to make sure that you can simply say districts in aoy dot columns yes in this case we actually have another column which is the id as well now if you would like to use the variable explorer and if you open up these districts in aoi yeah from here you'll be able to see very clearly we have three columns district id and geometry what i'm going to do is i'm going to come back to this ipython console and i'm going to declare a new name for this job and a geodata frame in which i'll be storing the area values so i'm going to name that one as let's say area and to calculate that all you have to do is specify the name of the jio pandas geodata frame and simply say area and it'll create a dedicated column for area and it'll calculate the area of each of the different attributes now if i go ahead and run this script and now if i say districts in aoi.columns you will see that we have a new column over here called area as well and of course i can go back to my variables explorer and if i open up these districts in aoi and if you scroll to the right side you will see a new column called area and as you can see over here now the area has been calculated but if you are wondering about the units since we were working in utm coordinate reference system the units that you see over here are in square meters which might not be very convenient when it comes to certain cases so in this case let's say if you wanted to convert these units into square kilometers all you had to do was to divide this by 10 to the power 6 these districts in aoi dot area divided by 10 to the power 6 and after that we can run the script again and if i check the variables explorer and if i open up the districts in aoi and if i scroll to the right side you can now see that the area has been calculated in square kilometers just like this all right so i'm going to go ahead and close this one out all right guys so so far you understand the fact that we created these districts in aoi joe pandas geodata frame entirely in geopandas itself let's say if you wanted to export this into an s3 share file or maybe a geo json file so that you can simply share this with somebody else you can simply do that as well and it's not much of a hassle to actually export files into s3 shape files using joe pandas at all so let's say i'm going to put a heading call s3 shape files well in this case i'm going to export just one so into an s3 shape file so let's say i'm going to export these districts in aoi all i have to say is dot 2 file and right over here just specify the file path now in this case i would like to actually export this into the same place where i save my python script so in this case i'm i'm not going to enter the full file path so i'm going to specify the file name to be districts within aoi bit of a long file name and that's going to be dot shp because it's going to be an s3 shape file and i'm going to specify the driver to be equal to s3 shape file and i will run this and if i navigate back to my working folder and right over here you can see a shape file called districts within aoi which was the geopandas geodata frame which we converted into an h3shape file so just to demonstrate this to you guys i'm going to use a gis software like qjis so that i can simply open this one up show you guys that this is a legitimate s3 shape file so as you can see over here we have qgis i'm going to simply drag this one and drop it into my qgis interface and now you can see that the shape file is over here and i can open the attributes table and right over here you can see all the different attributes that we had as well we have the districts column we have the id column and also we have the area which we calculated within geopandas and later we exported that into an s3 shape file and you have the different areas of the different attributes over here just like this pretty cool isn't it so i'm going to get rid of this alright guys that brings us to the end of this tutorial i hope you guys learned something new especially if you were getting started with jio pandas if you were trying to take your very first steps in using the jio pandas library to get some actual work done using python and i really hope that this tutorial was helpful for you guys to take that initial step and of course if you would like to dive into more detailed geoprocessing functionalities of jio pandas i'm going to recommend this video to you guys which you can see on the top right corner do check that tutorial out and you'll be able to see 10 extremely useful geoprocessing operations that you can actually perform using geopandas to make your life easier when working with special data all right guys if you do have any questions or comments don't forget to add them down below and we'll get back to you guys as soon as possible so that's it for this tutorial guys thanks a lot for watching and i'll see you in the next one
Info
Channel: GeoDelta Labs
Views: 22,034
Rating: 4.9681907 out of 5
Keywords: geopandas python tutorial, introduction to geopandas, geopandas basics, geopandas python, geopandas latitude longitude, geopandas jupyter notebook, absolute begineers guide to geopandas, matplotlib python tutorial, geoprocessing, geodelta, geodelta labs, how to, geospatial data, gis programming, python geospatial visualization, python geospatial, python gis programming tutorial
Id: t7lliJXFt8w
Channel Id: undefined
Length: 48min 41sec (2921 seconds)
Published: Thu Nov 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.