2

I am using the function contourLines() in R to record the vertices of a contour based on a probability density estimation. Then I test to see whether a point lies inside the contour region. I can do this test easily when there is only one region (polygon) created from contourLines, but sometimes the there are multiple polygons created. I am trying to come up with a way to determine whether a point lies inside the multiple polygon contour.

My idea so far is to calculate the number of polygons generated and treat each one separately. I was thinking I could use graph theory to determine the number of polygons generated because there will not be a path between points on 2 separate polygons.

Probably there is an easier way. Any suggestions?

Thanks in advance,

HS

galahol
  • 21
  • 2
  • If you use the [ray casting algorithm](http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm), you can treat the polygons as an (unordered) set of segments: you do not have to check which segments are in the same connected component. (The polygons have to be closed, though.) – Vincent Zoonekynd Jul 15 '13 at 21:00
  • Can you put together a dummy example, something where the contours reflect the kind of data you will want to use? You can cast contourLines objects to SpatialLinesDataFrame with maptools, and then you could close them by intersection with the bounding box (probably), using rgeos. – mdsumner Jul 15 '13 at 22:39
  • But then, why not just do the test on where the points fall on the grid data? You can figure out which contour region they will lie in with < and > – mdsumner Jul 15 '13 at 22:41

0 Answers0