Geospatial Data in R - Cropping Data

Поділитися
Вставка
  • Опубліковано 3 гру 2024

КОМЕНТАРІ • 21

  • @connorohara-baker9208
    @connorohara-baker9208 Рік тому +1

    You're amazing at explaining this stuff. Thanks a million for the helpful tutorials

  • @weecology
    @weecology  4 роки тому

    Glad you're enjoying them! My stylists schedule is complicated, but we'll keep doing them as often as we can coordinate!

  • @cuteturtle438
    @cuteturtle438 4 роки тому

    Loving the hairstyle changes!

  • @alemayehumullatuadashio5350
    @alemayehumullatuadashio5350 2 роки тому

    Thank you very much for your response ! I found it very useful , hope you'll respond similarly when I face similar problem.

  • @hikikomorihachiman7491
    @hikikomorihachiman7491 4 місяці тому

    Nice editor 😊

  • @nowknow0
    @nowknow0 8 місяців тому

    Thank you boss.....

  • @alemayehumullatuadashio5350
    @alemayehumullatuadashio5350 2 роки тому +1

    Thank you it very useful. Yet I have question about how to much two /more spatial data with different resolutions ( e.g. 0.05 degree Soil moisture data and say 0.1 degree of ET data or other? ) thank you?

    • @weecology
      @weecology  2 роки тому +1

      In the context of cropping you can just keep the rasters at different resolutions and crop them separately (which is what you would have done anyway. For some kinds of analyses you will need all of your raster data at the same resolution. You can do this using the st_warp function in the stars package to change the resolution of the finer resolution data to match the coarser resolution. There's a nice written example here of coarsening the resolution: 132.72.155.230:3838/r/geometric-operations-with-rasters.html#resampling

    • @alemayehumullatuadashio5350
      @alemayehumullatuadashio5350 2 роки тому

      @@weecology thank you very much!

  • @alorsan2012
    @alorsan2012 11 місяців тому

    Congrats! Could you explain how to crop a netcdf file by shapefile?, regards

    • @weecology
      @weecology  11 місяців тому +1

      Everything should work the same way for raster data stored in netcdf files. You can load .nc files using `read_stars()` and they should work the same way if they contain a single raster. If there are multiple rasters in the .nc then things will still work, but dealing with the extra dimension(s) adds some complexity.

  • @connorohara-baker9208
    @connorohara-baker9208 Рік тому

    I'm having an issue with cropping a non-contiguous raster mosaic to a set of polygons. When I try to crop, I get error [crop] extents do not overlap. However, I know there is overlap because I verified in ArcMap. IS there a way to crop many independent rasters to many polygons in R? thank you

    • @weecology
      @weecology  Рік тому

      It's a complicated enough situation and I don't work with raster mosaics so I won't be able to satisfactorily answer it, but here's a couple of things to hopefully point you in the right direction:
      1. Check to make sure the projections are the same. You've probably done this already, but it's always worth a second look in case ArcMap is automatically reprojecting things when you visualize them. This is the most common cause of this error in simpler situations.
      2. I'm assuming that all of your polygons are in a single shape file, but if not then I'd try combining them. This should ensure that as long as the polygon and raster data overlaps at all and shares the same projection that the extents overlap.
      2. If the mosaic is just combining non-overlapping rasters (and therefore isn't doing any of the work of combining overlapping pixels) then I'd probably try doing the cropping for each raster independently (if that works for your use case). You could do this with apply/map or a for loop and use a tryCatch() statement to skip over any cases where the extents don't overlap.
      So, yes, this definitely should be possible, but can't quickly understand the details of what's going wrong in your case and couldn't find any obvious examples of solutions to the general problem online.

  • @vineetsansi
    @vineetsansi 3 роки тому

    this is a really nice video & I am trying to apply the same on the files I have.
    When I try to crop I get this Error: Error in st_crop.stars(ind_region_stars, ind_outline) : for cropping, the CRS of both objects have to be identical
    shapefile: Projected CRS: LCC_WGS84
    tile file: from to offset delta refsys point values x/y
    x 1 4800 60 0.00833333 WGS 84 FALSE NULL [x]
    y 1 6000 40 -0.00833333 WGS 84 FALSE NULL [y]
    I have also raised this at: stackoverflow.com/questions/68176438/how-to-adjust-projections-in-r-to-be-able-to-crop-raster-using-shapefile
    It would be of great help if you could help in fixing this issue.
    Thanks

    • @vineetsansi
      @vineetsansi 3 роки тому

      well it got resolved by using: `ind_outline

    • @weecology
      @weecology  3 роки тому +1

      @@vineetsansi Glad you got the original issue figured out. You can find more information about st_transform and projections here if you're interested:
      ua-cam.com/video/42prUS2SNGo/v-deo.html
      Unfortunately the error you're now seeing looks like there is an issue with the shape file itself that I'm not sure how to solve in R. You might be able to filter out that particular feature before trying the crop or see if you can import and export the shape file in another program in the hopes that it cleans up that duplicate vertex somehow.

    • @vineetsansi
      @vineetsansi 3 роки тому

      @@weecology thank you for such quick response.
      This error got fixed when i used raster package and cropped & masked using raster only. Not sure why sf & stars were having issues.
      And i saw ur video from the link you shared and its great and is really helpful 😀👍
      Another doubt: After cropping a raster is there a way to fill the white empty space with some color before writing it as tif again. Any video link if you could suggest ?
      I am totally new to spatial data and have created elevated map using rayshader package but not able to color the white empty space in it.
      So i thought if i would color the white na space in tif file itself then i will have colored backgrounds in rayshader elevation maps.
      Apologies for bothering you again and thanks for helping me out above.

    • @weecology
      @weecology  3 роки тому +1

      @@vineetsansi Glad to hear you got that fixed. Unfortunately I don't have any experience with the rayshader package. The empty space is being stored as a null value in the geotiff, which is generally what you want since it doesn't represent any particular value. Typically you then handle that null data in different ways in other packages or presentations of the image. So my only suggestion is to spend some time looking for information on handling null (or "NA") values in rayshader to see if it can help accomplish what you're trying to do. Good luck!

    • @vineetsansi
      @vineetsansi 3 роки тому

      @@weecology Thank you so much for giving me more clarity on how NA's are treated in geotiff files, really appreciate it.
      And using rayshader I have made few post, here is a small example: twitter.com/ViSa04438318/status/1410329401565220864