r-raster

r raster brick sum values in the cells determined by two different rasters, how to speed up calculations

血红的双手。 提交于 2020-06-25 06:49:04
问题 I'm working with climate data files with daily data so for most years 365 rasters in a brick. I want to sum over the value in files for subsets of days - say day x to day y. This can be done with stackApply. I've created some code below that generates some rasters, creates a brick and applies stackApply using specific values for x and y, 1 and 3. What I need however is for x and y to taken from two raster layers. In the code below they are called raster.start and raster.end. Below the first

Spatial line start and end point in R

拈花ヽ惹草 提交于 2020-06-01 06:41:10
问题 I am attempting to use the sp package to access the start and end points of a linestring, similar to what ST_StartPoint and ST_EndPoint would produce using psql . No matter how I try to access the line, I get errors or NULL value: > onetrip@lines[[1]][1] Error in onetrip@lines[[1]][1] : object of type 'S4' is not subsettable > onetrip@lines@Lines@coords Error: trying to get slot "Lines" from an object of a basic class ("list") with no slots > onetrip@lines$Lines NULL The only solution that

Spatial line start and end point in R

╄→尐↘猪︶ㄣ 提交于 2020-06-01 06:41:10
问题 I am attempting to use the sp package to access the start and end points of a linestring, similar to what ST_StartPoint and ST_EndPoint would produce using psql . No matter how I try to access the line, I get errors or NULL value: > onetrip@lines[[1]][1] Error in onetrip@lines[[1]][1] : object of type 'S4' is not subsettable > onetrip@lines@Lines@coords Error: trying to get slot "Lines" from an object of a basic class ("list") with no slots > onetrip@lines$Lines NULL The only solution that

R: over-write xy coordinates of raster layer

人走茶凉 提交于 2020-05-09 04:44:29
问题 I have a raster with XY pixel coordinates which I want to convert to lat and long. class : RasterLayer dimensions : 1617, 1596, 2580732 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : 0, 1596, 0, 1617 (xmin, xmax, ymin, ymax) coord. ref. : NA data source : C:\janW1.png names : janW1 values : 0, 255 (min, max) I have calculated the lat/long coords using the formula specified here. This has resulted in the following dataframe heads(cords) lat lon x y janW1 1 46.99401 -14.99122 0.5 1616.5

Keeping raster variable names when converting to NetCDF using R

假装没事ソ 提交于 2020-03-18 15:24:19
问题 Taking a raster file of monthly temperature data for multiple years which has a name attached accessible via names(object) in the following format 'Jan.1981', 'Feb.1981' etc (example files for two years that works with code below here - adding all files makes it too big. Reading in and writing this to NetCDF using the following code: #Load Packages library(raster) library(ncdf4) #Read in temperature files r1 <- brick('TavgM_1981.grd') r2 <- brick('TavgM_1982.grd') #stack them together

Keeping raster variable names when converting to NetCDF using R

…衆ロ難τιáo~ 提交于 2020-03-18 15:22:18
问题 Taking a raster file of monthly temperature data for multiple years which has a name attached accessible via names(object) in the following format 'Jan.1981', 'Feb.1981' etc (example files for two years that works with code below here - adding all files makes it too big. Reading in and writing this to NetCDF using the following code: #Load Packages library(raster) library(ncdf4) #Read in temperature files r1 <- brick('TavgM_1981.grd') r2 <- brick('TavgM_1982.grd') #stack them together

R - crop LIST of Least Cost Paths intersected with SpatialPolygonsDataFrame objects

心已入冬 提交于 2020-01-16 08:13:06
问题 I have a series of steps I need to complete on a LIST of SpatialLinesDataFrame (=least cost paths flowing 'downslope' created using ] gdistance ; 'LCPs' herein) objects based on their relationships with individual features within a MULTI-FEATURE SpatialPolygonsDataFrame ('polygons') object. To summarize, each LCP element in the list originates inside a single polygon feature, and may or may not pass through one or more other polygon features as it 'flows' downhill. I want to create new

Zonal statistics to get majority pixel value per polygon in R?

♀尐吖头ヾ 提交于 2020-01-15 09:53:50
问题 Actually I try to calculate the major pixel values from a raster with a SpatialPolygonsDataFrame. Here is some code I found which might lead in the right direction: library(raster) # Create interger class raster r <- raster(ncol=36, nrow=18) r[] <- round(runif(ncell(r),1,10),digits=0) r[]<-as.integer(r[]) # Create two polygons cds1 <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-60), c(-180,-20)) cds2 <- rbind(c(80,0), c(100,60), c(120,0), c(120,-55), c(80,0)) polys <-

Counting species occurrence in a grid

一笑奈何 提交于 2020-01-14 09:39:50
问题 I have about 500,000 points in R of occurrence data of a migratory bird species throughout the US. I am attempting to overlay a grid on these points, and then count the number of occurrences in each grid. Once the counts have been tallied, I then want to reference them to a grid cell ID. In R, I've used the over() function to just get the points within the range map, which is a shapefile. #Read in occurrence data data=read.csv("data.csv", header=TRUE) coordinates(data)=c("LONGITUDE","LATITUDE