DEM raster data analysis in Python using rasterio , richDEM , geopandas , and shapely

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone this video is different from the previous videos on my youtube channel on the previous videos I was using mainly vector data in this video I'll be working on raster data the purpose of this video is to explain the following first how to load a DM raster data into Python de M stands for digital elevation model de M raster for those who are not familiar is a raster storing elevation values second how to illustrate basic attributes of the loaded de M raster third how to create two new rosters using the loaded de M raster the two new rasters will have values for slope and aspect respectively a slope value in a pixel represents steepness usually in angular degrees ranging from 0 to 90 degrees a high slope value indicates a steep terrain and a low value indicates a flatter terrain regarding the aspect raster a pixel value basically represents the direction of the slope ranging from 0 to 360 degrees so for example in a specific location if a pixel has a slope value of 75 degrees and a pixel has an aspect value of 180 degrees this means the area in the given location is steep and the steepness is toward the south in another example if the slope value is 75 degrees and the aspect value is 355 degrees this means it's steep but the steepness is toward the north such values can be used in applications such as watershed delineation and flood management fourth we will create random vector points and assign these points the attributes of elevation slope and aspect using the three raster's finally we will export the created points into two outputs shapefile and geo jason all right now i will talk about the python libraries I'll be using raster i/o rich de m geo pandas and shapely raster i/o is a library built using G doll and numpy it is used mainly to read and right raster data rich DM is a library offering de M analysis functionality geo pandas is an extension of pandas the very well known data analysis library in Python geo pandas extends pandas dataframes to use a geometry data type and to run geospatial analysis and the Shapley library is used here to create the point objects for geo pandas in this video I'm using Jupiter notebook to illustrate the steps before I start I would like to mention one thing about printing output on Jupiter notebook when you write a Python script let's say for example using sublime or visual studio code if you want to print the last element of a list you will write print my list index negative one but in Jupiter notebook you don't have to do that you can just type my list index negative one this doesn't mean that the print statement does not work on Jupiter notebook so in other words Jupiter notebook acts in printing output as a Python interactive shell environment I left comments here to help you understand each step the comments in jupiter notebook can be added in what is called markdown style let us start so here we are importing the packages we need this line enables plots to be displayed on jupiter notebook in this line of code on creating a raster io data set object using the geotech file called Madinah on the same path of this notebook running this cell okay okay it was loaded without any errors by the way this is the g OT file we're using now let's check the coordinate system assigned to the g OT file so this is the CRS value and as you probably know it is for wgs84 here the count attribute will tell us how many bands we have in the geotech file in the DM file we have only one band all right now let's see the bounds of the DM file let me scroll up so these are the bounds of the raster IO dataset and height and width are so as you can see the raster has the same number of rows and columns now I can plot the de m raster using the plot module in raster i/o this is the plot and later I will use rich DMS plotting option ok next I will create band 1 object using the reed method the output of the reed method is an umpire array and I am converting the values in band 1 to float I need to do this because rich DM needs float values to create the slope and aspect now from band 1 I can get the pixel value of Row 1 and column 5 remember band 1 is basically a numpy array so this is the value I can also get the longitude and latitude coordinates for the pixel in Row 1 and column 5 but I can do that with the raster i/o data set object not the bad one since band 1 is only an umpire array ok now we are starting to use rich TEM package so first thing I'm creating a rich TEM object on this line of code rich de M accepts an input of numpy array which is here band 1 in this cell I'm plotting the rich de M object using rich de m Rd show method right here this means that the minimum elevation in the raster is 490 meters and the highest is 1245 the C map attribute is for coloring ballots you can Google more palettes if you are interested to try them out next we can create the slope raster from the rich DM object this attribute says slope degrees there are other methods in the rich DM package to represent slope for instance in Radian and percentage I think it's easier for us to interpret the three values in our mind but if you want you can explore the other options let's plot the slope raster now I'm using a different color palette yellow to brown the low yellow values are for flatter pixels while the brown values are for more steep ones now we can create the aspect raster as you can see I updated the method to aspect don't worry about those these are only warnings they are not errors let's plot the aspect so for example the orange pixels are mostly west slope values since a perfect west direction should be 270 degrees we are almost done in this cell I'm creating a Python dictionary of four lists elevation slope aspect and geometry we need this dictionary to generate the random points along with their attributes geo pandas accepts a Python dictionary in this format as an input to create a geo pandas dataframe this for loop will create distant points now we're creating the geo pandas dataframe no errors finally we're exporting the geo pandas dataframe into two formats shapefile and geo jason so this is geo jason and this is shapefile this is the group returns notebook folder i'm working on so as you can see this is the notebook this is the geotech file and this is the new shape file and the new geo json file okay now let's see the output on cutest can click that vector select the geo JSON file open that let me change the symbology if I open the attribute table so as you can see three columns elevation slope and aspect for each point that's it for this video I hope you learned something here if you any questions please let me know
Info
Channel: Tips for GIS
Views: 1,844
Rating: undefined out of 5
Keywords: python, geospatial, GIS, raster, DEM, Digital Elevation Model, rasterio, richDEM, geopandas, shapely, slope, aspect, GIS programming, geospatial programming, spatial programming, GDAL
Id: 6wqFzbiU8uY
Channel Id: undefined
Length: 8min 57sec (537 seconds)
Published: Sun Jul 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.