Reputation: 59
I'm working with satellite tracked animals and have a load of relocation data.
So I have my map data and relocations as SpatialPointsDataFrames and when I ask
if proj4string(map)==proj4string(locs)
I get TRUE.
But when I try the count.points function as follows
cp <- count.points(locs, map)
I get the following error
Error in count.points(SpatialPoints(x), w) :
different proj4string in w and xy
Does anyone have any ideas on why this is the case?
Edit Code:
load("mydata")
map = mydata$map
map
mimage(map)
locs= mydata$relocs
locs
image(map)
points(locs, col=as.numeric(slot(locs, "data")[,1]), pch=16)
cp <- count.points(locs, map)
Upvotes: 2
Views: 989
Reputation: 72731
Reproducible example would go a long, long way here. But generally speaking R's comparison of projection strings is approximately verbatim. So if there's an extra space or so forth, it will fail.
Given the out for proj4string(map)
, proj4string(locs)
, proj4string(SpatialPoints(locs))
in the comment, particularly that proj4string(SpatialPoints(locs))
is NA
, I'd say that count.points
is dropping the proj4string
when it changes to a SpatialPoints
object. I think the way to coerce a SPDF
to SP
while keeping the projection string is via as(x,"SpatialPoints")
.... Try using trace
to insert that into count.points
?
Upvotes: 2