Python for Geospatial Data Analysis | Alemayehu Midekisa | Skillshare

Python for Geospatial Data Analysis

Alemayehu Midekisa, Geospatial Data Scientist

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
4 Lessons (40m)
    • 1. 1 DownloadAnaconda Final

    • 2. 2 PlottingMatplotlib Final

    • 3. 5 DEMData Final

    • 4. 9 MapProjections Final


About This Class

This Python for beginner course will get you up and running with using Python for data analysis and visualization. You will learn how to download and access a Jupyter Notebook environment. You will have sample Python scripts and example data so that you will get a chance to practice manipulating GIS data. Additionally, you will get HD videos to guide you through out the course.

The course assumes you have no prior knowledge of Python, so you also get to learn the basics of Python in the first two sections of the course. However, if you already know Python, the first two sections can serve as a refresher before you jump into the data analysis and visualization part. In the course, you will learn how to install conda and various libraries that are necessary for geospatial data analysis such as basemap, geopandas, pandas, matplotlib, and seaborn. We will also use the popular open source tool, the Jupyter Notebook.

You will learn how to integrate different spatial libraries within your Python code. We will walk you step by step to apply various Python packages to manipulate GIS data, visualize geospatial data to get better insights. I will provide you with all the data that I demonstrate in the course. By the end of this course, you will be able to download Jupyter Notebook, install conda, and perform various spatial analysis including manipulating, aggregating, and visualizing GIS datasets using Python.


