Receiving ID of polygons when intersecting SpatialPolygons(DataFrame) and SpatialPoints

classic Classic list List threaded Threaded
3 messages Options
Vv
Reply | Threaded
Open this post in threaded view
|

Receiving ID of polygons when intersecting SpatialPolygons(DataFrame) and SpatialPoints

Vv
Hi list,
 
I am currently tackling with the sp function over.
 
I intersect a SpatialPoints object with a SpatialPolygonsDataFrame.
I'd like to know how I can receive the ID of the polygons within the Polygons slot of the SpatialPolygonsDataFrame which are intersecting the SpatialPoints?
 
Overlap<-sp::over(spPoints, spPolyDataFrame, returnList=TRUE)
 
Whenever I use over I just receive "1" as result.
 
Or is there a way to intersect SpatialPoints with objects of class polygons that I miss?
 
Best,
Ena

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Receiving ID of polygons when intersecting SpatialPolygons(DataFrame) and SpatialPoints

Roman Luštrik
​Hello,

check out the example section of `?sp`.


# return the number of points in each polygon:
sapply(over(sr, geometry(meuse), returnList = TRUE), length)

r1 r2 r3 r4
50 57 48  0


where names in the result should be sufficiently informative.

sapply(slot(sr, "polygons"), slot, name = "ID")

[1] "r1" "r2" "r3" "r4"



Cheers,
Roman


On Thu, Oct 8, 2015 at 9:14 AM, Vv <[hidden email]> wrote:

> Hi list,
>
> I am currently tackling with the sp function over.
>
> I intersect a SpatialPoints object with a SpatialPolygonsDataFrame.
> I'd like to know how I can receive the ID of the polygons within the
> Polygons slot of the SpatialPolygonsDataFrame which are intersecting the
> SpatialPoints?
>
> Overlap<-sp::over(spPoints, spPolyDataFrame, returnList=TRUE)
>
> Whenever I use over I just receive "1" as result.
>
> Or is there a way to intersect SpatialPoints with objects of class
> polygons that I miss?
>
> Best,
> Ena
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


--
In God we trust, all others bring data.

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Receiving ID of polygons when intersecting SpatialPolygons(DataFrame) and SpatialPoints

edzer
In reply to this post by Vv


On 08/10/15 03:14, Vv wrote:

> Hi list,
>  
> I am currently tackling with the sp function over.
>  
> I intersect a SpatialPoints object with a SpatialPolygonsDataFrame.
> I'd like to know how I can receive the ID of the polygons within the
> Polygons slot of the SpatialPolygonsDataFrame which are intersecting the
> SpatialPoints?
>  
> Overlap<-sp::over(spPoints, spPolyDataFrame, returnList=TRUE)
>  
> Whenever I use over I just receive "1" as result.
>  
> Or is there a way to intersect SpatialPoints with objects of class
> polygons that I miss?
rgeos::gIntersects : with arguments byid=TRUE and returnDense=FALSE it
should return a similar list.

>  
> Best,
> Ena
>
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

signature.asc (501 bytes) Download Attachment