clipToExtent: Restrict to extent of a polygon Currently does the sloppy...

Description Usage Arguments Value See Also Examples

View source: R/R-GIS.R

Description

Restrict to extent of a polygon Currently does the sloppy thing and returns any object that has any area inside the extent polygon

Usage

1
clipToExtent(sp, extent)

Arguments

sp

Spatial object

extent

a SpatialPolygons object - any part of sp not within a polygon will be discarded

Value

A spatial object of the same type

See Also

as.SpatialPolygons.bbox to create a SP from a bbox

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
set.seed(1)
require(rgdal)
require(sp)
P4S.latlon <- sp::CRS("+proj=longlat +datum=WGS84")
ply <- sp::SpatialPolygons(list(
   sp::Polygons(list(Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))), "s1"),
   sp::Polygons(list(Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))), "s2")
 ), proj4string=P4S.latlon)
pnt <- sp::SpatialPoints( matrix(rnorm(100),ncol=2)+2, proj4string=P4S.latlon )
# Make bounding box as Spatial Polygon
bb <- matrix(c(3,2,5,4),nrow=2)
rownames(bb) <- c("lon","lat")
colnames(bb) <- c('min','max')
bbSP <- as.SpatialPolygons.bbox(bb, proj4stringTo=P4S.latlon )
# Clip to extent
plyClip <- clipToExtent( ply, bbSP )
pntClip <- clipToExtent( pnt, bbSP )
# Plot
plot( ply )
plot( pnt, add=TRUE )
plot( bbSP, add=TRUE, border="blue" )
plot( plyClip, add=TRUE, border="red")
plot( pntClip, add=TRUE, col="red", pch="o")

gsk3/taRifx.geo documentation built on May 17, 2019, 8:56 a.m.