Hello,<br>I have 2 spatial objects, a SpatialPointsDataFrame objects with 4 points, and a SpatialPolygons object with 3 polygons.<br><br>
I created the SpatialPolygons object by using the gBuffer function from the rgeos package.<br>
What I am trying to do is find a function that will return a count or a subset of the SpatialPolygons object that intersects with the points.<br>In this example, it should return the count of 3 polygons, or a SpatialPolygons object with all 3 polygons in it. Since there are 2 points within one polygon, it would be alright if it returned the same polygon twice, so then the expected output would be a SpatialPolygons objects with 4 polygons in it & 2 would be duplicates.<br>
<br>If there is no function that will do what I am requesting.. then I could iterate through the polygons, and use an overlay statement. So then the other question would be, how does one iterate through the polygons within a SpatialPolygons object.<br>
Thanks!<br><br>I have included an image of the points & polygons and I have also including the structures:<br>str(my.pts)<br>Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots<br> ..@ data :'data.frame': 4 obs. of 3 variables:<br>
.. ..$ Agency : chr [1:4] "EC-Surface Wx" "EC-Surface Wx" "EC-Daily Climat" "EC-Daily Climat"<br> .. ..$ Station_Co: chr [1:4] "1018620" "1018598" "1022571" "1012573"<br>
.. ..$ id : int [1:4] 1 2 3 4<br> ..@ coords.nrs : num(0)<br> ..@ coords : num [1:4, 1:2] 1189982 1199727 1164557 1167413 406887 ...<br> .. ..- attr(*, "dimnames")=List of 2<br> .. .. ..$ : NULL<br>
.. .. ..$ : chr [1:2] "coords.x1" "coords.x2"<br> ..@ bbox : num [1:2, 1:2] 1164557 386154 1199727 418120<br> .. ..- attr(*, "dimnames")=List of 2<br> .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"<br>
.. .. ..$ : chr [1:2] "min" "max"<br> ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots<br> .. .. ..@ projargs: chr " +init=epsg:3005 +proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +"| __truncated__<br>
<br>str(my.poly)<br>Formal class 'SpatialPolygons' [package "sp"] with 4 slots<br> ..@ polygons :List of 1<br> .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots<br> .. .. .. ..@ Polygons :List of 3<br>
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots<br> .. .. .. .. .. .. ..@ labpt : num [1:2] 1188981 385285<br> .. .. .. .. .. .. ..@ area : num 7.06e+08<br> .. .. .. .. .. .. ..@ hole : logi FALSE<br>
.. .. .. .. .. .. ..@ ringDir: int 1<br> .. .. .. .. .. .. ..@ coords : num [1:39, 1:2] 1177292 1178815 1181603 1184693 1187783 ...<br> .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2<br> .. .. .. .. .. .. .. .. ..$ : NULL<br>
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"<br> .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots<br> .. .. .. .. .. .. ..@ labpt : num [1:2] 1189982 406887<br>
.. .. .. .. .. .. ..@ area : num 3.09e+08<br> .. .. .. .. .. .. ..@ hole : logi FALSE<br> .. .. .. .. .. .. ..@ ringDir: int 1<br> .. .. .. .. .. .. ..@ coords : num [1:21, 1:2] 1199982 1199493 1198072 1195860 1193072 ...<br>
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2<br> .. .. .. .. .. .. .. .. ..$ : NULL<br> .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"<br> .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots<br>
.. .. .. .. .. .. ..@ labpt : num [1:2] 1165985 416992<br> .. .. .. .. .. .. ..@ area : num 3.81e+08<br> .. .. .. .. .. .. ..@ hole : logi FALSE<br> .. .. .. .. .. .. ..@ ringDir: int 1<br> .. .. .. .. .. .. ..@ coords : num [1:25, 1:2] 1159904 1158679 1156466 1155046 1154557 ...<br>
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2<br> .. .. .. .. .. .. .. .. ..$ : NULL<br> .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"<br> .. .. .. ..@ plotOrder: int [1:3] 1 3 2<br>
.. .. .. ..@ labpt : num [1:2] 1188981 385285<br> .. .. .. ..@ ID : chr "buffer"<br> .. .. .. ..@ area : num 1.40e+09<br> ..@ plotOrder : int 1<br> ..@ bbox : num [1:2, 1:2] 1154557 373171 1209727 428120<br>
.. ..- attr(*, "dimnames")=List of 2<br> .. .. ..$ : chr [1:2] "x" "y"<br> .. .. ..$ : chr [1:2] "min" "max"<br> ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots<br>
.. .. ..@ projargs: chr " +init=epsg:3005 +proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +"| __truncated__<br><br>