Calculating Zonal Statistics of a Raster using Python

  Рет қаралды 14,054

GeoDelta Labs

GeoDelta Labs

4 жыл бұрын

This tutorial explains the basics of calculating the zonal statistics such as average, max, min values corresponding to a defined spatial area of a raster using a polygon vector layer using Python, with the aid of GeoPandas, rasterio and rasterstats libraries. Additionally, you will learn how to plot rasters and vectors on the same layer, how to use matplotlib subplots to plot maps and histograms together in the same canvas, as well as to extract the summary of the data into a Pandas DataFrame using the Pandas library.
Download exercise data - drive.google.com/drive/folder...
⭐NOTE:
‘Kite’ is an excellent tool that can help you boost your productivity when it comes to programming with its free Artificial Intelligence (AI) powered coding assistant. Kite is a plugin which provides smart completions and documentation as you’re typing-in your code, and its compatible with most of the well-known IDEs such as PyCharm, Spyder and VS Code. I absolutely love it, and recommend you guys to try it out as well.
www.kite.com/get-kite/?...

Пікірлер: 57
@olssonfilip
@olssonfilip 4 жыл бұрын
Just wanted to thank you for these vids, wish I had them during my time at Uni but now as a GIS professional I’m feeling even more inspired by your work! Looking forward to the next one : )
@geodeltalabs
@geodeltalabs 4 жыл бұрын
Glad you like them!
@kaustavdas5600
@kaustavdas5600 Жыл бұрын
@geodeltalabs: In the same code, if I want to extract the 95th percentile value, what modification in the code do I need to do ?
@moisengwa9904
@moisengwa9904 4 жыл бұрын
Very Good job GeoDelta Labs. I don't have enough words to thank you. Please please kindly post the part 2 tutorial Calculating Zonal Statistics of a Raster using Python. Looking forward to that:
@muhammadanjum524
@muhammadanjum524 4 жыл бұрын
Dear Sir , Thank you soooooooooooooo much . You are sooo nice and kind . You are sooo expert in GIS . I hope you will continue your help .Its really very very helpful for me . I actually want to do that one . Sir, you solved my problem . Once again THANK YOU soo much .
@abramswee
@abramswee 6 ай бұрын
Thank you very much for sharing this with us! much appreciated.
@rafaeltiara9092
@rafaeltiara9092 3 жыл бұрын
Great tutorial. Thank you!
@mulugetaworkuayele6412
@mulugetaworkuayele6412 Жыл бұрын
I am too late to learn from this interesting and very useful tutorial. Thank you so much!
@geodeltalabs
@geodeltalabs Жыл бұрын
Better late than never :)
@amitblizer4567
@amitblizer4567 Жыл бұрын
Thank you. This was very helpful for me in my thesis🙏
@jeffz7310
@jeffz7310 Жыл бұрын
I didn't need to go to Uni because of these videos, thx
@yaarobmohammad1020
@yaarobmohammad1020 4 жыл бұрын
You are the best
@mohammadbelalalzoubi8102
@mohammadbelalalzoubi8102 3 жыл бұрын
Thank you. It was a great video.
@geodeltalabs
@geodeltalabs 3 жыл бұрын
You are welcome :)
@shaileshshrestha9725
@shaileshshrestha9725 4 жыл бұрын
good job bro...more geopandas pls.. one thing you have a good voice
@DileepGuptagoodman
@DileepGuptagoodman 3 жыл бұрын
Very nice video . I like sir . 👍👍👍
@geodeltalabs
@geodeltalabs 3 жыл бұрын
Thanks!
@gmjakirullahnooruddin1734
@gmjakirullahnooruddin1734 4 жыл бұрын
Dear @GeoDelta Labs, Thanks for this great tutorial. Very much appreciable. Waiting for part two with multiple raster data. I have a couple questions. Do I have to project both my vector and raster dataset? If so how could I project multiple raster datasets at once? and the second question is while plotting/showing the raster data how could I show also raster scale right-side on my raster plot? Thanks in advance.
@hugonicolaubarbosadegusmao7824
@hugonicolaubarbosadegusmao7824 4 жыл бұрын
The tutorial was very good, I learned a lot! A question, where did you download this data? I wanted to download to Brazil.
@aakashbhatt3303
@aakashbhatt3303 2 жыл бұрын
Hi @Geo Data Labs, Great Tutorial thanks for this And please can you make tutorials on the liabrary raterio
@australoitaliano
@australoitaliano 3 жыл бұрын
@GeoDelta Labs, thank you very much for this fantastic tutorial. Just one question: how can I save the "mean" dataset in the shapefile? After I have performed the zonal statistic, I have open the shapefile with QGis but the "mean" column was not present in the attribute table. Thanks
@muhammadanjum524
@muhammadanjum524 3 жыл бұрын
Dear Sir, I am also trying to use QGIs and also python , but I could not my results . Can we discuss Please ?
@raquelzafrir2752
@raquelzafrir2752 4 жыл бұрын
Hi GeoDelta thanks for the video. I have a question. Did you check the values where your raster has no data or zero values? I am getting negative values and I do not know how to correct them. Thanks!
@umairrasool9580
@umairrasool9580 3 жыл бұрын
Very great and clear work you have done. i have a question please, i am working on my raster dataset for prediction like ANN, RF and CNN, i have converted the rasters into numeric and then train and test the data and got very good accuracy. Now i need to convert my test data into raster again as final prediction map but i don't know how to do this, please guide me thanks.
@sonalisharma3421
@sonalisharma3421 2 жыл бұрын
Hello Sir, can you please tell me how to perform zonal statistics on each band of raster stack. Thank you very much for making such useful videos.
@manuvideos3979
@manuvideos3979 Жыл бұрын
Hello, Thanks for this great tutorial. I have a question, while calculating the average, are taking in account the nodata pixels? If yes, is there a way to exclude nodata pixels while calculating average? Thanks in advance for your answer.
@yaarobmohammad1020
@yaarobmohammad1020 4 жыл бұрын
Can you please make more videos How to extract and compute volumes from raster How to make hydrogeological analysis And so on
@geodeltalabs
@geodeltalabs 4 жыл бұрын
Hi, do you mean to just to do a one time computation of the volume from a raster? If you do not have a specific reason to use scripting to do that, I believe you can do this kind of processes quite easily using qgis
@yaarobmohammad1020
@yaarobmohammad1020 4 жыл бұрын
GeoDelta Labs I think that coding always better than do it with software ; because u can use you’re code always with different situations and faster Thank you so much
@kaustavdas5600
@kaustavdas5600 Жыл бұрын
Thanks a lot for this! ...just one question, if I want to extract the 95th percentile at any of the districts, wherever the raster is present. What modification in the code do I need to do. Anyone's help is really appreciated
@DileepGuptagoodman
@DileepGuptagoodman 3 жыл бұрын
Please make the video for mapping of CSV data in geotiff. CSV have lat lon and values
@JesusRomero-zw8yw
@JesusRomero-zw8yw 2 жыл бұрын
Thanks for the explanation, but if I want to extract the areal average of each day (that is, the average area of ​​a polygon) from a netcdf file, for example precipitation or temperature, maybe some idea
@geodeltalabs
@geodeltalabs 2 жыл бұрын
Hi, for this I suggest you follow the tutorials that I have done on handling netcdf files using python. You might be able to modify the code in such a way that you would be able to extract the values into a separate set based on their geographical position, and perform the statistical operations on those extracted values.
@shakhawathossainshohel5159
@shakhawathossainshohel5159 4 жыл бұрын
Thanks a lot for the video, it was great. But I need to learn zonal statistics for multiple netcdf file like daily TRMM. Would you please help me?
@geodeltalabs
@geodeltalabs 4 жыл бұрын
Better try to convert to raster first.
@rajuahmmad9923
@rajuahmmad9923 3 жыл бұрын
I have converted APHRODITE precipitation data from netcdf to tif file. After that, i followed your tutorial and calculated mean value for each subbasin within my watershed shapefile, But i got NaN value in three of my subbasin. Could you please point out what might be the possible cause of this problem. Thanks in advance.
@slimieboy6264
@slimieboy6264 4 ай бұрын
having the same issue with a tif converted from a netcdf. idk what is wrong tbh
@malaymondal9953
@malaymondal9953 4 жыл бұрын
From which site we can get raster weather data, like wind speed, rainfall, temp etc.
@geodeltalabs
@geodeltalabs 4 жыл бұрын
You can try Aphrodite's portal for rainfall and temp in netCDF format. Windspeed, not so sure.
@andresfiallos7112
@andresfiallos7112 3 жыл бұрын
Hello GeoDeltaLabs, thanks a lot for this great video. I have a question and was hoping someone here can help me. When I run this line "avg_rf = rasterstats.zonal_stats(districts, rainfall_array, affine = affine, stats = ['mean'], geojson_out = True)" I get the following error: "MemoryError: Unable to allocate 3.95 TiB for an array with shape (620193, 874319) and data type float64" I have been trying to resolve this issue but I havent been able to do so. I would really appreciate the help!
@eddisonjose
@eddisonjose 4 жыл бұрын
Hola muchas gracias, eso se puede hacer en pycharm? Soy neófito en programación, pero que opinas del programa pycharm? Saludos
@geodeltalabs
@geodeltalabs 4 жыл бұрын
Hello Eddison, pycharm is a good IDE too, however I have always worked with Spyder IDE, as the interface is simple, but sufficient enough to get the job done. You can indeed use pycharm to do all what we are doing here
@eddisonjose
@eddisonjose 4 жыл бұрын
@@geodeltalabs hola muchas gracias por su respuesta y amabilidad
@eddisonjose
@eddisonjose 4 жыл бұрын
GeoDelta Labs Hola una pregunta mas: Que opinas de hacer estos procesos en jupyter notebook? es factible? se pueden hacer allí?🙂
@jitutiwari7813
@jitutiwari7813 3 жыл бұрын
Hi, first of all Thank you for this Tutorial. I am a GIS and remote Sensing student and also want to Learn python for geospatial task can you please suggest me how could i learn python. or which books or tutorial can help me. waiting for your response. and please can you tell me how to calculate zonal on bigTiff.
@geodeltalabs
@geodeltalabs 3 жыл бұрын
You are welcome :)
@sonukumar-cy1fo
@sonukumar-cy1fo 3 жыл бұрын
Sir, I got this error :MemoryError: Unable to allocate 21.4 TiB for an array with shape (2028294, 1449644) and data type float64. please help me
@daanidev
@daanidev 3 жыл бұрын
Hi, Can you please tell me how you prepare tif files? i have tif files and shape file but i am unable to map correctly just as you did in this video. Can you help me with it? Thanks
@geodeltalabs
@geodeltalabs 3 жыл бұрын
Hi, did you check whether both the raster and the vector files are having the same coordinate reference?
@daanidev
@daanidev 3 жыл бұрын
@@geodeltalabs Hi my shape file and raster file has same crs can you please help me to show shape file over raster in python ?
@daanidev
@daanidev 3 жыл бұрын
@@geodeltalabs thanks issue solved (Y)
@reshmaa8818
@reshmaa8818 2 жыл бұрын
How to install rasterio and rasterstats?? Can you provide your video link below
@muhammadanjum524
@muhammadanjum524 3 жыл бұрын
Dear Sir, this is really really an excellent video for zonal statistics . But I followed your method but could not get results . I need to discuss . Sir, Please help me .This is my very very humble request . Please . I need to discuss with you . Please let me know how and where can i discuss with you ? Please my most humble request . Please reply positively as soon as possible . Please
@geodeltalabs
@geodeltalabs 3 жыл бұрын
Hi, kindly send your query to our email. Thank you.
@muhammadanjum524
@muhammadanjum524 3 жыл бұрын
@@geodeltalabs Sir, I have raster , I did calculate average monthly values by using QGIS raster calculator and now I want to calculate Zonal statistics . How can i send you my raster and shape file . Please help me . Sir, its my humble request that how can i send you ? Please
@wongamasiza7877
@wongamasiza7877 3 жыл бұрын
I wish I could do all this in R. ..I can't install some of these packages as I am not administrator. I have to log calls to our service desk every time I need to install a package. When I try installing them on my laptop I get errors that I must provide a path to GDAL.. Last time I had to use anything related to GDAL it gave me hell. Its easier to install all these packages in R... my goodness, I have to migrate to python once. I am going to die
Automating Raster Data Extraction using Python
21:36
GeoDelta Labs
Рет қаралды 14 М.
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 67 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
Zonal statistics in ArcGis
3:20
Made 4 Geek
Рет қаралды 41 М.
Create a Hypsometric Curve from a DEM using QGIS
9:13
Hans van der Kwast
Рет қаралды 12 М.
Introduction to Visualizing Geospatial Data with Python GeoPandas
28:29
Analyze floods using ONLY Python! (aka spatial data science)
24:07
Matt Forrest
Рет қаралды 13 М.
SHAP with Python (Code and Explanations)
15:41
A Data Odyssey
Рет қаралды 52 М.
QGIS Demo 40: Zonal Stats for Multiband Raster
5:01
Aaron Maxwell
Рет қаралды 2 М.
An Absolute Beginner's Guide to Python GeoPandas
48:42
GeoDelta Labs
Рет қаралды 97 М.
Exploratory Data Analysis with Pandas Python
40:22
Rob Mulla
Рет қаралды 440 М.
How to Convert Coordinates from CSV to ESRI Shapefile
14:03
GeoDelta Labs
Рет қаралды 14 М.
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 67 МЛН