I originally posted this question to Stack Overflow, and I was told that
this was the right place to go.

I performed an analysis on a set of X, Y coordinates producing a Voronoi
diagram, and I then created a border. Here I intersect the diagram and the
border, and attempt to get the area of the resulting polygons. The areas
for the interior "hole" polys are correct, but the edge polygons appear to
maintain their original exaggerated size. A link to my data is here:

https://drive.google.com/a/ruths.ai/file/d/0B8QG4cbDqH0UaGM2VkkxZHZkZTA/edit?usp=sharing

Code illustrating the problem is here:


# Read in shapefiles.
# Files are located at:

require(sp)
require(rgeos)
SPDF <- readShapeSpatial("SPDF.shp")
SpP <- readShapeSpatial("SpP.shp")

# Examine plots
plot(SPDF)
SPDF@polygons[[337]]@area # Too large; want it cut off
SPDF@polygons[[339]]@area # Hole poly; area correct
gArea(SPDF[339,]) # Ditto
gArea(SPDF[337,]) # Still wrong


# Merge polys using gDifference
D <- gDifference(SpP, SPDF, byid = TRUE)
plot(D)

# Seems to work, but areas now have a couple of problems.
# I pick apart D using the plotOrder slot to separate
# polys that are holes versus those that are not, allowing
# me to get the correct area for "hole" polys, but the
# edge polygons are still not correct, maintaining their
# area estimates from the original SPDF data frame.

areas <- vector()
for (i in 337:339){ # 337 = exterior poly, 338 and 339 are holes
  po <- D@polygons[[i]]@plotOrder

  if (max(po) == 2) {
    areas[i] <- D@polygons[[i]]@Polygons[[2]]@area
  } else {
    areas[i] <- D@polygons[[i]]@area

  }
}

areas

How does one get the right areas for the edges that should be cut
off by the intersection?

	[[alternative HTML version deleted]]

