Automating Raster Data Extraction using Python

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

GeoDelta Labs

GeoDelta Labs

2 жыл бұрын

In this tutorial, you will learn how you can use a simple python script to extract data from a raster.
Extracting pixel values at point locations can easily be done using a dedicated GIS software package such as QGIS or ArcGIS, if you are doing it just for a limited number of points. However, if you were to do the same for a large number of points, this exercise can get quite tedious, repetitive and extremely challenging.
In this tutorial, we are discussing a way of doing this in just a matter of few seconds using a small Python script, regardless of how large the dataset is. To demonstrate this, we are making use of a point shapefile, which indicates a number of selected cities across the United States. Along with that, we are using a raster dataset which shows the average temperature variation across the country at a selected day in November 2021.
The two major Python libraries that are being incorporated in this tutorial are GeoPandas and Rasterio. With the help of these two libraries, we manage to extract the point coordinates in the form of Latitude and Longitude values at each point location (city), and extract the corresponding temperature value (pixel value) from the raster for each of the aforementioned points. Finally, we write the information to a Pandas DataFrame and export it as a separate CSV file using the Pandas library.
#spatialanalysis #geopandas #rasterio

Пікірлер: 40
@pacomermela6497
@pacomermela6497 2 жыл бұрын
Excellent. It would be interesting to show how to extract pixel values ​​from an ESRI Shapefile of polygons to create a dataframe. It would also be interesting to learn how to assign a value to each sample according to a field in the attribute table. Thanks for your videos!!!
@niampahamidou8931
@niampahamidou8931 2 жыл бұрын
Thanks a lot for this video. You're the best!
@ibrahimalabdulsalam1005
@ibrahimalabdulsalam1005 2 жыл бұрын
I should always start your videos by clicking the LIKE button.
@sonukumar-cy1fo
@sonukumar-cy1fo 2 жыл бұрын
Thank you very much sir for your kind support. Your all material is very interesting. May I request you to make one video on object based classification
@sanjayawanninayake3819
@sanjayawanninayake3819 2 жыл бұрын
Good one...!!!👍
@MrABN143
@MrABN143 2 жыл бұрын
Excellent brother 💐
@johnowusukonduah2305
@johnowusukonduah2305 2 жыл бұрын
These video came as a live saver just when I needed it most. Thank you very much. But I want to ask if this same approach works similarly for multiband raster data? If its not so, please can you do a video to cover that? This will really help me a lot
@joshritman2480
@joshritman2480 2 жыл бұрын
Great content. Thanks. Where can we download the raster data (avg_temp_nov2021.tif) from?
@syedrafsanali6522
@syedrafsanali6522 Жыл бұрын
Thank you very much. It was very helpful.
@geodeltalabs
@geodeltalabs Жыл бұрын
Glad it helped!
@syedrafsanali6522
@syedrafsanali6522 Жыл бұрын
@@geodeltalabs Could you please check your email? I have sent something in detail. It would be a great help for me. Thanks again.
@MrABN143
@MrABN143 2 жыл бұрын
Can we use same process in other operations in raster? Like solar panel monitor , thermal sensor raster?
@user-ef4fu8os9v
@user-ef4fu8os9v Жыл бұрын
Great tutorial! Can you please share the source for download link or the temperature raster?
@abdallahabdelmajeed8120
@abdallahabdelmajeed8120 8 ай бұрын
Thank you very much but how can we do the same for polygons not point and in time series data?
@PP_User
@PP_User 7 ай бұрын
Thanks so much for your great tutorial. I followed your step and I can extract the tiff file already but I still have a concern that I have many files from the year 1981 - up to now (the step is one day). I would like to get all data day by day but still cannot solve this problem, could you has any idea or could you make another tutorial to do that if possible. Thanks again for your kind.
@christodoulossazeides8988
@christodoulossazeides8988 Жыл бұрын
i was searching for 3 days to do that. Every one suggested a different packages as (gdal, pygmt...) and i was not able to extract the values. Your simple way solve my problem. thank you very match
@geodeltalabs
@geodeltalabs Жыл бұрын
Glad I could help
@Jobsvisapro7030
@Jobsvisapro7030 2 жыл бұрын
Sir can you please upload complete tutorial list about PyQgis
@mrcactus1984
@mrcactus1984 Жыл бұрын
hello, how could i extract values from a certain point from diferent rasters to table? thank you
@nilpipra
@nilpipra 2 жыл бұрын
wish you could provide the sample files (raster and the points) used in this tutorials. We all learn a lot from you. You are the best!!
@geodeltalabs
@geodeltalabs 2 жыл бұрын
Thanks. Will include them wherever relevant in the upcoming videos :)
@nilpipra
@nilpipra 2 жыл бұрын
@@geodeltalabs : is there still a chance to upload this two files (US temp raster and station shape) used in this exercise?. I am doing something similar to that and it will be a great help if I have the exact file to practices,. Thanks in advance!
@moumitaghorai2040
@moumitaghorai2040 Жыл бұрын
I am struggling with installing rasterio. I can see it in the site-packages folder. But cannot import it, getting an error. Do you have any suggestions on this?
@AsifMarazi
@AsifMarazi Жыл бұрын
Great video... really helped me get closer to my goal. However, now I have multiple raster files, I tried to loop over the raster files but failed to write the extracted values in a better way.
@geodeltalabs
@geodeltalabs Жыл бұрын
Hi, you may follow this video and you will be able to get an insight on how to iterate through multiple raster files kzbin.info/www/bejne/labEh6WJmrF5o6M
@user-ug7he4xl8q
@user-ug7he4xl8q 5 ай бұрын
can you provide sample data that you have used??
@not4weak
@not4weak 2 жыл бұрын
Put the readio statement outside for loop
@mmukarrammuneer8715
@mmukarrammuneer8715 Жыл бұрын
Can I done same task in Jupyter of NetCdf (Raster) file with any shaple file???
@geodeltalabs
@geodeltalabs Жыл бұрын
Absolutely
@AbuZafor-yy5qh
@AbuZafor-yy5qh Жыл бұрын
AttributeError: 'numpy.float32' object has no attribute 'is_integer' at the last segment this error is come.What is the solution ?
@anitat9727
@anitat9727 10 ай бұрын
thanks
@geodeltalabs
@geodeltalabs 10 ай бұрын
You're welcome!
@henryjayr
@henryjayr Жыл бұрын
can you show tis in arcMap?
@geodeltalabs
@geodeltalabs Жыл бұрын
In arcmap this can be done using one of the inbuilt tools. Search for the tool 'Extract values to point', and it basically does the same thing
@isabelahorta3063
@isabelahorta3063 2 жыл бұрын
Hi! Thx for the tutorial! I got an error in the "print" line: --------------------------------------------------------------------------- IndexError Traceback (most recent call last) in () 11 rowIndex, colIndex = dem.index(longitude, latitude) 12 ---> 13 print(str(code) + ': ' + str(dem_data[rowIndex, colIndex])) IndexError: index 752266 is out of bounds for axis 0 with size 17336 Do you know how to solve it?
@isabelahorta3063
@isabelahorta3063 2 жыл бұрын
Hiiii! I already fixed it! I reprojected the shape and the raster to the same projection system. Thx.
@geodeltalabs
@geodeltalabs 2 жыл бұрын
Great! glad you were able to fix it! :)
@manasranjanpanda9859
@manasranjanpanda9859 2 жыл бұрын
Indeed it's an excellent tutorial but I think if we do have the shapefile of locations (includes coordinates) then just by using the extract raster values to points tool in ArcGIS, we can easily get values from n number of points that we need.
@matthese9986
@matthese9986 2 жыл бұрын
But you have to pay for it
@manasranjanpanda9859
@manasranjanpanda9859 2 жыл бұрын
@@matthese9986 yeah I agree 😊
10 Geoprocessing Applications of GeoPandas Library
51:33
GeoDelta Labs
Рет қаралды 29 М.
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 18 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 67 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 136 МЛН
The most important Python script I ever wrote
19:58
John Watson Rooney
Рет қаралды 156 М.
Convert between CSV and GeoTIFF with GDAL in Python
28:11
Making Sense Remotely
Рет қаралды 20 М.
Calculating Zonal Statistics of a Raster using Python
31:59
GeoDelta Labs
Рет қаралды 14 М.
Analyze floods using ONLY Python! (aka spatial data science)
24:07
Matt Forrest
Рет қаралды 12 М.
How to plot data from a NetCDF file (NetCDF in Python #02)
19:55
Luke Data Manager
Рет қаралды 1,6 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1 МЛН
An Absolute Beginner's Guide to Python GeoPandas
48:42
GeoDelta Labs
Рет қаралды 97 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 137 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 88 М.
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 18 МЛН