[R-sig-Geo] overlay method in sp package

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Feb 21 13:39:28 CET 2014


Luis,

Running your script on the data attached gives me the following error,
that has nothing to do with your problem:

> coordinates(linuData) = ~ longd + breidd
Error in coordinates(linuData) = ~longd + breidd :
  object 'linuData' not found

Also, the script below does not work on the data you supplied.

Please verify posts carefully before you press send.

On 02/19/2014 11:22 AM, Luis Ridao wrote:
> Dear Edzer,
> 
> A script and a workspace are attached (tried 'over' but still not working)
> 
> thanks for your prompt response
> 
> best,
> Luis
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> Luis Ridao Cruz
> Faroe Marine Research Institute
> Nóatún 1, P.O. Box 3051
> FO-110 Tórshavn
> Faroe Islands
> Tel   : (+298) 353900
> Fax: : (+298) 353901
> e-mail: luisr at hav.fo
>            luridao at gmail.com
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 
> 
> 
> On Tue, Feb 18, 2014 at 4:47 PM, Edzer Pebesma <
> edzer.pebesma at uni-muenster.de> wrote:
> 
>> Dear Luis,
>>
>> overlay is deprecated and you should use "over" now. Please provide a
>> reproducible example if you want me to understand what happens, and
>> consider posting to r-sig-geo.
>>
>> With best regards,
>>
>> On 02/18/2014 04:16 PM, Luis Ridao wrote:
>>> Dear Edzer,
>>>
>>> I'm using the "overlay" method to detect the presence of some points onto
>>> a "GridTopology" object but i keep on bumping with errors:
>>>
>>>
>>> fbgrid <- GridTopology(c(-9.5, 60.4), c(0.05, 0.05),c(40,
>>> 20))
>>> yy <- SpatialGrid(grid =
>>> fbgrid)
>>> fish <-
>>> SpatialPoints(linu$coords)
>>> out  <- overlay(yy,
>>> fish)
>>> out1 <- formatC(out, width=4, format="d", flag="0")
>>>
>>> res  <- aggregate(rep(1, length(out)), list(out1), sum)     # res$x are
>> the
>>> counts in cells
>>> res1 <- numeric(nrow(coordinates(yy)))                      # res1 are
>> the
>>> counts on every cell even in
>>>
>>>> res1[as.integer(as.character(res$Group.1))] <- res$x     # those with 0
>>> counts
>>> Error in res1[as.integer(as.character(res$Group.1))] <- res$x :
>>>   NAs are not allowed in subscripted assignments
>>> In addition: Warning message:
>>> In res1[as.integer(as.character(res$Group.1))] <- res$x :
>>>   NAs introduced by coercion
>>>
>>>
>>> and if i try :
>>>
>>>> res1[!(is.na(as.integer(as.character(res$Group.1))))] <-
>>> res$x
>>> Warning messages:
>>> 1: In res1[!(is.na(as.integer(as.character(res$Group.1))))] <- res$x :
>>>   NAs introduced by coercion
>>> 2: In res1[!(is.na(as.integer(as.character(res$Group.1))))] <- res$x :
>>>   number of items to replace is not a multiple of replacement length
>>>
>>>> tail(res)
>>>     Group.1  x
>>> 344 0733 2
>>> 345 0737 1
>>> 346 0767 1
>>> 347 0768 2
>>> 348 0775 1
>>> 349      NA 14
>>>
>>>> dim(res)
>>> [1] 349   2
>>>
>>>> length(res1)
>>> [1] 800
>>>
>>>
>>> how can i solve this problem?
>>>
>>> best,
>>> Luis
>>>
>>> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>>> Luis Ridao Cruz
>>> Faroe Marine Research Institute
>>> Nóatún 1, P.O. Box 3051
>>> FO-110 Tórshavn
>>> Faroe Islands
>>> Tel   : (+298) 353900
>>> Fax: : (+298) 353901
>>> e-mail: luisr at hav.fo
>>>            luridao at gmail.com
>>> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>>>
>>
>> --
>> Edzer Pebesma
>> Institute for Geoinformatics (ifgi), University of Münster
>> Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
>> 83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795
>>
>>
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140221/28fc529f/attachment.bin>


More information about the R-sig-Geo mailing list