r-raster

Draw heat map (or similar) of 2D population distribution

╄→гoц情女王★ 提交于 2019-12-23 02:34:41
问题 I am wondering how I can draw an image of the population proportion (pop.prop) at these locations (x and y) so that I can see the population distribution clearly? The data is shown below: pts.pr = pts.cent[pts.cent$PIDS==3, ] pop = rnorm(nrow(pts.pr), 0, 1) pop.prop = exp(pop)/sum(exp(pop)) pts.pr.data = as.data.frame(cbind(pts.pr@coords, cbind(pop.prop))) x y pop.prop 3633 106.3077 38.90931 0.070022855 3634 106.8077 38.90931 0.012173106 3756 106.3077 38.40931 0.039693085 3878 105.8077 37

Reproducibility of results from predict() function - raster package

孤街浪徒 提交于 2019-12-23 02:19:34
问题 I am having trouble reproducing my results exactly when I make predictions with predict() and a saved gbm model object. I am using the raster package to predict to a raster. Each time I run predict() with the same model object and inputs (a raster stack), I get slightly different values (max value within 0.7 for a range of predictions from 0.08 to 12.30 for example). However, there seems to be a limited amount of outcomes. For example, I can get the results to reproduce if I run predict

Why is crop sometimes introducing NAs on a categorical raster?

偶尔善良 提交于 2019-12-22 18:40:18
问题 library(raster) r <- raster('glc2000_v1_1') # http://forobs.jrc.ec.europa.eu/products/glc2000/products/glc2000_v1_1_Grid.zip extent(r) # class : Extent # xmin : -180.0045 # xmax : 179.9955 # ymin : -56.01339 # ymax : 89.99554 ext <- extent(-69,-63,-3,3) r1 <- crop(r,ext) #Warning message: #In .getRat(x, ratvalues, ratnames, rattypes) : NAs introduced by coercion If I try to crop a smaller area, it works fine. ext <- extent(-68,-64,-2,2) r1 <- crop(r,ext) # works fine This error is preventing

R: Error thrown while using RGDAL and RASTER packages

天涯浪子 提交于 2019-12-22 09:56:28
问题 To whom this may concern: Here is the source code: GRA_D1<- raster(files[[1]]) //Sets up an empty output raster: GRA_D1<- writeStart(GRA_D1,filename='GRA_D1.tif', format='GTiff', overwrite=TRUE) //Write to the raster, for loop: for(i in 1:dim(GRA_D1)[1]){ //Extract raster values at rows d.Frame<- matrix(NA,ncol=2,nrow=dim(GRA_D1)[2]) d.Frame[,1]<- getValues(r1[[1]],i) d.Frame[,2]<- getValues(r1[[2]],i) w.Frame<- as.data.frame(d.Frame) names(w.Frame)<- c("D1_pred_disAg","D1_pred_RK") //Apply

writeRaster output file size

十年热恋 提交于 2019-12-22 09:55:51
问题 I have a function that reads a multi-band image in as a raster brick object, iterates through the bands doing various calculations, and then writes the raster out as a new .tif. All of this works fine, but the file size of the new image file is roughly four times greater (I assume because the original image has 4 bands). I'm wondering if there's a parameter in the writeRaster() function that I'm unaware of, or if there's some other way I can ensure that the output image is basically the same

Fill in gaps (e.g. not single cells) of NA values in raster using a neighborhood analysis

北慕城南 提交于 2019-12-22 09:30:44
问题 With the raster below, with an increased number of NA values library(raster) filename <- system.file("external/test.grd", package="raster") r <- raster(filename) r[r<300] <- NA summary(getValues(r)) is it possible to 'fill in' only the NA cells? I have been using this helpful post but as seen below, NA values remain in the final product. fill.na <- function(x, i=5) { if( is.na(x)[i] ) { return( round(mean(x, na.rm=TRUE),0) ) } else { return( round(x[i],0) ) } } r2 <- focal(r, w = matrix(1,3,3

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

二次信任 提交于 2019-12-20 14:45:18
问题 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 Topography, example files can be downloaded here. This is my code: ## install.packages("rgdal") ## install.packages("raster") library("rgdal") library("raster") tobecroped <- raster("C:/files/krel

Mapping slope of an area and returning percent above and below a threshold in R

拟墨画扇 提交于 2019-12-13 20:10:40
问题 I am trying to figure our the proportion of an area that has a slope of 0, +/- 5 degrees. Another way of saying it is anything above 5 degrees and below 5 degrees are bad. I am trying to find the actual number, and a graphic. To achieve this I turned to R and using the Raster package. Let's use a generic country, in this case, the Philippines {list.of.packages <- c("sp","raster","rasterVis","maptools","rgeos") new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,

Aggregating seasonal means with the raster package in r

给你一囗甜甜゛ 提交于 2019-12-13 14:05:24
问题 I am attempting to aggregate daily data (35 years) to monthly then calculate seasonal mean using the raster package in R (I know how to do it with CDO). Below is my code, which outputs 4 seasonal means for all years (140 layers). How can I loop to output only 4 layers ( for the 4 seasons)?. I appreciate your help. dailydata <- brick ("dailyrain.nc") dates <- seq(as.Date("1981-01-01"), as.Date("2015-12-31"), by="day") months <- format(dates, "%Y-%m") Aggregate2Monthly <- function(x) { agg <-

extract raster pixel value as well as pixel xy coordinates using a SpatialLine object in R

孤街醉人 提交于 2019-12-13 12:42:02
问题 I have a Spatialline that I converted from a polygon shapefile (digitized manually based on features in "imagebrick" - this means that spatially the "polyline" and "imagebrick" are overlapped as I wanted) polyline <- as(shapefiles_data[1,],"SpatialLines") > polyline class : SpatialLines features : 1 extent : 357714.3, 357719, 4076030, 4076035 (xmin, xmax, ymin, ymax) coord. ref. : +proj=utm +zone=11 +datum=NAD27 +units=m +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can