3

This question assumes that I'm using R with the sp and rgdal packages installed. Now that I have a set of spatial segments of class SpatialLinesDataFrame (called 'segmentData') and a set of spatial points of class SpatialPointsDataFrame (called 'poi'). Suppose that the segments and the points intersect each other as illustrated in the example figure below where line segments are in red and POIs are in blue. I'm trying to query using the function 'over' of the sp package in order to find out which lines cross over a given point. I'm having the following 2 problems:

(1) Whenever I try to query using over(poi, segmentData) or over(segmentData, poi), the returned result is always a list of NA's. But apparently, they do intersect each other, as illustrated in the example. How do I get a valid returned list?

(2) The 'over' method only returns one line id that intersects a given POI (if any), but apparently given one POI there could be several segments that cross over it (e.g., POI located at intersection of 2 road segments). How do I query so that for a given POI, I wish to find all the segments that cross over it?

Illustrating example

asked Jul 18, 2015 at 19:08
2
  • Are the projections the same? Commented Jul 18, 2015 at 22:12
  • The projections are both WGS84. Commented Jul 20, 2015 at 15:35

1 Answer 1

2

(1) Your plot shows the points as small circles. In the computation, they are considered as real, zero-area points, and the lines are considered as zero-width lines. If the plot suggests they intersect, this may be because the lines have a certain width and points a certain area, but that their mathematical representations do not intersect. You could compute a small buffer around the points with rgeos::gBuffer to replace the points with small circles.

(2) You can use rgeos::gIntersects with argument byid = TRUE to find all intersections.

answered Jul 19, 2015 at 19:05
1
  • Thank you! Your solution works perfectly. I combine both (1) and (2): buffer each point by a small 'width' and then use rgeos::gIntersects to find the intersections with lines. Commented Jul 21, 2015 at 2:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.