Automating Raster Data Extraction using Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • 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 ปีที่แล้ว +5

    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!!!

  • @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

  • @johnowusukonduah2305
    @johnowusukonduah2305 2 ปีที่แล้ว +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

  • @ibrahimalabdulsalam1005
    @ibrahimalabdulsalam1005 2 ปีที่แล้ว +1

    I should always start your videos by clicking the LIKE button.

  • @PhatPham-User
    @PhatPham-User 11 หลายเดือนก่อน

    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.

  • @sonukumar-cy1fo
    @sonukumar-cy1fo 2 ปีที่แล้ว +1

    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

  • @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 ปีที่แล้ว +1

      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!

  • @niampahamidou8931
    @niampahamidou8931 2 ปีที่แล้ว

    Thanks a lot for this video. You're the best!

  • @abdallahabdelmajeed8120
    @abdallahabdelmajeed8120 11 หลายเดือนก่อน

    Thank you very much but how can we do the same for polygons not point and in time series data?

  • @joshritman2480
    @joshritman2480 2 ปีที่แล้ว

    Great content. Thanks. Where can we download the raster data (avg_temp_nov2021.tif) from?

  • @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 ?

  • @AsifMarazi
    @AsifMarazi 2 ปีที่แล้ว

    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  2 ปีที่แล้ว

      Hi, you may follow this video and you will be able to get an insight on how to iterate through multiple raster files
      th-cam.com/video/_uaVrSeLFmA/w-d-xo.html

  • @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.

  • @SiddhZarathustra
    @SiddhZarathustra ปีที่แล้ว

    Great tutorial! Can you please share the source for download link or the temperature raster?

  • @moumitaghorai2040
    @moumitaghorai2040 2 ปีที่แล้ว

    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?

  • @mmukarrammuneer8715
    @mmukarrammuneer8715 ปีที่แล้ว

    Can I done same task in Jupyter of NetCdf (Raster) file with any shaple file???

  • @mrcactus1984
    @mrcactus1984 ปีที่แล้ว

    hello, how could i extract values from a certain point from diferent rasters to table? thank you

  • @MrABN143
    @MrABN143 2 ปีที่แล้ว

    Excellent brother 💐

  • @MrABN143
    @MrABN143 2 ปีที่แล้ว

    Can we use same process in other operations in raster? Like solar panel monitor , thermal sensor raster?

  • @AayushiSaini-l3g
    @AayushiSaini-l3g 8 หลายเดือนก่อน

    can you provide sample data that you have used??

  • @sanjayawanninayake3819
    @sanjayawanninayake3819 2 ปีที่แล้ว

    Good one...!!!👍

  • @Jobsvisapro7030
    @Jobsvisapro7030 2 ปีที่แล้ว

    Sir can you please upload complete tutorial list about PyQgis

  • @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

  • @not4weak
    @not4weak 2 ปีที่แล้ว

    Put the readio statement outside for loop

  • @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 ปีที่แล้ว +1

      Great! glad you were able to fix it! :)

  • @anitat9727
    @anitat9727 ปีที่แล้ว

    thanks

  • @manasranjanpanda9859
    @manasranjanpanda9859 2 ปีที่แล้ว +1

    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.