![]() Function ccodes returns country names and the ISO codes Data are read from files that are first downloaded if necessary. Get geographic data for anywhere in the world. dimensions: Dimensions of a Raster* object.datasource: Are values in memory and/or on disk?.cover: Replace NA values with values of other layers.corLocal: Local correlation coefficient.coords: Coordinates of the Extent of a Raster object.Compare-methods: Compare Raster* objects.compareCRS: Partially compare two CRS objects.cellsFromExtent: Cells from extent, and vice versa.cellFrom: Get cell, row, or column number.boundaries: boundaries (edges) detection.blockSize: Block size for writing files.as.matrix: Get a vector, matrix, or array with raster cell values.as.logical-methods: Change cell values to logical or integer values.as.list: Create a list of RasterLayer objects.as.ame: Get a ame with raster cell values, or coerce.as.character: Character representation of a Raster or Extent object.Arith-methods: Arithmetic with Raster* objects.approxNA: Estimate values for cell values that are 'NA' by.animate: Animate layers of a Raster* object.alignExtent: Align an extent (object of class Extent).aggregate: Aggregate raster cells or SpatialPolygons/Lines.Result = foreach(i = 1:dim(NDVI_stack_h24v06).packages='raster'.combine=rbind. R = rasterFromCells(NDVI_stack_h24v06, cell],values=F) NDVI_stack_h24v06 = stack( mget( rep( "NDVI_stack_h24v06", 500 ) ) )Ĭell = cellFromPolygon(NDVI_stack_h24v06, pt, weights=FALSE) # Create a matrix with random data & use image() Proj4string(pt) <-"+proj=longlat +datum=WGS84 +ellps=WGS84" Pt <- SpatialPolygons(list(Polygons(list(Polygon(pt)), ID="a"))) Extract polygon or points data from raster stacks - library(raster) You can avoid some operations by using cellFromPolygon (or cellFromXY for points) and then clip and getValues. You must be a R wizard! Here is a very minor tweak to simplify your code (may improve performance slightly in some cases). Speed up extracting raster (raster stack) from point, XY or Polygon So to use it, adjust the to fit with the column name of your identifying polygon (guess that could have been built into the function.) and put in: myoutput <- (cores, polygonlist, rasterlayer) ![]() ![]() #close(mypb) #not sure why but closing the pb while operating causes it to return an empty final dataset. Reproducible Example: library(maptools) # For wrld_simplĭata(wrld_simpl) #polygon of world countriesīound <- wrld_simpl #name it this to subset to 25 countries and because my loop is set up with that variableĬ <- raster(nrow=2e3, ncol=2e3, crs=proj4string(wrld_simpl), xmn=-180, xmx=180, ymn=-90, ymx=90)įastest Method so far result <- ame() #empty result dataframeįor (i in 1:nrow(bound)) ) #trycatch error so it doesn't kill the loop I looked into those, but have had trouble with gdal in the past and don't know it well enough to know how to implement it. The only thing I've found related to this is this response by Roger Bivand who suggested using GDAL.open() and GDAL.close() as well as getRasterTable() and getRasterData(). Nonetheless, it's pretty slow, and I'm wondering if anyone has any suggestions for improving the efficiency and speed of my code. I've found that the extract function works much faster if I iterate through each individual polygon and crop then mask the raster down to the size of the particular polygon. I'm extracting the area and percent cover of different land use types from a raster based on several thousand polygon boundaries.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |