2

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)
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235

1 Answers1

2

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?

Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
  • proj4string(map) is "+init=EPSG:32736 +proj=utm +zone=36 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0" proj4string(locs) is "+init=EPSG:32736 +proj=utm +zone=36 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0" proj4string(SpatialPoints(locs)) is NA. Thanks! – killbot2000 May 13 '13 at 11:12
  • So if I use as(x,"SpatialPoints") for the location data I get: Error in checkSlotAssignment(object, name, value) : assignment of an object of class "numeric" is not valid for slot "data" in an object of class "SpatialPixelsDataFrame"; is(value, "data.frame") is not TRUE – killbot2000 May 13 '13 at 13:19
  • 1
    Is it a `SpatialPixelsDF` or a `SpatialPoints` one? Can you reproduce the problem with a smaller version of your objects and post that here? It's nearly impossible to debug without knowing either the function or having data to reproduce. – Ari B. Friedman May 13 '13 at 14:57
  • 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) – killbot2000 May 14 '13 at 09:59
  • Hi Ari, see above for the full code I'm using in the analysis. Thanks for your help. – killbot2000 May 14 '13 at 10:00
  • @killbot2000 Best to edit the question for things like this. I've done it for you. Also, need data to make it reproducible. Please [see this](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for posting guidelines. – Ari B. Friedman May 14 '13 at 13:21
  • Hi Ari, could I email you a csv file of a sample of my data? Might be easier to see my problem that way. Thanks – killbot2000 May 16 '13 at 07:28