Description Usage Arguments Value See Also Examples
Restrict to extent of a polygon Currently does the sloppy thing and returns any object that has any area inside the extent polygon
1 | clipToExtent(sp, extent)
|
sp |
Spatial object |
extent |
a SpatialPolygons object - any part of sp not within a polygon will be discarded |
A spatial object of the same type
as.SpatialPolygons.bbox
to create a SP from a
bbox
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.