1. 1 DownloadAnaconda Final: pie. Welcome to this lecture. In this lecture we'll show you how you can access in download Deep Iten, the latest Piketon version 3.7 for this course and I will show you how you can download it using the anaconda um, platform. So let's get started. OK, First, let's just look at what the latest fightin is available. Um e think it's piped in 3.7 and let's go to the main pipe and website. Here's the main pipeline website. So that's the latest version pipe and 3.7 eso. This course will be based on, you know, pie tense. Very specifically. Brighton 3.7, you can download the you know, the pie 10 version and Jupiter not poke. But I think what I prefer is just, um, to download the anaconda, um, the anaconda platform, uh, and install it on their own. Your machine and the beauty of you know Anaconda is it provides you. It installs automatically python. And it also provides you Voris, you know, data visualization and analysis tools like the Jupiter not book and the sea born. Ah, and what have you Right. So let's go to the Anaconda website It's just that in another side, and I corned, uh, I think it's here. Anaconda Joko. So here anaconda dot com I mean, the way the man website here. So why you do is just you find the down wants, you know, button on the top, right corner here. So go ahead and click downloads, and it will take me to the download page. So, um, at downloading the anaconda package, um, platform? Rather. So what is the latest version off the anaconda that we have? So it's Anaconda five point Street, you know, for windows in Stoller. So if you have a Mac, you can check this version Anaconda 5.3 for Mac installers. And if you have ah Lin X mission, you can check this and according a 5.3 for Atlantic. So So Anna, conduct comes for all of this. You know, the three operating systems for Windows Mac and Linux. You know, in my kids, I have a windows machine, so just go ahead and down the windows version. But if you have like if you're working on a Mac operating system or leanings, you can, you know, do so right. Just choose the you know your own, Um um version if its Windows Mac or Lennox. Okay, so for now, since I have Windows operating system, I'll just click the Windows version. It's, you know, dark block. That's when I selected. And also, it shows you here, you know, for Windows versions. So this is the latest Anaconda, and the other thing that you have to know is you It will provide two options off pint in Piketon 2.7 version in Piketon 3.7. So this course is based on the latest fightin pied Ansari specifically pipe and 3.7. So I'll just go ahead and download this latest version of fightin. And you can also choose here. If you're operating system has a 64 beat or 30 forbid you can, you know, choose. So so in my case, I have a 64 bit operating system, so I'll just click on download the 64 you know, Python and the anaconda was the fighting 3.7 version. All right. And as you can see here, Anaconda is downloading. Once this blue circle is complete, my doll. ODIs done. Then I can go ahead and look at that in the down. Launch the download option. Let me go down a lot. Okay. Here. So Anaconda here is just, you know, downloaded here. 64 bit. 3.5. Sorry. 5.3 version. So for you, you know, go ahead and double Click this and you will out to medically start installing Anaconda in your machine. Right? But because I already have installed Anaconda, let's just go ahead and start opening the Anaconda navigator. Right? So here's just a green, you know, uh, logo or I can hear. So, Anaconda Navigator if I click that, um, the anaconda window, you know, pops up, right? It's just you have to wear a little bit of fixed time to come figure and just Lord, um OK, so So my anna let me just minimize this. Okay, So this is the my anaconda. Um, you know, Navigator, right? So as you can see here, you know, the anaconda navigator has various tools, including, you know, the Jupiter lab and in Jupiter, not books. This is the main, uh, plot firm where we will take You know, this course this is a Jupiter, not book. Where will do you? No pipe and quoting Inter actively, right. You know, so we'll use this one before now. Let's just go ahead and check the other so the, you know, the, um I pie and then the spider and glue Visa arranged three. And then our studio, which is a popular data science, you know, open source tool. The escort. So you have Anaconda comes with, you know, various applications. So in our kids, we're going to use the Jupiter or not book. So let's initiate a Jupiter nup like lounge a Jupiter notebook. This is one approach. Have you can't open a Jupiter, not book, right? And then I'll show you another way off initiating a Jupiter notebook. So, python geospatial. This is my course, um, you know, directory on. It will just take me to directly to, you know, the court. Right? So this is, you know, technically an interactive way off Marina riding a pie, tennis craved and just looking at your results and looking at your maps and plots, which is pretty cool. And then you can also see that this is a pipe conversion here. Asi conceits Python three. Right. And we can you know you can save your file s Oh, this is just that the court, like a pint and notebook, and then you can add sales here. You can cut here. You couldn't run. Uh, so it's it's pretty handy. And so So let's up. You know, let's just look at it another way off installing a Jupiter notebook like this. Same thing, right? Let me close this. Okay, let me close the anaconda window. The python window. So and And let me closed the anaconda navigator. So without going Mama Lee to the anaconda navigator, you can open the Jupiter, not book just programmatically by using, um um, a console. Yes. All right. So because I already have an icon installed, then I can open the anaconda prompt. Here, you can see here it's block. So justify. Click that, um and, um, the center on according a problem. So any time you want, you know, to write, install, um, ongoing They like package. Like you known empire Pandas. And what have you This is like, how you can write, you know, Ah called installation, quoting, despondent. And then he will. It will down, but even toe open a jupiter, not book. I can do that. here. So what I'll do is just right. Jupiter notebook. And then if I hit it will automatically open a Jupiter, not book. Same thing that have been mounted, Lee, Right. That's pretty cool. So every time you want to open, um, you know, Jupiter not pull. You can just write it here, programmatically. So that's all to, um, what I have to, um, you know, show you how you can download Piketon wisdom, and I call in the navigator. And then once you have Anaconda Navigator, you can initiate a Jupiter, not book to start, You know you're calling exercise, all right? 2. 2 PlottingMatplotlib Final: hi will come to this lecture and this lecture will be installing the Jupiter, not book initiating a Jupiter, not book using, um, cut prompter. And we will, um, do some exercise on my plot lead to do, you know, basic graph. Um, and let's first start. So the first thing you do to start and not book is just you can definitely used the anaconda. Um, you know, navigator, just if you want to do it mentally and, um wants the anaconda, um, navigator Inish, it's you can lounge a Jupiter, not book. Okay, so that's kind of a mono away elf doing that. And so Anaconda is just configuring and in shedding. So once you have the Anaconda navigator, you just lounge Jupiter, not book, right? And then you just go to the the folder that you have your old, um, you know, scripts. I mean, you can you can, you know, save it in a different location if you want to. So let's get started. Was the first, um, you know, quote Piketon coat that we have. So So the first thing is, this is just in an exercise where we will do some demonstration on on how to plod is he might plot live, right? And so So this is kind of a new interactive, you know, platform to quote. You know, Piketon, you can create new sales. For example, here. If I just create new sale, it will open. And also, you know, if you want to write a court, like, for example, import, Um, hand us something like that. So this is just the court, right? If you want to, like, write a note, you can change here. Like from accord to a marked down. And you can say, like, this is my crotch, right? And then if you clean, it's not running. So it's just a text file. So you can change that here and then if you want to, like, move this sell, you can just move it up and down. If I want to move it down, I can do that. Um, and I can you know, they did that. Just delete that. Even I can dilly the entire cell like I can cut that in distillate. So it's a pretty cool, interactive platform for coating. So it's a quoted a teacher, but it's interactive. You can add code. You can import data. You can, you know, print. Uh, you know, your intermediate results. You can also, um, plot, you know, time serious. You can put maps for geospatial data. So that's Ah, kind of an overview off. You know, Jupiter, not book. So let's get started with our, you know, PLA thing. So the first thing elders just import Matt plot Lee package and that pew I plot as plots. So if I if you want to run a script, So this is our first line, you just go ahead and do that if you want to run it, you know, line by line. So this is the first line of court, and then if I read that, uh, it's it's so loading. The data was an amp I ah, I think my immediate stream of this. Okay, so if there's no issue, it would just keep on running the next one. So just and it lets also import, you know, pandas a speedy right. Ah, but mind you like before we import the data, if in your kids, you might have problem was when important, my plot leave and then the pond us you have to first install this package. Right? And once you install it, you can you can, you know, important. So let me show you how you can. Um you can install a package for the Jupiter, not book. So let's go to the anaconda. Prompt. Right. So that's how you install pockets. For example, the pond us. Right. So, to install any Jupiter 80 pie 10 package, let me show you like, let's go. Really? Like in the store his store upon. Does your P teacher No. Right. So if you if you just click here, you I'm just looking for, you know, sample script like script. I just want to show you how you can get, like, some quotes or, um, how you can, um All right, it's not a lot much. Okay, so let's just go back and let's go to the, you know, Anaconda prompt. And let's do install Thebe pandas package. Right? But I have I have already installed it just but for you, That's how you stole it, Leslie. So Conda, right? Condoms. Its toll found us. That's the package that you want. If it's a different package you right. So, Kanda, install. You know the name off the package and just your hit. Enter Now it's just activity solving environment says it's attempting to install that. So it's just responding. So this is a line, of course, that you need to know. Um, whenever you have, you have to install some package. This is how you install it, right on an accord. A problem. Okay, so it says that, um, you know, the following package or not a village from the current child, but it's already install. I think that's the rate that the reason that it's not, you know, let me do that, OK? And if your package is not installed, if you run here, you'll just, you know, see an ear message. If it's not showing you here, then it means that your package is already installed, and then it's it's importing it. So no issue. Right? Okay. This this is the first housekeeping that you need to know before you just go in some dibs, right? Okay, So run the import that my plug in the pants and then this is where my, you know, data is saved. So I'll define a d if PD as a pandas, um, and releases if you so so technically I'm writing the name off the fight. Another thing that I would like to show you is just You might be interested. Words? Where should I put my data? In an on all my scripts. So where is that? You know, let's just at another line here. I think it's PW. Let's just try that. Okay. P w deep Okay. All right. Perfect. So PW D is just you're working in a directory for for this Jupiter, not book. It will. If you write pw d, it will tell you where you're just Technically, you're working, director, right? See, for if I go here, see users. You know, if I go to this file, I'll get my all my, you know, anaconda codes and on the input data. That's just my working there too. So let me go to see and users all my and then piped in geospatial. That's where it is. Okay, so you can see all this. You know all these. Let's go to the main page. Okay? So you can see all this chords right here, right? Because all of my you know, fightin and courts with I p y and be, You know, Suffolk's so you can see all of this course, right? And then my denies here, So that's that's how you So that's how you write like your data. So this is your working there tree. So when you ride the filing, you just simply because this is our working directory, you know, we're writing here data analyst LST brazil. So data LSD, Brazil LST possible. Here's the CSP five. So that's were just technically call in this fire. So for in your kids, the first thing you need to know is just to lock it. You're working directory, right? By writing P w d. Once you know you're working there tree credit, a data folder and the data folder and try to add, you know, the date of the data finds LST Brazil and put it there, and that's it. And just write this, you know, write this script and just run. It should run smoothly, right? Um, that's the first thing you need to know. And then once we imported the data, it's just, um, call. So our data is just give now, So let's select some variables, right? Um and the other thing is, we might be interested to do like the F head. Okay, so if you ride DF head, then you know what? What? The different columns and this data Bizarre. Right? So I have a month's parameter Ah, year primary and enlistee and land surface temperature on the rainfall. This is ah, for process. Right? Um and I like to map, you know, LST you know? So I want to select, you know, the different parameters here. So what I'm doing here is just Ellis physical two DF is my data file and just ride the name off the column here LST then volleys. So it's just selecting that that specific call it and then the same thing for Rampal here and in the same thing full for the months in the year. Okay, so now it's easy for me to plot each off. You know, these parameters, right? And the next thing is, I define my x and y primary because I'm doing, you know, line plot here. So I'm I'm telling, like so I want my egg sacs is to be months. Here's months we really find that. And then the y axis is just LST so, um, you know, the Y axis is LSD, right, And then plot dot Plot X y I'm just plodding, you know, LST by mints, right? And then just run that. They'll have to just run this first, that's why. Okay, Perfect. Because I have to rent this, um, you know, dispatch off scripts. So now we have made our first time serious plot s. So this is, you know, months off the year. And this is land surface temperature values, you know, for Brossel. And this is just, you know, basic, you know, plot. So let's do some a little bit of, you know, changing the color and entitled in X and Y actives, right? It's that some private, it's prod plot X y and then add plot title. So we're gonna write, Read a title here. Brazil enlistee. Here is just my title. If I want to change it, it can change. Um and, you know, plot X label. So this is our ex label and then plot. Why label? So this is our, um Why? Why? Um, my access I can change actually, LSD, All right. Our lunch surface and pressure and do Reese else's. All right, so let's just run this a shoot change right we have Tampere and, you know, months, years when I run, the script should change, right? So long surface temperatures changing out of medically. And then here was 2015 and 2016. Actually, this change that back to 2015. Okay, Perfect. So now we have also in a changed, you know, the color and the type off, you know, line. Ah, and we have added a title. We about X and y axis. That's pretty cool. And let's dio this is a line graph and inlets to a bar plot. So to do a bar plot instead off. You know, plt plots we do plt bar, right? And an ex wife. So and then we also just, you know, tied toe, you know, x and y level. So if you run this crib, it will just give us, um, pretty nice looking, you know, bar plot instead of a line. So that's how we can do some plot. Think using the, uh, Matt plot leap package. Inp Iten A Jupiter, Not book, right 3. 5 DEMData Final: Hi. Well, come to this lecture. Let's get started. In this lecture, we talk about mapping a D d m or digital elevation model. Which raster Data. Okay, First, let's some loaded Jupiter or not book by typing Jew P to her notebook. Right. Okay. And it's good. Or data folder script here. So to start with, you need Teoh install all this package raster humanely and mastery of package. And once you install them, you can important if I run the script. Um, it will important off this packages. And, um, I have this, ah, elevation data saved in the data folder. Um, and you can credit the data folder yourself. So you know, I leaves the roster you in a package to open this teach elevation model. All right around that script. And once I important my D's elevation model with the Ross Torrio package and I will create , I'll create a plot using Mott my split lead right here in port. Might put leave and then plot. Um um I am show and then we'll have an area here. My diesel vision model, um, and credit interpellation. And, um, I need a color bar here. Just wait have here on a title off my map. You can change it here if you want to and plot show. Then it should show me that map in the run This script. Fantastic. So this is technically our first raster map by using to basically package Ross Torrio and then the might plot leave to create a title color and in a color bar here. Legend. Pretty cool, right? It's just more basic. But, um, that's how you can, you know, important raster data and generate a nice looking gum up. 4. 9 MapProjections Final: However, one will come to this lecture in this lecture. Look at how you can compare different map projections in Piketon. Right? So the first thing first is make sure that you install some package suggests an EMP I plot leave, and also based map. This is a very important for this. Um, you know, for this exercise. So you just want to make sure that you go to the anaconda prompt or just, you know, able to open here on your consul Anaconda prompt, and then ride Anaconda, Um, Kanda install. Um, you know the name of your package, for example, Base map, right. They just if you hit enter. That's how you install. You know, your package once you are done with that and then run the script. So when we're doing, you're just exploring different, you know, bells, map tool to, you know, look at I said background. You know, the oceans and the continents in different colors in in different contrasts and also different projection to create some nice looking professional maps in Piketon, right, that we're using the plot leave and biz map. Right. So the Bismarck will give you a background, um, off you know that the map like here, So you can see, for example, you have, you know, satellite, you know, satellite background off. You know, there's your service and also the oceans, and we'll look a different base maps. Tysoe came and also different projections. So it's first run the script. So this is just importing the different packages and getting ready, and our first map is that, you know, would plot dot figure so figure size we can change this, you know, the size of the figure and then we're importing a biz map was a projection so orto that's kind of the orto view in a kind of projection. And we can define a resolution for just and we don't need a resolution here. And then the lot long is kind of the the the the focus that we wanna, you know, we want toe, uh, zooming toe our map. So just if you click there, you know this map you're gonna get, You know, this this map and then if you want to change the lot long information, it kind of changed automatic. Elik Think, for example, if I lick it here, Allah, titted nine, maybe two. Lynge itude. Certainly five. She'd go somewhere in Africa. All right. So you can you can dynamically change the focus off. You know this map, right? If you're changes a little bit, um, mine is, you know, then it will just go, you know, below some some part below the equator, right? And zooming into Africa. So So you can you can play with this lot lying information in the size, you know, for example, by changes 12 um, and run that. See, it's just enlarging. You know, you can increase the size of that map in, and you can focus a different map. It's pretty cool. It's It's amazing that this bez map, you know, package will let you great some, you know, very nice looking. You know, professional maps, right? Was that it was an amazing in the background. Let's go, Teoh another in a mapping style. Okay, so here we're just creating. It's, you know, lcc. That's the projection style that we're choosing here again. We'll plot, you know, the size off the map, and then we define the weeks like, you know, the weeds in the height, and you're so also the lot long information here in this example will just focus in Seattle . So we're giving a lot long information in Seattle area. Um and, you know, the beauty is just We can also create some, um, you know, marker. Like, you know, this marker here. And then we can write a text if you want to, uh, in a Seattle and then just run. You know, the plot we can't create, like, focus on a certain, you know, region off the world. Right? Um, And again, you know, I can change this into, um, say, for example, nine. And here Blunkett information, You know, 32 Um, maybe, um is a freak. I think that's where it is. Let's just try and they're right. Fantastic. So that's where Okay, We have to define the the where just the markers are. It should match the location off the base map. So, um, this is the longitude 32 on, and then here is the latitude. All right, let's just cred. Uh, let's run that and see what's coming. Fantastic. So this is, you know, so you can change. You can play with you know, these applauding parameters in a Bismack package that starts amazing. So we can change the location a lot long information and zoom into that area and then create some markers and also create some text where that area is. And it's just it's just brilliant, right? Okay, let's go to another one. And then here, let's look at Cem in a map projection. So So here. So far, we don't have a latitude and longitude, right? Just you know, this is just a plain map. But now where we're doing here is just write a function to create the lot long lines. Right? So half here, um, a drone map function. So dif drum up. This is my function. And it has just this import primary, which is our map technically and then draw shaded relief image. Right? And then it would just credit. Ah, ah, lot long. You know, the lot longs in a minus 90 90. Every like this is the difference, you know, create a line every 30 13 you know, units right. And the longitudes again the same. Just It's minus at 180. This is like the farthest in the west and this is the farthest It's right. And then once we have dysfunction that creates you know? Ah, latitude and longitude. Let's do you know, create different map projections and then see what? What? What comes up? Right? So the 1st 1 is a cylindrical projection. And this this just creates a typical like, you know, the lot long. The lot longs are in a calm, have a constant, you know, gap, like on a straight line on a horizontal and vertical lines. This is just what you look at. So here, where we're creating is just defining the projection primary like it's silly, it's cylindrical projection, and we're defining the, you know, the lat long or just, you know, the latitude range in the longitude ridge and just drum up. So drum up is, you know, function that we created where we can create this lines. Right? So if we run the script, um, for some reason, it's just ah did drum up. Okay, we haven't run this script us way. All right, Okay. It's because we have not run this this initial script. That's what's just giving us your now it's It's scoring good. Like it can run it again. Should be fine. Right? Okay. All right. Perfect. Fantastic. So this is just a week. I think we can change the size of probably 86 Just proportional. Probably 12 8 plus for 10 maybe. Well, it's just running, you know, a large increase the size of a little bit so that we can see. Yeah, that's pretty cool. Um, so you know, this is amazing. We just have, you know, satellite background. And also we have this lot. Longitudes was a constant in a gap, and also the latitude like here. And we have that, you know, drum out function. And also, we selected a cylinder cylindrical function, and we can we can define the size like by, for example, I can say the latitude just to be, like, you know, 10 latitude that, you know, the four resist. No, I think that's the South. And this is just north. And also did the longitude Probably 20 in minus 20. How about that? All right. And we will have a different a little bit different zoom label. Okay. You see, I was just falling somewhere that we don't need that lately has just change this. Probably gonna minus five. And, um, that's the longitude. So how about certified? You know, and Okay, let's just run the all right. Didn't like this just to about it's, um five and 35 was to that just most some part of, like, Central Africa. Okay. And let's have something like this'll Let's have something like this and sturdy over here. Right? Okay, hopefully result lost. Try just to zooming to Africa. Like, let's just increase a little bit. Um, minus 10. All right. We're just an experiment into, you know, the lot long, you know? Yeah. So this is, like, mostly Africa. If not, all right, So we can We can define the different in a lot long, you know, border lines and just zooming to any place that we're interested to map. Okay, It's pretty cool. And this is cylindrical. And then we can also do Cedo cylindrical projection. We just call it here more, and you don't leave everything us. It is. And we can create, like, a nice looking map. Like like you see it here, Um and okay, that's pretty good. And and also, we can do like some perspective projections or orto orto projection, which can, like, provided, like some bird's eye view off the globe here in this case we just define or to hear defined some lot long information, especially the Arctic. Here you can see the Arctic here, and lastly, let's just do aquatic projection right here. You can define an iconic projection and define a lot long information again. Here's just arctic. A little bit slight, different version. So so overall here in this in a lecture. What we have done is just trying to use the biz map in my plot. Leap two great and amazing of, you know, map and a professional looking my funeral additions with different projections and in different, you know, background information. And this will help you to create some professional looking maps in Piketon using especially plot league and the debate is map, um, package.