raster

R - Fitting a grid over a City Map and inputting data into grid squares

女生的网名这么多〃 提交于 2019-12-04 10:21:38
I'm trying to place a grid over San Jose like this: Grid of San Jose You can make the grid visually using the following code: ca_cities = tigris::places(state = "CA") #using tigris package to get shape file of all CA cities sj = ca_cities[ca_cities$NAME == "San Jose",] #specifying to San Jose UTM_ZONE = "10" #the UTM zone for San Jose, will be used to convert the proj4string of sj into UTM main_sj = sj@polygons[[1]]@Polygons[[5]] #the portion of the shape file I focus on. This is the boundary of san jose #converting the main_sj polygon into a spatialpolygondataframe using the sp package tst_ps

Merging multiple rasters in R

試著忘記壹切 提交于 2019-12-04 09:21:11
问题 I've been trying to find a time-efficient way to merge multiple raster images in R. These are adjacent ASTER scenes from the southern Kilimanjaro region, and my target is to put them together to obtain one large image. This is what I got so far (object 'ast14dmo' representing a list of RasterLayer objects): # Loop through single ASTER scenes for (i in seq(ast14dmo.sd)) { if (i == 1) { # Merge current with subsequent scene ast14dmo.sd.mrg <- merge(ast14dmo.sd[[i]], ast14dmo.sd[[i+1]],

How do I extract raster values from polygon data then join into spatial data frame?

牧云@^-^@ 提交于 2019-12-04 08:43:38
I would like to merge polygon data and raster data into one dataframe for purposes of then using randomForests package in R. This involves first extracting the mean raster value per polygon. So far, I have the following: #load libraries library(raster) library(rgdal) library(sp) library(maptools) #import raster data r <- raster("myRasterdata.tif") #import polygon data p <- readShapePoly("myPolydata.shp") #extract mean raster value for each polygon ExtractMyData <- extract(r, p, small=TRUE, fun=mean, na.rm=TRUE, df=FALSE, nl=1, sp=TRUE) # note I have also tried this with df=TRUE and sp=FALSE

how to convert longitude from 0 - 360 to -180 - 180

风流意气都作罢 提交于 2019-12-04 06:33:51
The longitude in CMIP5 future climate data is in 0 - 360 degree. How can I convert it to -180 - 180 degree using the raster package? I tried with shift(r0,-180) and shift(r0,-360) . It does not work. Any help will be appreciated. r0 here is a raster. Try rotate() . Its help page even mentions its utility with the type of data you're dealing with: Rotate a Raster* object that has x coordinates (longitude) from 0 to 360, to standard coordinates between -180 and 180 degrees. Longitude between 0 and 360 is frequently used in data from global climate models. Here's a simple reproducible example to

Relassify continuous raster data into binned classes with discrete colors

孤人 提交于 2019-12-04 06:18:31
I would like to: Reclassify the raster ras into nine classes using reclassify Provide a colorkey with values written beside each colour (see sample plot below). The colorkey should not be split, as in the sample plot, but rather shown as a single colour ramp with 9 colours. Display the data using levelplot function (this I can do) Thanks for your help. AEZ library(rasterVis) Please use these colors: col <- colorRampPalette(c("yellow4", "yellow", "orange", "red3", "darkred")) levelplot(reclassras, col.regions = col) Below is the dput of my raster layer: ras=new("RasterLayer" , file = new("

Performing loops on list of lists of rasters

此生再无相见时 提交于 2019-12-04 05:53:23
Need solution, help will be much appreciated. In the following code I am creating three rasters. I then create a random number of point locations on this raster and I am receiving a list of three matrices with coordinates of those random locations called samples . I then take those locations and sample raster values to receive samplevalues . What I want to change is that I want to create a set of 100,150,200 and 250 random point locations ( numberv ). So after generating these locations and receiving a list of locations, each raster will be sampled length(numberv) times (in this case 4 times).

attaching customized colormap to geoshow in matlab

痴心易碎 提交于 2019-12-04 05:30:42
问题 I am trying to plot a world map in mollweide projection using geoshow command. However, I am not able to modify the colors in the plot based on cutomized colormap values. Most likely this is an issue with how axesm and geoshow commands are used together, Please help me on this. See the ref. code below: G = rand(180,360); G(1:90,:)=-1*G(1:90,:); R = georasterref('RasterSize',size(G),... 'Latlim',[-90 90], 'Lonlim', [-180 180],'ColumnsStartFrom','north'); % ref this link: http://stackoverflow

R raster avoid white space when plotting

南楼画角 提交于 2019-12-04 03:31:44
问题 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

extract() data from raster with small polygons - rounded weights too small

雨燕双飞 提交于 2019-12-04 03:31:15
Using R, I am trying to extract data from a raster layer using a polygon layer. The polygons are much smaller than the raster cells: Now I call extract() from raster library: a <- extract(raster, polygons, weights = TRUE, small = TRUE) a # ... # [[1551]] # value weight # 209 0.03 # top left cell - more than 50% of the polygon area There are two problems - the weight is the proportion of the cell area covered by the polygon, and the weights are rounded to 1/100. In my case, only the top left cell is present in the output (value 209) - the weight of 3 other cells was rounded to zero and they

plot raster factor values with ggplot

谁说胖子不能爱 提交于 2019-12-03 21:04:16
I have problems plotting a raster with factor values using ggplot2. library(ggplot2) library(raster) first, load raster data f <- system.file("external/test.grd", package="raster") r <- raster(f) extract coordinates and values val <- getValues(r) xy <- as.data.frame(xyFromCell(r,1:ncell(r))) xy <- cbind(xy,val) plot the grid using geom_raster(). Everything works fine. ggplot(xy, aes(x=x, y=y, fill=val)) + geom_raster() + coord_equal() I don not have a continuous raster, but a classified. Reclass the raster: r <- reclass(r, c(0,500,1, 500,2000,2)) val <- getValues(r) xy <- as.data.frame