[R-sig-Geo] How to establish location of points relative to a line

Bjarke Christensen Bjarke.Christensen at sydbank.dk
Tue Oct 14 16:12:27 CEST 2008


>>> I have a SpatialLinesDataFrame (A) and a SpatialPointsDataFrame (B).
How
>>> can I establish which points in B are to the east of a given line in A?
>>>
>>> The problem is to figure out which persons (whose addresses are
geocoded in
>>> B) have addresses to the east of a given road (whose coordinates are
given
>>> in A).

Barry Rowlingson:
>> Is this problem well-defined for a wiggly road? You could be both
>> east and west of a particularly curvy road.

That's a good point. For my purpose, the more precise definition would
really be 'not to the west of any point in A having the same longitude',
but fortunately all my lines are very well behaved in that respect.

>> You could take the nearest point of the road to the address location
>> and then see if this vector has a positive or negative X component....

Roger Bivand:
>Perhaps you could consider completing a polygon with the road on the
>"west" edge, for your definition of "west", for example adding the south.
>east and north edges of the bounding box of the points to the line (take
>care over ring direction!). Then the overlay method would get you there.

This solution works for me, for my non-wiggly roads.

Thanks for your help!

Bjarke.




More information about the R-sig-Geo mailing list