Remi Valois
Remi Valois

Reputation: 1

blank/crop a SpatialPointsDataFrame with a polygon in R

I have a spatial data frame named dataK below and I want to crop it (or blank outside) according to a

polygon
class       : SpatialPolygons
features    : 1
extent      : 836479.4, 840865.5, 6341039, 6347730  (xmin, xmax, ymin, ymax)
crs         : NA

How to do it ?

I tried

raster::crop does not crop
rb \<- crop(dataK,polygon)
spplot(rb,"var1.var",contour=T)

and

out \<- gIntersection(dataK, polygon, byid=TRUE) required rgeos package which cannot be installed on my RStudio 2022.02.1 Build 461`
summary(dataK)
Object of class SpatialPixelsDataFrame
Coordinates:
min       max
EAST   836454.4  840854.4
NORTH 6341013.7 6347713.7
Is projected: NA
proj4string : \[NA\]
Number of points: 11792
Grid attributes:
cellcentre.offset cellsize cells.dim
EAST           836479.4       50        88
NORTH         6341038.7       50       134
Data attributes:
var1.pred        var1.var  
Min.   :30.82   Min.   :0.5508  
1st Qu.:32.78   1st Qu.:1.4504  
Median :32.99   Median :1.8386  
Mean   :32.95   Mean   :1.6855  
3rd Qu.:33.08   3rd Qu.:1.9858  
Max.   :35.75   Max.   :1.9858

Thanks

Upvotes: 0

Views: 17

Answers (0)

Related Questions