sp_clip: Function to clip spatial (or raster) objects by a rectangular...

View source: R/sp_clip.R

sp_clipR Documentation

Function to clip spatial (or raster) objects by a rectangular envelope or a spatial polygon.

Description

sp_clip uses raster::crop by default if an envelope is used rather than rgeos::gIntersection because the crop method can keep the data slot in the spatial object intact (at times).

Usage

sp_clip(sp, envelope, sp_polygon = NULL, method = "raster")

sp_crop(sp, envelope, sp_polygon = NULL, method = "raster")

ra_crop(sp, envelope, sp_polygon = NULL, method = "raster")

Arguments

sp

Spatial object to be clipped.

envelope

A vector with the length of 4 containing the extent of the envelope to be used as a bounding box. The order is: xmin, xmax, ymin, ymax. Watch out when using latitude and longitude, the order is longitude, longitude, then latitude, latitude. These coordinates need to be in the same projection as sp.

sp_polygon

A spatial polygon to use to clip sp. The projection systems of sp and sp_polygon must be identical. If this argument is used, the method argument will not be used.

method

What method to use? Default is to use raster::crop but rgeos::gIntersection could be used if preferred. method can be "raster" or "rgeos"

Details

If a spatial polygon is supplied, the rgeos::gIntersection method will be used.

Author(s)

Stuart K. Grange

See Also

sp_filter, sp_intersect

Examples


## Not run: 

# Clip a spatial lines object which contains roads in Saudi Arabia

# Build envelope
envelope <- c(23.830562, 25.584393, 45.200111, 47.311495)

# Clip spatial lines
sp_road_clip <- sp_clip(sp_roads, envelope)


# Or use a polygon to clip a road network
sp_roads_clipped <- sp_clip(sp_roads_main, sp_gibraltar_peninsula)


## End(Not run)


skgrange/gissr documentation built on Feb. 24, 2024, 2:55 p.m.