FAQ Database Discussion Community


Why does as.data.frame give error when converting a raster with factors as data and specifying xy=T?

r,r-raster
I would like to convert a raster layer into a dataframe and get the coordinates as well. This works just fine, but doesn't give xy values: as.data.frame(raster_layer) as.data.frame(x = naip_svm_cropped) category 1 forest_broadleafdark 2 forest_broadleafdark 3 forest_broadleafdark 4 grassland 5 grassland 6 grassland This throws an error: as.data.frame(raster_layer, xy =...

How to get contour lines around the grids in R-raster?

r,r-raster
Having a raster in R, how can I draw a contour line around the grids (not joining the centers or anything else, really following the boundaries of the grids) having some value (or identified by some mask)? The following example shows how to get the contour lines around areas with...

R: Crop GeoTiff Raster using packages “rgdal” and “raster”

r,crop,raster,rgdal,r-raster
I'd like to crop GeoTiff Raster Files using the two mentioned packages, "rgdal" and "raster". Everything works fine, except that the quality of the resulting output tif is very poor and in greyscale rather than colour. The original data are high quality raster maps from the swiss federal office of...

Issue using saveRDS() with raster objects

r,r-raster
I'm trying to use saveRDS() to save a large number of lists each containing a raster layer and a list with metadata. It worked fine when the raster layer was extracted from a ncdf file, but when the original file is an ascii file, saveRDS() only writes a pointer to...

Using grid2poly with raster

r,kml,raster,r-raster
I am trying to take data from a raster and push it to KML format so that I get a series of gridded polygons. Looking at samples on the web it would appear that the way to go is to using grid2poly with plotKML. Unfortunately I have hit an error...

R: two functions with the same name and :: doesn't to work

r,r-raster
I am trying to use the as.raster function of the raster package, but there is already a function with the same name in the grDevices package. So, I use the :: operator to differentiate between the two, but it doesn't appear to work. Can someone explain where I'm going wrong?...

Extracting points that belong to a certain area of a RasterLayer (raster)

r,r-raster
As per title. I have a "classified" RasterLayer object which has (apart from NAs) two fixed values, 0 and 1. It is a kind of logical image. I also have a data frame of points with their coordinates, in form of a SpatialPointsDataFrame. How can I extract points belonging to...

Error when plotting RasterLayer in R 3.x.x

r,plot,r-raster
Since the release of R 3.x.x I have problems when plotting. Until now I was always able to go back to an older version to avoid this problem, but now I use packages which are not available for R 2.15.x. Little example: > r <- raster(matrix(1:25,5,5)) > r class :...

Plot Circle on Raster with Known Coordinates and Radius

r,plot,raster,r-raster
I am attempting to plot circles with a defined radius onto a raster image. I have successfully plotted my raster and put points onto the image: # open image to save png("RasterImage.png", width=10, height=10, units="in", res=144) # plot raster plot(VI.SOS.mean, main="VI Mean SOS", col=terrain.colors(length(seq(100,220,20))-1), axes=F, breaks=seq(100,200,20)) # add points points(sensors$X,...