1

I have a list with 4 objects, each object is a data frame. The data frame is the coordinate matrix of each polygon. I would like calculate the total area of the 4 polygons and then draw the voronoi tessellation. Here is my workflow, first, I convert the data frame within the list to polygon:

 Region_HE_srl <- lapply(Region_HE,FUN= function(x) Polygon(x))

Then, I create the SpatialPolygons object:

 Region_HE_sp <- SpatialPolygons(list(Polygons(Region_HE_srl,length(Region_HE))))

Now that the SpatialPolygons object is created: enter image description here I used the 'gArea' function from the 'rgeos' package to calculate the area.

 area <- gArea(Region_HE_sp, byid = TRUE)

Normally, when there is only 1 polygon within the SpatialPolygon object, this function works fine, but now as there are 4 polygons, an error occurs:

Error in createPolygonsComment(p) : rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon for hole at index 1

Same thing when I applied the voronoi.polygons function from 'SDraw' package.

 voronoi.tess <- SDraw::voronoi.polygons(pts_ppp, Region_HE_sp)

The error occurs again. As the package claimed that the bounding polygon parameter should be a spatialpolygons object, I cannot figure out why this error happened.

Any suggestions?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 12, 2020 at 5:46

1 Answer 1

1

R thinks one or more of your polygons are holes, and a hole has to be inside a non-hole.

Hole detection is done in the Polygon function:

 Polygon(coords, hole=as.logical(NA))
 coords: 2-column numeric matrix with coordinates; first point (row)
 should equal last coordinates (row); if the hole argument is
 not given, the status of the polygon as a hole or an island
 will be taken from the ring direction, with clockwise meaning
 island, and counter-clockwise meaning hole

So you either have to reverse the holey Polygon, or set hole=FALSE in your Polygon function call:

 hole: logical value for setting polygon as hole or not; if the hole
 argument is not given, the status of the polygon as a hole or
 an island will be taken from the ring direction, with
 clockwise meaning island, and counter-clockwise meaning hole
answered Aug 12, 2020 at 11:15
0

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.