[R-sig-Geo] polygon intersecting with point question

Hailey Eckstrand haileyeckstrand at gmail.com
Fri Dec 10 00:10:48 CET 2010


Hello,
I have 2 spatial objects, a SpatialPointsDataFrame objects with 4 points,
and a SpatialPolygons object with 3 polygons.

I created the SpatialPolygons object by using the gBuffer function from the
rgeos package.
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.
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.

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.
Thanks!

I have included an image of the points & polygons and I have also including
the structures:
str(my.pts)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 4 obs. of  3 variables:
  .. ..$ Agency    : chr [1:4] "EC-Surface Wx" "EC-Surface Wx" "EC-Daily
Climat" "EC-Daily Climat"
  .. ..$ Station_Co: chr [1:4] "1018620" "1018598" "1022571" "1012573"
  .. ..$ id        : int [1:4] 1 2 3 4
  ..@ coords.nrs : num(0)
  ..@ coords     : num [1:4, 1:2] 1189982 1199727 1164557 1167413 406887 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  ..@ bbox       : num [1:2, 1:2] 1164557 386154 1199727 418120
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ 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__

str(my.poly)
Formal class 'SpatialPolygons' [package "sp"] with 4 slots
  ..@ polygons   :List of 1
  .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
  .. .. .. ..@ Polygons :List of 3
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] 1188981 385285
  .. .. .. .. .. .. ..@ area   : num 7.06e+08
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:39, 1:2] 1177292 1178815 1181603
1184693 1187783 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] 1189982 406887
  .. .. .. .. .. .. ..@ area   : num 3.09e+08
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:21, 1:2] 1199982 1199493 1198072
1195860 1193072 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] 1165985 416992
  .. .. .. .. .. .. ..@ area   : num 3.81e+08
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:25, 1:2] 1159904 1158679 1156466
1155046 1154557 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ plotOrder: int [1:3] 1 3 2
  .. .. .. ..@ labpt    : num [1:2] 1188981 385285
  .. .. .. ..@ ID       : chr "buffer"
  .. .. .. ..@ area     : num 1.40e+09
  ..@ plotOrder  : int 1
  ..@ bbox       : num [1:2, 1:2] 1154557 373171 1209727 428120
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "x" "y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ 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__
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101209/6a2f5df3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clusters_pts.TIF
Type: image/tiff
Size: 41232 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101209/6a2f5df3/attachment.tiff>


More information about the R-sig-Geo mailing list