Reputation: 55
I am having trouble with the extract function in the raster package. The raster is not empty, but when I perform the extract function all the values come back as NAs. I can plot the points over the raster fine and they show up in the same location.
library(dismo)
library(raster)
#Import CSV File
file <- paste("C:/Michelle/Michelle/R/CuskPA_Sept12_2013_1.csv", sep=" ")
#read file
cusk <- read.table(file, header=TRUE, sep=',')
cusks<- subset(cusks, SlongDD!=0 & SlatDD!=0)
cuskll <-cusks[,24:25]
#import raster
salvar <- raster("C:/Michelle/Michelle/R/Variables/salvar")
ext <-extent(-67.6, -64.9, 41.0, 44.7453)
salvarc <-crop(salvar, ext)
#extract from raster
psalvar <- extract(salvarc, cuskll)
This is what I get when I'm finished the extraction
head(psalvar)
[1] NA NA NA NA NA NA
summary(psalvar)
Mode NA's
logical 3859
The raster does not show up as empty.
> salvar
class : RasterLayer
dimensions : 334, 240, 80160 (nrow, ncol, ncell)
resolution : 0.01121539, 0.01121539 (x, y)
extent : -67.59662, -64.90493, 41.00048, 44.74642 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
data source : in memory
names : salvar
values : 0.01655413, 2.137321 (min, max)
Here is an example of the lat/longs in the file
head(cuskll)
SlatDD SlongDD
1 44.41533 -66.07883
2 44.41167 -66.07733
3 44.44883 -66.07433
4 44.47067 -66.01217
5 44.47050 -66.01183
6 44.47633 -66.01450
Upvotes: 0
Views: 1226