Hot answers tagged

4

if it's a raster-package raster you can do r2 <- setExtent(r, extent(xmin(r) + 1, xmax(r) + 1, ymin(r), ymax(r))) But, beware that's a "use at your own risk" move because we assume 1 is one metre (it might be in degrees, or km - look at the crs), and that "East" is to the right in the "positive x" direction (this is wildly not true in many projections)....


4

You're almost there! You can calculate the area of your new intersecting shapes, and then merge this back into your nc object: # Calculate area and tidy up intersect_pct <- st_intersection(nc, tr_buff) %>% mutate(intersect_area = st_area(.)) %>% # create new column with shape area dplyr::select(NAME, intersect_area) %>% # only select ...


2

Your code worked just fine for me, so I think that make it throws that error because you have some topology error in your shape. I've just adapted your code adding a check and repair part in order to avoid error (st_is_valid and st_make_valid). Here you can download the data and code I've used. library(sf) library(mapview) # Load data my.sf <- st_read(...


2

Can your GDAL write ArcInfo ascii grids? > rds = st_drivers(what="raster") > rds["AAIGrid",] name long_name write copy is_raster is_vector vsi AAIGrid AAIGrid Arc/Info ASCII Grid FALSE TRUE TRUE FALSE TRUE that shows mine can't write them. The raster package gets round this by implementing its own ASCII Grid writing ...


1

To answer your first question, many packages come with their own function to open a file. The current state of the art for working with vector data in R is the sf package, like @Spacedman already mentioned. To open your shapefile in sf, simply use: munboundary<-st_read("Filename.shp") As Spacedman also correctly assumed (not taking credits here), your ...


1

The palr package has a function image_raster for the task of baking in the palette to RGB version of the raster. (You can set the extent and projection using raster itself as usual). library(raster) #> Loading required package: sp r <-raster(volcano) library(palr) ## apply the colours used by raster plot() itself rgb0 <- image_raster(r, col = ...


Only top voted, non community-wiki answers of a minimum length are eligible