giftindependent.blogg.se

Crop years raster in r
Crop years raster in r






crop years raster in r

crop years raster in r

We will use lapply (to act as a loop) and iterate through the polygons to get cell counts for each class.Raster: Create a RasterLayer object Description Here,we can take a quick look at a subset for the first aggregate polygon. rdf <- rasterize(vect(deforest), r, value=1, background=0)ī <- st_cast(st_as_sf(st_buffer(st_sample(deforest, 5), 40000)), We will also create some buffers (pretend municipalities) to act as aggregate polygons to get cell frequencies. We create a raster where deforested areas are one else zero. Plot(rdf_area <- rasterize(vect(deforest), r, field="AREA")) We will be using a binary representation for analysis. We will rasterize the "AREA" field of the polygons, but just for illustration. deforest <- st_read(system.file("shape/nc.shp", package="sf"))ĭeforest <- deforest Read the polygons (here we grab a random sample for partial coverage of the study area). Here we just pretend that the nc polygons represent deforested areas and the buffer that we create are the municipalities, or any other aggregate unit. Let's perform a dummy analysis to illustrate a workflow deforest_rast <- rasterize(vect(deforest), r, values=1, background=0) The advantage of using a uniform value is that you can simply mask the data and return a cell count (see below). Using uniform output "1" with a background value "0". Using an attribute file to rasterize deforest_rast <- rasterize(vect(deforest), r, field="deforest_area") Note you have to coerce your sf object into a terra vect object. I an using "deforest_area" as a place holder for your attribute. Or, you can just output and tally the "1" cells in another analysis.

crop years raster in r crop years raster in r

R <- rast(ext(deforests), nrow = 1000, ncol = 1000)Īssuming that you have an attribute indicating area (eg., hectares) for each polygon, we can use it to have our raster values indicate area. We will then create an empty raster "r" to act as our reference for rasterizing the deforestation data. I will illustrate how you can rasterize your data and leave your distance question for another time. You have a few questions nested in your post so, it would be helpful to clarify your thinking and focus on exactly what you are after here. We will use the terra library to rasterize the data. How do I rasterize this Deforestation data within the Municipality boundary?

#CROP YEARS RASTER IN R HOW TO#

This rasterizes the Municipality polygon, but I can't figure out how to assign a value to each raster cell based on the Total Area Deforested - possibly by combining the above with st_intersection, but I'm not too sure. Mun_Raster <- rasterize(Municipalities, r) Municipalities <- as(Municipalities_sf, "Spatial") I've also tried rasterizing the Municipality area through: Municipalities_sf <- st_read("Munic.shp") I've tried st_rasterize, without success. Unfortunately I'm struggling to rasterize this. Each black dot in the picture is a polygon of deforested land. The next step is to rasterize this data and calculate distance of each centroid to the municipality border (picture below) - where the value for each raster cell corresponds to the Total Area Deforested within that cell (i.e Total Area of the cell covered by deforestation polygons). I'm only interested in polygons within 30 municipalities (which I have unioned and buffered - see below), so I've subsetted the deforestation data to these municipalities only. I'm working with Deforestation data (EPSG: 5880) for the Brazilian Amazon - consisting of 70,000 polygons of deforested land that covers all of Brazil. I'm a relatively new to working with spatial data in R.








Crop years raster in r