Clip multiple raster files at once using a Shapefile with different CRS in R

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone well today i'm going to show you how to crop a raster with a zip file having different crs than rest of itself ah so let's begin first of all we need to load all required libraries rsp which is necessary to work with a file a similar raster is used to work with raster files and finally our digital uh i'm using it to that creates a file however it has other many functionalities now now let us just import our save file and uh to import a file we need to provide a directory where our save file exists in my case uh my file are here in this directory so i am simply simply going to uh select it and just copy it and test it uh however we have to take care to change this first class to backslash otherwise r will not recognize her the theory path provided yes after we sense this first last backslash then we have to provide the name of rc file as well with dot hsp extension yes finally we have imported our file and now we can visualize it with the plot function oh wow seems great yes finally we have input our file and we have just floated it in r now we need to import our raster files as well so here i'm going to show you how to import all raster files at once so for this first of all we need to change our working directory to the directory where all of our raster file like this [Music] uh so i'm going to set my working directory to the directory where my raster file exists so this is my working directory so i'm simply going to copy it and paste it of course we have to change this first last to backslash so once we have done with this changing our working directory now let's write the code to input all the raster files at once so here just provide a path which is same as our working directory and work with this backslash thing and then we need to provide a pattern of our file which in our case is dot gif well great so now just stack it after we are done with this tracking we can just visualize how our raster looks like so with plot rgb call so this is our raster file and now we have to crop it with with a given zip file so for this first of all we need to take the crs so we can simply do it with with the function crs this is the share crs offset file now let's take a crs of restore as well oh no what is this yes we have different crs but no risk we'll find the solution to change the crs of safe file to share some crs of raster file uh yes even we can simply validate this with plot function as well we can just overlap this save file into the right onto the raster raster but it doesn't seem yeah that really overlap now so here we need to change the crs of safe file to the shares of raster file so let's do it oh no what is this oh yeah it seems i used wrong function so we just need to change it great nice let us visualize then if the save file overlaps with the raster well yeah so here you can see our save file has already overlapped onto our raster file we can even see it more clearly with defining any color so let's set a red color to that wow great so here you can see it is totally overlapped so now we are ready to go ahead to crop our raster file with just a file that we have so we can do it with raster a crop function yes we did it now just just visualize it if it works totally fine seems great however we don't want these blue areas so we need to get rid of this for this we can simply use raster max function wow looks great so finally we clicked the rest file that we that we have with our save file and we get we got rid of this blue rails as well now we can simply save our clip to raster file so for this we just provide the the latest clipped rust file which is msk and i'm going to save it here so i have i've said uh my final clipped raster file in the same directory where other raster file exists but however you are always free to give any location you want oh yes we have to provide the name whatever you like you can just simply call any name but however i have given here a name called cropped and we can say oh wow so here already we have even we can verify it by importing uh the raster into into r however here you need to use break function well yeah oh what is this oh yeah it seems i put additional space there which i need to get rid of yeah so now it seems it worked now just visualize it great so we did it so finally it's done i hope you enjoyed it keep watching bye you
Info
Channel: Remote Sensing & Data Analysis
Views: 619
Rating: undefined out of 5
Keywords: #R, #raster, #clip_raster, #import_raster
Id: B-d02twVnFw
Channel Id: undefined
Length: 13min 23sec (803 seconds)
Published: Thu Oct 08 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.