I have 2 shape files: data (spatial point dataframe) and polys (polygons dataframe). I want to do an overlap but is seems that it does not work.
Here are data and polys:
> data
class : SpatialPointsDataFrame
features : 12527
extent : 10.20075, 20.6108, 54.08669, 57.75905 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs
variables : 3
names : timestamp_pretty, timestamp, imo
min values : 01/04/2006 00:00:55, 1143849655232, 9048392
max values : 30/04/2006 23:59:36, 1146441576823, 9191541
> polys
class : SpatialPolygonsDataFrame
features : 436375
extent : 4210000, 5441000, 3395000, 4813000 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs
variables : 2
names : Id, Count
min values : 0, 0
max values : 99999, 9
to manage the overlapping, I use
proj4string(data) <- proj4string(polys) # to confirm the same reference system
inside <- !is.na(over(data, as(polys, "SpatialPolygons"))) # overlapping shape file and data
and then mean(inside)
to check the average of points in polys.
But there is nothing happening, mean is always 0. I used this many times before and it always work, I guess it does not work not because the extent of the 2 sph files are different. Is there a way to edit this?
Thank you!