Question

I have a high number of polygons in a shape file and after importing it into r I would now like to create 10 random points inside each polygon. Can anyone please recommend a package which will do this? I'm fairly new and slightly overwhelmed to/by r. Thanks in advance.

Was it helpful?

Solution

You need to implement a point-in-polygon test. This is done by drawing an horizontal line through the point and finding all polygon sides that cross it. If the number of line/side intersections located on the right of the point is odd, then the point is inside the polygon.

You can use this test by drawing random points in the bounding box of the polygon and stopping when 10 of them pass the insideness test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top