0

I have a map of landcover data in R and want to clip a circle of specific area, say 20km, and extract the resultant circular shapefile.

# read in the shape file, assign the CRS and plot it
area <- readShapePoly("Corrine Land Use ITM Projection - Copy.shp", proj4string = CRS("+init=epsg:2157"))
plot(area, xlim = c(560000,600000), ylim = c(530000,580000), axes=TRUE)

# create a dataframe of the location where the buffer should be made and plot it
locations<-data.frame(latitude=584503.3,longitude = 560164.5)
points(locations, bg='tomato2', pch=21, cex=3)

Do I need to change my points into a coordinate system first before I do this? The shape file is the Corine Landcover 2012 - National http://gis.epa.ie/GetData/Download

Thanks

rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
adkane
  • 1,429
  • 14
  • 29
  • Can you direct us to the shapefile you used more clearly? Can't find it on the website. – erc Jun 09 '16 at 12:40
  • Possible duplicate of [Buffer (geo)spatial points in R with gbuffer](http://stackoverflow.com/questions/25411251/buffer-geospatial-points-in-r-with-gbuffer) – rafa.pereira Jun 21 '16 at 19:26

2 Answers2

1

Your polygons

area <- shapefile("Corrine Land Use ITM Projection - Copy.shp")

You can create a circle (or multiple circles) like this:

library(dismo)
p <- polygons(circles(cbind(0,0), sqrt(20000 / pi), lonlat=FALSE, dissolve=FALSE))
crs(p) <- crs(area) 

Intersect

int <- crop(area, p)

Write

shapefile(int, 'landcover_circle.shp')
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
0

@Manassa: I believe you will need to ensure the shapefile and raster are in the same projection before you clip, then you can use the crop function in the raster library. Please note, the output will be a clipped raster, not a shapefile as stated in your original question.

# Reproject shapefile to same projection as the raster
#shp = shapefile
#r = raster
library(rdgal)
shp.reproject <- spTransform(shp, crs(r))

#crop raster with polygon
library(raster)
r.crop <- crop(r, shp.reproject)
Tim Assal
  • 677
  • 6
  • 15