All Questions
1,780 questions
46
votes
3
answers
56k
views
How can I convert data in the form of lat, lon, value into a raster file using R?
I have a data set of values over a km grid in the continental U.S. The columns are "latitude", "longitude", and "observation", e.g.:
"lat" "lon" "yield"
25.567 -120.347 3.6
25.832 -120....
39
votes
6
answers
29k
views
Increasing speed of crop, mask, & extract raster by many polygons in R?
I'm extracting the area and percent cover of different land use types from a raster based on several thousand polygon boundaries. I've found that the extract function works much faster if I iterate ...
37
votes
2
answers
83k
views
Clipping raster in R
I am building a map for the northeastern U.S.A. The map background needs to be either an altitude map or a mean annual temperature map. I have two rasters from Worldclim.org which give me these ...
34
votes
1
answer
42k
views
Raster legend in R: how to colour specific values?
I have an elevation model plotted in R
r <- raster("example.dem")
plot(r, col = topo.colors(20))
Some of the values are below sea level (0), and I'd like to have those display in red. How can I ...
29
votes
1
answer
72k
views
How to assign CRS to RasterLayer in R
I have a layer with coord. ref. : NA.
How can I assign coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 to coord. ref. : NA?
class : RasterLayer
dimensions : 127,...
29
votes
7
answers
10k
views
Speed of various raster data formats
I'm having trouble locating any discussion or comparative benchmarking of different raster file formats (e.g., for use in data analysis in R). Does anybody have any insight into why particular formats ...
24
votes
1
answer
26k
views
Create polygons of the boundary of a Raster in R
I want to create two polygons.
One is of the rectangular extents of my raster. I know I can obtain the extent of the raster using
r <- raster("band5.tif")
e <- extent(r)
plot(e) gives me this:
...
22
votes
3
answers
14k
views
Performing Raster Noise Reduction and Edge Smoothing?
I have a raster image like this
I want to delete the isolated noise point and smooth the edge (say the white single points, and I want the edges of the entity look smooth). How can I do this in ...
20
votes
2
answers
34k
views
How to make RASTER from irregular point data without interpolation
I was trying to make a raster image from an irregularly spaced point database. The data looks like-
> head(s100_ras)
x y z
1 267573.9 2633781 213.29545
2 262224.4 2633781 ...
20
votes
4
answers
45k
views
R: How to get latitudes and longitudes from a RasterLayer?
I am an absolute beginner of geographic data, so please, forgive me if the question is not appropriate.
I downloaded data from NCDC NARR and managed to load into R using the raster package. I would ...
19
votes
1
answer
32k
views
Reprojecting raster from lat/lon to UTM in R?
i have to turn it into a UTM in order to make the buffer functional.
wets<-readOGR(dsn=".",layer="shapefile")
r.raster <- raster()
extent(r.raster) <- extent(wets)
res(r.raster) <- 100
...
19
votes
1
answer
44k
views
Converting a polygon into a raster using R
I'm trying to convert a shapefile into a raster within R. My approach is to read in the raster as follows:
library(rgdal) # Loads SP package by default
demo <- readOGR('F:/data/', 'shapefile') # ...
17
votes
7
answers
11k
views
Get Raster Values from a Polygon Overlay in Opensource GIS Solutions
I have two layers. A polygon-shape-layer with many tiles and a raster-layer containing CORINE 2006 land cover with many categories in a colourmap.
I want to obtain for each polygon in the shapelayer a ...
17
votes
2
answers
14k
views
Snapping raster grids in R
I am trying to align two raster grids in R. Once aligned I would like to be able to add them together.
I have tried to check whether making a stack would work:
grid_snap <- stack(habi_sdw, ...
17
votes
2
answers
46k
views
Extracting values from rasters at location of points using R
My question is about extracting values from rasters at the location of points. With the function extract this is very easy, and the function gives me a dataframe with the values of all the variables ...
15
votes
1
answer
23k
views
Replacing NAs with 0 for raster data using R [duplicate]
I am new in R.
How can I replace NAs with 0 for my raster data which have spatial information?
15
votes
6
answers
9k
views
Convert line shapefile to raster, value=total length of lines within cell
I have a line shapefile representing a road network. I wish to rasterize this data, with the resulting values in the raster showing the total length of the lines that fall within the raster cell.
The ...
15
votes
3
answers
20k
views
Converting point data into gridded dataframe for histogram analysis using R?
I am very new at using GIS data and only modestly experienced with R. I've been reading about how to analyze spatial data using the spatial-analyst.net PDF book, so I'm not completely lost, but I ...
15
votes
1
answer
29k
views
Using resample vs. aggregate & extend in R to have rasters of matching resolution and extent
I have two rasters of different resolution and extent:
> res(Elevation)
[1] 0.002083333 0.002083333
> res(Ann_precip)
[1] 0.008333333 0.008333333
> extent(Elevation)
class : Extent
...
14
votes
2
answers
8k
views
Random sampling of raster using R?
Is there a straightforward way of randomly sampling a raster so that the output of the process is a raster?
I'm using an example that I found on the r-sig-geo list and I have also tried the ...
14
votes
2
answers
15k
views
Aggregating points to grid using R
I have a question with regard to spatial aggregation in R.
What I am trying to do is aggregate a point dataset to a grid.
I am unsure however how to do this as I have little experience with this sort ...
14
votes
1
answer
4k
views
Calculating road density in R using kernel density? [closed]
I have a large (~70MB) shapefile of roads and want to convert this to a raster with road density in each cell.
My initial approach was to directly calculate the lengths of line segments in each cell ...
13
votes
3
answers
44k
views
Extract Raster from Raster using Polygon shapefile in R
I am new to R and using the raster package. I have a problem extracting polygons from an existing raster file. If I use
extract(raster, poly_shape)
function on the raster it always creates a list ...
13
votes
5
answers
12k
views
How to speed up raster to polygon conversion in R?
I've decided to process my Landsat data in R instead of ArcGIS - due to my missing knowledge of python and because of (assumed) high computation capacities of R. I want to :
import r1 raster to R,
...
13
votes
1
answer
892
views
Randomly altering raster map of habitat types?
I have a raster of habitat types for a specific area in Scotland. I need to create future habitat scenarios with changes in habitat to assess the population viability of a bird species.
For example, ...
13
votes
1
answer
2k
views
Why does @data@values slot for RasterLayer only contain logical(0) and not the actual values?
Trying to get to the bottom of why, when I read in a raster of NDVI, the @data@values slot does not contain the actual values until I set them manually. For example:
NDVI <- raster("./filename....
12
votes
3
answers
7k
views
Processing vector to raster faster with R
I am converting vector to raster in R. However the process was too long. Is there possibility to put the script into multithread or GPU processing in order to do it more faster?
My script to ...
12
votes
2
answers
15k
views
Mosaicking rasters in R?
I am trying to mosaic several rasters into single big raster in R. Using script that posted in https://stackoverflow.com/questions/15287807/how-can-i-create-raster-mosaic-using-list-of-rasters
But, I ...
12
votes
3
answers
3k
views
Conditional assignment of values to adjacent raster cells?
I have a value raster:
m <- matrix(c(2,4,5,5,2,8,7,3,1,6,
5,7,5,7,1,6,7,2,6,3,
4,7,3,4,5,3,7,9,3,8,
9,3,6,8,3,4,7,3,7,8,
3,3,7,7,5,3,2,8,9,8,
7,6,2,6,5,...
12
votes
1
answer
2k
views
Efficiently calculate distance between raster patch edges
I have a binary raster which I've classified into patches using raster::clump. I now want to efficiently calculate the edge-to-edge, i.e. minimum, pairwise distance between patches. I am currently ...
11
votes
1
answer
11k
views
R raster: masking a raster by polygon also remove cells partially covered?
I want to mask out a raster based on the values of a polygon: i.e., set to NA all values of the raster that are not covered by the polygons. However, it seems that raster::mask() masks out cells (i.e. ...
11
votes
4
answers
13k
views
Calculating areas of different raster classes in R?
I have generated a raster as a *.tiff file in R, with four classes. I'd like to calculate the area occupied by each raster class. Each class has a value (-5, -4, -3, -2) - I expect that I could also ...
11
votes
2
answers
3k
views
Creating randomly shaped clumps of cells in raster from seeds of 1 cell/pixel
I wish to "grow" clumps of cells from seeds within a raster. My base raster is full of 1's and 0's, 1's indicate land and 0's sea/NA areas. From the 1's I wish to select 60 random pixels/...
11
votes
2
answers
829
views
Count raster value in a bounding box (spatial extent)
Given a bounding box, how can I count the number of specific values (say, I am interested in the number of value == 1 ) in a raster in 1) arcpy, or 2) raster package in R?
11
votes
3
answers
5k
views
R: Download a large DEM, change projection, and adjust to smaller scale
This is a process that takes just a few seconds in GIS software. My attempt to do it in R uses a large amount of memory then fails. Is there something wrong in my code, or is this just something R ...
11
votes
1
answer
6k
views
Difference between gdalwarp and projectRaster
I am trying to project a Raster. In R there is the projectRaster() function to to this (below a fully reproducibly example) :
# example Raster
require(raster)
r <- raster(xmn=-110, xmx=-90, ymn=40,...
11
votes
3
answers
2k
views
From polygon to continuous measure of diversity?
First of all; I have tried to find a similar question, without success. Maybe it's because I'm quite new to GIS and I don't really know what exactly I'm looking for. If someone points me to a similar ...
11
votes
1
answer
10k
views
How to read *.adf files into R?
I want to load .adf files into R. The data is from this page:
http://www.fao.org/geonetwork/srv/en/metadata.show?id=14057
I tried the following code that I found after some research in the internet.
...
10
votes
2
answers
12k
views
Create spatial polygon grid from spatial points in R
I am trying to recreate a map in R. I need 2 by 5 degree grid cells across the contiguous United States, but plotted in Albers Equal Area. The result is a grid with curved lines and slightly variable ...
10
votes
4
answers
4k
views
Problems with NA values when reading .DEM file with R 'raster' package in Windows
I am trying to read a raster file in a .DEM format on windows using the 'raster' package in R.
I get problems with NA values, when loading the data into R in Windows 7, but I do not have the problem ...
10
votes
2
answers
19k
views
Create a raster with georeferenced information in R
Referring to my previous question, how do I "geocode"/convert - using R - a generated raster image to a format that can be shown as a layer on a map? In short, I'm aiming to recreate the results of ...
10
votes
1
answer
11k
views
Fill the gaps using nearest neighbors
I want to fill the NA values using the average values of the nearest neighbors:
r <- raster(matrix(1:16, nrow=8, ncol=8))
r[r==12] <- NA
10
votes
4
answers
6k
views
Assigning RGB values from Geotiff image to LiDAR data, using R
I have given a Geotiff image and its corresponding Lidar data (x,y,z) in UTM coordinates. I need to merge the Lidar data with the RGB values from the image.
That means, at the end, I need to plot (...
10
votes
2
answers
44k
views
Saving GeoTIFF from R
I have a raster file and I would like to save it to be able to open it with a attribute table in ArcMap.
When I use the command writeRaster(raster, "test_output11", format = "GTiff"...
10
votes
4
answers
17k
views
How can I export raster data from Arcmap to an R *.grd file format?
I want to work with raster data in R, but I have problems exporting my raster dataset from ArcMap. By "export data"/GRID I get a file with an *.aux extension. What I need is *.grd.
Can anybody help ...
10
votes
2
answers
6k
views
R: overlay a line on a raster stack/brick, and get profile of cell values along the line
I've combed through R's raster functions and vignettes and can't seem to get this working.
I want to specify a line/vector across a raster stack (a DEM and possibly related variables), and get a ...
10
votes
3
answers
6k
views
Remove clumps of pixels in R
I would like to remove isolated pixels (or clumps of pixels <9) from my raster image.
library(raster)
# create some raster data
r <- raster(ncols=12, nrows=12)
set.seed(0)
r[] <- round(runif(...
10
votes
1
answer
8k
views
Importing multiple stacked raster images in R?
I would like to import all multiple mosaic rasters (each mosaic is composed by 7 layers) from indicated folder into my R. Then access them as single multilayers rasters.
So I did:
# read all mosaics ...
10
votes
2
answers
11k
views
Max cell value from a stacked raster
How can I find a max cell value from a stacked raster.
Rmax <- maxValue(RAD1998.all[[1]])
works fine but
Rmax <- maxValue(RAD1998.all[[2]])
gives NA.
Of course not in a stacked raster.
...
10
votes
3
answers
809
views
Preventing reflective surface in rasterVis
I have been experimenting with digital terrain model files in ESRI ASCII grid raster format. Despite zero experience with this type of data I found it very easy to load into R, as per code below. The ...