raster

How many non-NA values in each row for a matrix?

六眼飞鱼酱① 提交于 2019-12-02 10:18:05
I have a matrix(raster) that I am computing the the mean of each row in this raster as: library (raster) r <- raster(nrows=10, ncols=10);r <- setValues(r, 1:ncell(r)) extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90)) stepsize = (r@extent@ymax - r@extent@ymin) / r@nrows yvals = seq(r@extent@ymax - stepsize / 2, r@extent@ymin, -stepsize) The x-values will be the mean of each row in the raster: xvals = rowMeans(as.matrix(r)) plot(xvals, yvals) What I need is to know how many values were considered when computing the mean for each row (N)? Some pixels may have NA so the number of values will

Gap filling temporal raster objects

对着背影说爱祢 提交于 2019-12-02 08:00:39
问题 Suppose I have 4 raster layers each belong to every other week of the month. I want to use linear interpolation to create new layers for each day. In this case, the first 2 rasters belonging to the month of Feb with 29 days and the second 2 belong to March with 31 days . I want to know how to create daily raster objects that can fill the time period with the consideration of number of days in the month (29 rasters for Feb and 31 rasters for March). Thanks! library(raster) r1 <- raster(nrow=5,

Calculate distance between 2 lon lats but avoid going through a coastline in R

风流意气都作罢 提交于 2019-12-02 05:20:41
问题 I am trying to calculate the closest distance between locations in the ocean and points on land but not going through a coastline. Ultimately, I want to create a distance to land-features map. This map was created using rdist.earth and is a straight line distance. Therefore it is not always correct because it not taking into account the curvatures of the coastline. c<-matrix(coast_lonlat[,1], 332, 316, byrow=T) image(1:316, 1:332, t(c)) min_dist2_feature<-NULL for(q in 1:nrow(coast_lonlat)){

Calculate distance between 2 lon lats but avoid going through a coastline in R

≡放荡痞女 提交于 2019-12-02 01:57:42
I am trying to calculate the closest distance between locations in the ocean and points on land but not going through a coastline. Ultimately, I want to create a distance to land-features map. This map was created using rdist.earth and is a straight line distance. Therefore it is not always correct because it not taking into account the curvatures of the coastline. c<-matrix(coast_lonlat[,1], 332, 316, byrow=T) image(1:316, 1:332, t(c)) min_dist2_feature<-NULL for(q in 1:nrow(coast_lonlat)){ diff_lonlat <- rdist.earth(matrix(coast_lonlat[q,2:3],1,2),as.matrix(feature[,1:2]), miles = F) min

How to fix poor interpolation of very small rasters in viewed pdfs (evince and chrome)

好久不见. 提交于 2019-12-02 01:54:57
I want to create a visualization of a matrix for some academic work. I decided to go about this by having the pixels in the image correspond to the values in the matrix. I created the nice small png that follows: When properly scaled up, you get a very reasonable image: This is a screenshot from within inkscape. However, when export this as a pdf, both evince and chrome do a terrible job at upscaling what should be very trivial, and instead I get something that looks like: The pdf itself seems to scale appropriately well for printing, but unfortunately I do a lot of my editing without printing

How to change a Lambert Conic Conformal raster projection to latlon degree R

北战南征 提交于 2019-12-01 22:39:47
I have a raster, obtained from a netcdf which is in (Lambert Conic Conformal projection): library(meteoForecast) wrf_temporary <- getRaster("temp", day = Sys.Date(), frames = 'complete', resolution = 36, service = "meteogalicia") wrf_temporary extent : -18, 4230, -18, 3726 (xmin, xmax, ymin, ymax) coord. ref. : +proj=lcc +lat_1=43 +lat_2=43 +lat_0=34.82300186157227 +lon_0=-14.10000038146973 +x_0=536402.34 +y_0=-18558.61 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=km +no_defs Now I want to transform that wrf_temporary raster to "+proj=longlat +datum=WGS84" (lat long degree). What to do? I want

Calculating weighted polygon centroids in R

女生的网名这么多〃 提交于 2019-12-01 18:07:33
I need to calculate the centroids of a set of spatial zones based on a separate population grid dataset. Grateful for a steer on how to achieve this for the example below. Thanks in advance. require(raster) require(spdep) require(maptools) dat <- raster(volcano) # simulated population data polys <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1]) # set consistent coordinate ref. systems and bounding boxes proj4string(dat) <- proj4string(polys) <- CRS("+proj=longlat +datum=NAD27") extent(dat) <- extent(polys) # illustration plot plot(dat, asp = TRUE) plot(polys, add =

R raster avoid white space when plotting

时间秒杀一切 提交于 2019-12-01 18:07:29
I have an image and i want to plot only 100*100 square with left hand bottom corner at 0,0. when i use below commands. Why do i get a white space around my cropped image? how can i avoid it and ensure that I get exact 100*100 image? If you want to repeat my example, you can use any image on line 1 (provided that the image is bigger than 100*100 pixels) r <- raster("C:/Users/nnnn/Desktop/geo.jpg") vector= getValues(r) plot(r) r par(mar=c(0,0,0,0)) par(oma=c(0,0,0,0)) par(mai=c(0,0,0,0)) par(omi=c(0,0,0,0)) plot(r,xlim=c(0,100),ylim=c(0,100),legend=FALSE,axes=FALSE) Aspect ratios are normally

PCA using raster datasets in R

空扰寡人 提交于 2019-12-01 17:34:37
I have several large rasters that I want to process in a PCA (to produce summary rasters). I have seen several examples whereby people seem to be simply calling prcomp or princomp. However, when I do this, I get the following error message: Error in as.vector(data): no method for coercing this S4 class to a vector Example code: files<-list.files() # a set of rasters layers<-stack(files) # using the raster package pca<-prcomp(layers) I have tried using a raster brick instead of stack but that doesn't seem to the issue. What method do I need to provide the command so that it can convert the

Calculating weighted polygon centroids in R

纵饮孤独 提交于 2019-12-01 17:13:41
问题 I need to calculate the centroids of a set of spatial zones based on a separate population grid dataset. Grateful for a steer on how to achieve this for the example below. Thanks in advance. require(raster) require(spdep) require(maptools) dat <- raster(volcano) # simulated population data polys <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1]) # set consistent coordinate ref. systems and bounding boxes proj4string(dat) <- proj4string(polys) <- CRS("+proj=longlat