0

I am using the raster::crop function to cut a Shape of multiple polygons (Agricultural Plots Information System) with another polygon (Formal Class spatialPolygonDataframe) and instead of cutting the shape of the MCP (single polygon) return a the first shape in a Square.

Any idea?

The code is:

maps <- c(map21, map22) #multipoligons I want to cut
mcpid2 <- crop(maps[[1]], mcpid)

I get this:

enter image description here

and I want this:

enter image description here

2 Answers 2

1

This is what raster::crop does:

Description:

     crop returns a geographic subset of an object as specified by an
     Extent object (or object from which an extent object can be
     extracted/created).  If ‘x’ is a Raster* object, the Extent is
     aligned to ‘x’. Areas included in ‘y’ but outside the extent of
     ‘x’ are ignored (see ‘extend’ if you want a larger area).

Hard to be definitive with what you really need without fuller details, but it sounds like you have sp polygons which means you need functions from the rgeos package to do geometric operations like intersections. Alternatively use the sf package and its functions (eg st_intersection) to chop polygons with polygons.

0

I solved the problem with

raster::intersect(maps[[1]], mcpid)

Thank you.

This helped: How to perform a true GIS clip of polygons layer using a polygon layer in R?

1
  • 1
    you can accept your own answer as solving the question. This will help others having the same question and it will not show up in the un-answered questions log.
    – Vincé
    Commented Dec 21, 2022 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.