How to create a Donut Polygon

How to use RGeostats package step-by-step.
Direct access to Tutorial index and Frequently Asked Questions

How to create a Donut Polygon

Postby Didier Renard » Tue Dec 04, 2018 7:49 pm

This post addresses the problem of selecting samples which lie:
- inside a large polygon
- outside a small polygon (included in the large one).
An example is a polygon delineating a part of the ocean [large polygon], excluding the islands [small polygon].

This would be solved by attaching an attribute (HOLE or NOT HOLE) to each polyset defining the polygon. But this is not yet available.

In the mean time, the following example gives a possible solution:

Let us create a data set constituted of 100 samples uniformly spread within a square of 1km side:

Code: Select all
db = db.create(x1=runif(100), x2=runif(100), z1=rnorm(100))

Let us create the two polygon: P1 for the large polygon and P2 for the small polygon. These two polygons are created as squares.

Code: Select all
P1 = polygon.create(x=c(0.2,0.8,0.8,0.2,0.2),y=c(0.2,0.2,0.8,0.8,0.2))
P2 = polygon.create(x=c(0.3,0.7,0.7,0.3,0.3),y=c(0.3,0.3,0.7,0.7,0.3))

In the following figure, we can see the data set, together with the large polygon (P1 in blue) and the small polygon (P2 in red).
Code: Select all

a1.png (29.95 KiB) Viewed 101 times

We now select the samples belonging to P1 (using db.polygon). Then we run this same function to exclude samples belonging to P2. And we combine these two selections:
Code: Select all
db = db.polygon(db,P1,flag.out=FALSE)
db = db.polygon(db,P2,flag.out=TRUE,combine="and")

Now we can produce the same graphic as before again, adding the active samples as black bullets.

Code: Select all

a2.png (30.89 KiB) Viewed 101 times
Didier Renard
Posts: 289
Joined: Thu Sep 20, 2012 4:22 pm

Return to Tutorials and FAQ

Who is online

Users browsing this forum: No registered users and 0 guests