0

I am currently trying to clip one spatial file to another however the spatial file I get is not the right shape. I know with a raster you have to use a mask, is there a similar command for 2 shape files?

c1 <- crop(spatial1, spatial2)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
KerryLee
  • 373
  • 2
  • 5
  • 13

1 Answers1

1

With the SpatialPolgyonDataFrame objects

library(raster)
p <- shapefile(system.file("external/lux.shp", package="raster"))
b <- as(extent(6, 6.4, 49.75, 50), 'SpatialPolygons')
crs(b) <- crs(r)

You can do

pc <- crop(p, b)

You need to have packages rgdal and rgeos installed.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63