LONGITUDE | LATITUDE | SAMPLINGWEIGHT |
-0.6178 | 51.42428 | 17 |
-0.6377 | 51.40813 | 21 |
-71.2431 | 46.81268 | 28 |
-79.8873 | 43.24028 | 12 |
-79.9193 | 43.26191 | 12 |
-79.9207 | 43.26286 | 36 |
37.4639 | 55.5149 | 99 |
38.3456 | 54.72669 | 99 |
-68.7205 | 47.89317 | 10 |
setwd("C:/Users/filepath") #Set working directory to where your files are
library(raster)
library(rgdal)
library(SDMTools)
library(spatial.tools) #Load necessary packages (Install first if necessary)
ts = read.table("Bias1.csv",header=T,sep=",") #Read in your bias file (CSV) which should include columns LONGITUDE and LATITUDE in WSG84 format. If you are using other coordinate formats for your environmental files then match these instead.
e <- extent(c(-180,180,-60,90)) #Define an extent that matches your environmental rasters
rast <- raster(e,ncol = 100, nrow = 100) #Create a new raster with the dimensions of the environmental files
x <- rasterize(ts[, 1:2], rast, ts[,3], fun=mean) #Add your data to the blank raster.
#Where there is more than one value per pixel this code line averages them.
#If you have more than 3 columns in your CSV amend this in the second set of square brackets
x[is.na(x)] <- 1 #Fill in the non sampled pixels with "1"
#None of the raster values should be zero, this causes errors
plot(x) #Check the coloured pixels are in roughly the right geographical location
bioclim<-raster('bio5.bil') #Load one of your environmental bil files as a raster to create a template for trimming the new raster
bioclim #Check the attributes of the environmental raster. Note that XDIM and YDIM are rounded to fewer decimal places when called in R.
r2 = raster(x)
res(r2) = min(res(x))
r2 <- resample(x, r2, method='bilinear') #This will reshape the pixels of your new raster from oblong to square
projection(r2)<-"+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
#This matches the projection of your new raster to the environmental raster
r3<-spatial_sync_raster(r2, bioclim, method = "ngb",
size_only = FALSE, raster_size, verbose = FALSE) #Spatially sync your new raster to the environmental raster
writeRaster(r3, "~/biasfile.bil", format = "BIL",overwrite=TRUE) #Write your biasfile in BIL so the format matches the env. rasters
--
You received this message because you are subscribed to the Google Groups "Maxent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at http://groups.google.com/group/maxent.
For more options, visit https://groups.google.com/d/optout.
r3<-spatial_sync_raster(kdl, climdat, method = "ngb",
size_only = FALSE, raster_size, verbose = FALSE)
Warning message:In .local(x, ...) : this does not look like an appropriate object for this function