Crop a Geospatial Raster in R

Today you will learn how to crop a raster into a vector. In this task, we will use the raster and rgdal packages. Let’s load them (read here). Then we load a raster (in the example we use Sentinel-2 satellite imagery) into the variable r, which we will crop (read here). We display the loaded raster (read here):

We load the polygon to be clipped into the variable border (read here) and display it on the raster:

We crop the raster with the polygon using the crop function from the raster package:

We display the result:

The raster has been cropped to the extent of the polygon only. To mask the pixels outside the polygon, you still need to use the mask function:

Show the result:

As a result of our action, we have obtained a raster that is clipped exactly to our polygon.

Leave a Reply

Your email address will not be published.

Translate using Google Translate»
Social media & sharing icons powered by UltimatelySocial

Podoba Ci się nasza strona? Odwiedź nasz profil