[R-sig-Geo] %over% is omitting data

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sat Sep 20 16:32:59 CEST 2014


Thierry, after looking at the data you sent me off-list, it turns out
that some polygons are contained in others. I tried:

x = over(basis.poly, basis.poly)
> any(x != 1:102)
[1] TRUE
> x[x != 1:102]
9731827  911327
     53      85

and plotted them with the ones you found omitted:

plot(basis.poly[c(53,54,85,86),])

over(x,y) or x %over% y returns a list with indexes with the first hit.
If you want all hits, try

over(x, y, returnList = TRUE)

and go through the list.

Hth,

On 07/25/2014 03:16 PM, ONKELINX, Thierry wrote:
> Dear all,
> 
> I use %over% to append the attributes of the SpatialPolygonsDataFrame to a SpatialGridDataFrame. It works fine expect for two polygons. Both are completely contained by the grid (see the summary below) and are large enough. Both cover several grid cell completely, so there should be output. Neither polygon is marked as a hole.
> 
> I'm out of ideas on what is going wrong. Any suggestions are welcome. I can send the data off list if required. The rda file is 4.3MB
> 
> Best regards,
> 
> Thierry
> 
>> library(rgdal)
>> combination <- basis.grid %over% basis.poly
>>   summary(combination)
>        ID
>  8731563:    607
>  9413613:    520
>  7623223:    359
>  3044067:    354
>  6812906:    337
>  (Other):   4757
>  NA's   :1111136
>>   summary(basis.grid)
> Object of class SpatialGridDataFrame
> Coordinates:
>         min      max
> x  22573.66 243973.7
> y 184600.44 235100.4
> Is projected: TRUE
> proj4string :
> [+proj=lcc +lat_1=49.8333339 +lat_2=51.16666733333333 +lat_0=90 +lon_0=4.367486666666666
> +x_0=150000.01256 +y_0=5400088.4378 +ellps=intl +units=m +no_defs]
> Grid attributes:
>   cellcentre.offset cellsize cells.dim
> x          22623.66      100      2214
> y         184650.44      100       505
> Data attributes:
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>       0  279500  559000  559000  838600 1118000
>>   summary(basis.poly)
> Object of class SpatialPolygonsDataFrame
> Coordinates:
>         min      max
> x  22573.66 243877.2
> y 184600.44 235090.9
> Is projected: TRUE
> proj4string :
> [+proj=lcc +lat_1=49.8333339 +lat_2=51.16666733333333 +lat_0=90 +lon_0=4.367486666666666
> +x_0=150000.01256 +y_0=5400088.4378 +ellps=intl +units=m +no_defs]
> Data attributes:
> 1104276 1184605 1212939 1321132  150057 1640781 1757090 1770778 1855918 2001918 2090205 2370933
>       1       1       1       1       1       1       1       1       1       1       1       1
>  241856 2590901 2659228 2957550 3040078 3042825 3044067  316529 3178448 3230545 3322126 3384170
>       1       1       1       1       1       1       1       1       1       1       1       1
> 3394372 3633380 3714251 3833887 3839772 3920302 3974872 4012319  411473 4155071 4193712  422510
>       1       1       1       1       1       1       1       1       1       1       1       1
> 4230828 4300995 4352428 4393061  446323 4477397 4559869 4599815 4720075 4849248  493549 4940272
>       1       1       1       1       1       1       1       1       1       1       1       1
> 5005842 5236141 5434095 5539529 5853116 5904606 6048855 6211032 6252318   63260 6377909 6496260
>       1       1       1       1       1       1       1       1       1       1       1       1
> 6812906 6890180 6958065 7190203 7284585 7316045 7389494 7477761 7484048 7613684 7618484 7623223
>       1       1       1       1       1       1       1       1       1       1       1       1
> 7682161 7708077  784327 7865873 7951049  798473 8175618 8208627 8227675 8359132 8370365 8434383
>       1       1       1       1       1       1       1       1       1       1       1       1
>  852311 8591606 8705267 8731563 8759351 8788624 8869929 8932474 8952361 9091973 9095956  911327
>       1       1       1       1       1       1       1       1       1       1       1       1
> 9228048 9296002 9413613 (Other)
>       1       1       1       3
>> which.missing <- which(!basis.poly$ID %in% unique(combination$ID))
>> which.missing
> [1] 54 86
> 
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> + 32 2 525 02 51
> + 32 54 43 61 85
> Thierry.Onkelinx at inbo.be
> www.inbo.be
> 
> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
> ~ Sir Ronald Aylmer Fisher
> 
> The plural of anecdote is not data.
> ~ Roger Brinner
> 
> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
> 
> * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
> The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
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/20140920/57036b16/attachment.bin>


More information about the R-sig-Geo mailing list