raster

How does the function “extract” deal with different projections?

偶尔善良 提交于 2019-12-23 02:30:16
问题 I need to use the function extract() to do a weighted average extraction from a raster using a grid cell of equal sized squares. My polygon grid is in UTM21n and the raster is in GCS WGS84 datum D. Do I have to reproject the raster before using it into extract()? Or will the function handle it properly? 回答1: You can find the source code of function extract for SpatialPolygons here. The code starts with the following snippet: setMethod('extract', signature(x='Raster', y='SpatialPolygons'),

Removing data outside country map boundary in R

给你一囗甜甜゛ 提交于 2019-12-22 10:27:39
问题 I know this is simple but could get this working. I want to remove the excess data points on the map below. How do i do it? Below code gave me the results. ggplot() + geom_polygon(data = rwa2, aes(x = long, y = lat, group= group), colour = "black", size = 0.5, fill = "white") + geom_tile(data = df, aes(x = Lon, y = Lat, z = z, fill = z), alpha = 0.8) + ggtitle("State Data") + xlab("Longitude") + ylab("Latitude") + scale_fill_distiller(type = "div", palette = "Spectral")+ theme_bw() + theme

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

Plot issues - legend bar scale, breaks, legend, decimals

末鹿安然 提交于 2019-12-22 06:50:12
问题 I want to plot a bunch of rasters and I created a code to adjust breaks for each one and plot them trough a for loop. But i'm getting a problematic color scale bar, and my efforts haven't being effective to solve that. Example: I have precipitation ranging from 0 to 11.000...but most part of the data is between 0 and 5.000... and very few up to 11.000. So I need to change the breaks to capture this variation... more breaks where I have more data. Then I created a breaks object for that. But

Global Raster of geographic distances

情到浓时终转凉″ 提交于 2019-12-21 21:46:31
问题 Im wondering if someone has built a raster of the continents of the world where each cell equals the distance of that cell cell to the nearest shore. This map would highlight the land areas that are most isolated inland. I would imagine this would simply rasterize a shapefile of the global boundaries and then calculate the distances. 回答1: You can do this with raster::distance , which calculates the distance from each NA cell to the closest non- NA cell. You just need to create a raster that

How can you crop raster layers in R in a batch and change projection

拥有回忆 提交于 2019-12-21 21:27:07
问题 I was working with spatial data to get ready for analyses - I have a DEM at the desired extent of my study area, though I have ~39 other layers at the national scale (US). Is there a way to crop all of these 39 layers to the same extent as the DEM at once? Also, I will be overlaying the output with other layers in a different projection. Is it possible to adjust the projection and pixel size of the output layers? I am trying to use freeware as much as possible for my data manipulation... 回答1:

How to map numbers to colours?

孤街醉人 提交于 2019-12-21 06:35:11
问题 I am trying to view this file(unsigned character, pixel =1440 and lines=720) as a map. I tried the piece of code given bellow. First, I downloaded may problem is that this code is using a continuous colour scheme, even though I have discrete data (which is a classification scheme). How can I map numbers to colours ? Please example of a wanted scale is shown below: conne <- file("C:\\landcover.bin", "rb") dfr<- readBin(conne, integer(), size=1, n=720*1440, signed=F) y<-matrix((data=dfr), ncol

How to map numbers to colours?

送分小仙女□ 提交于 2019-12-21 06:33:28
问题 I am trying to view this file(unsigned character, pixel =1440 and lines=720) as a map. I tried the piece of code given bellow. First, I downloaded may problem is that this code is using a continuous colour scheme, even though I have discrete data (which is a classification scheme). How can I map numbers to colours ? Please example of a wanted scale is shown below: conne <- file("C:\\landcover.bin", "rb") dfr<- readBin(conne, integer(), size=1, n=720*1440, signed=F) y<-matrix((data=dfr), ncol

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

Manipulate shapefile attribute table using R

别来无恙 提交于 2019-12-20 10:10:57
问题 I've posted this question on the GIS stack exchange, but it's not seeing much traffic. I'm a GIS user who's been using R for stats for a few years, and I'm excited to see a lot of new GIS capabilities being released (raster, shapefiles, rgdal, etc). I've done a lot of database and table manipulation in R, so being able to add and remove attributes from shapefiles is a powerful potential. I'm hoping I'm just missing what's out there, but I can't seem to find a good method for adding or